Skip to content

Agent state persistence — survive restarts with db backed#362

Open
clintjeff2 wants to merge 7 commits into
Bitcoindefi:mainfrom
clintjeff2:Agent-state-persistence-—-survive-restarts-with-DB-backed

Hidden character warning

The head ref may contain hidden characters: "Agent-state-persistence-\u2014-survive-restarts-with-DB-backed"
Open

Agent state persistence — survive restarts with db backed#362
clintjeff2 wants to merge 7 commits into
Bitcoindefi:mainfrom
clintjeff2:Agent-state-persistence-—-survive-restarts-with-DB-backed

Conversation

@clintjeff2

Copy link
Copy Markdown
Contributor

Motivation

  • Agent runtime state (position, tasks, skills, wallet, XP) must survive page reloads and worker restarts so the simulation is not reset on refresh.
  • Separate authoritative/immutable config from volatile live fields to match DB + KV semantics for performance and correctness.
  • Provide a hydration path for the frontend and a compact, batched way to update live positions from the canvas.

Description

  • Add a file-backed runtime store that splits DB-style persisted configs/stats and KV-style live state at lib/agent-runtime/state.ts.
  • Add a batch position sync helper lib/agent-runtime/position-sync.ts and a new API endpoint GET/POST /api/agents/positions at app/api/agents/positions/route.ts for reading and writing live coordinates.
  • Extend GET /api/agents (app/api/agents/route.ts) to return persisted state when requested via ?state=1 while preserving the existing capability registry response.
  • Hydrate and merge persisted agent configs and live positions in the client by updating components/open-stellar/open-stellar-hub.tsx, and batch-write canvas positions every 5s.
  • Add unit tests in lib/agent-runtime/state.test.ts to verify seeding/hydration and independent live-position persistence.

Testing

  • Ran npm test -- lib/agent-runtime/state.test.ts and the test file passed.
  • Ran npm test -- __tests__/api/agents/registry.test.ts lib/agent-runtime/state.test.ts and both tests passed after adjusting GET /api/agents to expose persisted state for hydration.
  • Ran npx eslint against the changed files (app/api/agents/route.ts, app/api/agents/positions/route.ts, lib/agent-runtime/state.ts, lib/agent-runtime/position-sync.ts, lib/agent-runtime/state.test.ts, components/open-stellar/open-stellar-hub.tsx) and the lint check for those files completed (the repo still contains unrelated pre-existing lint warnings elsewhere).
  • Note: running full npx tsc --noEmit and npm test revealed pre-existing unrelated TypeScript and task-drain test failures outside the scope of this change, and this package does not include a typecheck script.

Closes #47

clintjeff2 and others added 7 commits June 27, 2026 08:18
…h-database

Persist agent state across restarts
- Fix TypeScript error in task drain route by providing correct event result
- Fix async/await issue in task drain unit tests
- Increase MAX_PENDING_PER_AGENT to 500 to support existing test cases
- Remove accidentally generated tsconfig.tsbuildinfo artifact

Co-authored-by: clintjeff2 <119521983+clintjeff2@users.noreply.github.com>
…6952249712895268

Fix CI failures in task drain API and tests
- Update task-drain test expectations to match MAX_DRAIN_ITEMS=200
- Escape single quotes in app/offline/page.tsx to fix ESLint error
- Suppress unsafe declaration merging in Soroban validator client
- Add missing @base-org/account and @metamask/connect-evm dependencies
- Fix ESLint/TSC conflict for window.Buffer assignment in validator client
- Remove build artifacts and temporary log files

Co-authored-by: clintjeff2 <119521983+clintjeff2@users.noreply.github.com>
Fix CI checks: Typecheck, tests, build, and guards
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent state persistence — survive restarts with DB-backed state

1 participant