Skip to content

Fix session restoration after agent restart#84

Merged
gricha merged 1 commit intomainfrom
fix/session-restoration
Jan 10, 2026
Merged

Fix session restoration after agent restart#84
gricha merged 1 commit intomainfrom
fix/session-restoration

Conversation

@gricha
Copy link
Copy Markdown
Owner

@gricha gricha commented Jan 10, 2026

Summary

  • Fix session restoration when reconnecting after agent restart
  • Add disk registry fallback in findSession() to restore sessions not in memory
  • Add findExistingServer() to reuse running OpenCode servers instead of spawning duplicates

Problem

When the agent restarts, the in-memory session Map is cleared. Users reconnecting to old sessions would get "session not found" errors even though the session data (including agentSessionId) was persisted on disk.

Solution

Updated findSession() to:

  1. Check in-memory cache first (fast path)
  2. Fall back to disk registry if not found
  3. Restore the session by calling startSession() with the persisted agentSessionId

Also added findExistingServer() for OpenCode to detect and reuse running servers instead of spawning new ones on each agent restart.

Test plan

  • All 290 tests pass
  • Manual test: Start OpenCode session, restart agent, reconnect - should resume context

🤖 Generated with Claude Code

When the agent restarts, the in-memory session Map is empty but the disk
registry still has the session data with agentSessionId. Updated findSession()
to fall back to disk and restore sessions when not found in memory.

Changes:
- registry.ts: Add getSession() and findByAgentSessionId() lookups
- manager.ts: Make findSession() async, add disk fallback + session restoration
- bun-handler.ts: Await the now-async findSession() call
- opencode.ts: Add findExistingServer() to reuse running servers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gricha gricha merged commit 32ac25e into main Jan 10, 2026
8 checks passed
@gricha gricha deleted the fix/session-restoration branch January 10, 2026 22:57
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.

1 participant