feat(agent-service): persist agent state to disk and rehydrate on startup#5276
Open
bobbai00 wants to merge 1 commit into
Open
feat(agent-service): persist agent state to disk and rehydrate on startup#5276bobbai00 wants to merge 1 commit into
bobbai00 wants to merge 1 commit into
Conversation
…rtup Agents lived only in a process-local Map, so a restart/crash/redeploy lost every agent and its conversation. This adds opt-in disk persistence: - TexeraAgent.toSnapshot()/restoreFromSnapshot() capture and restore the ReAct step tree, HEAD, settings, delegate metadata, and workflow content (the user token and result caches are intentionally excluded). - AgentSnapshotStore writes one JSON file per agent (atomic temp+rename), with debounced coalescing, and loads/skips-corrupt on startup. - The server persists on create/clear/checkout/settings-change and after each WS turn, removes on delete, and rehydrates all agents on startup. Enabled by setting AGENT_STATE_DIR; empty keeps the previous in-memory-only behavior. Closes apache#5267
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5276 +/- ##
============================================
+ Coverage 49.01% 49.39% +0.37%
Complexity 2378 2378
============================================
Files 1050 1051 +1
Lines 40336 40544 +208
Branches 4277 4277
============================================
+ Hits 19772 20027 +255
+ Misses 19407 19360 -47
Partials 1157 1157
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Each agent was a stateful object in a process-local
Map, never persisted, so a restart / crash / redeploy lost every agent and its conversation. This adds opt-in disk persistence for agents:TexeraAgent.toSnapshot()/restoreFromSnapshot()— capture and restore the durable state: the ReAct step tree, HEAD, settings, delegate metadata, and the workflow being edited. The short-lived user token and the recomputable execution-result cache are intentionally excluded.createdAtis preserved across restarts.AgentSnapshotStore(src/persistence/) — one JSON file per agent, atomic writes (temp file + rename), debounced coalescing of rapid updates, andloadAll()that skips unreadable/unsupported files.rehydrateAgents. Enabled byAGENT_STATE_DIR; leaving it empty keeps the previous in-memory-only behavior.Any related issues, documentation, discussions?
Closes #5267
How was this PR tested?
New tests:
agent/texera-agent-snapshot.test.ts—toSnapshotof a fresh agent,createdAtround-trip,restoreFromSnapshotrestoring conversation/settings/workflow/delegate, a full JSON round-trip deep-equal, and version rejection.persistence/agent-snapshot-store.test.ts— save/load, directory auto-create, overwrite,loadAll(incl. skipping corrupt/unsupported/non-matching files), remove (incl. missing), and debouncedscheduleSave+flushcoalescing.server.test.ts— a created agent is written to disk, delete removes the file, andrehydrateAgentsrestores a persisted agent so it is served again.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.8 (1M context)