Context
From the system design audit, the Session-Thread coupling creates an implicit distributed state problem. Session state lives in-process while Thread state lives in the event store, but the boundary is not documented.
Design Decision (from spec)
INV-6: Session state is ephemeral; does not survive process restarts. On restart, all sessions initialize to idle.
The resumeCursor (provider thread ID) is stored in the event store, enabling a new session to pick up from the last completed turn. The session process is ephemeral; the turn/message context is durable.
Session State Machine (from spec)
IDLE -> STARTING -> RUNNING -> READY (turn complete)
-> INTERRUPTED (user interrupt)
-> ERROR (provider fault)
READY -> RUNNING (next turn)
ERROR -> IDLE (explicit stop + restart)
On process restart: ALL sessions -> IDLE
Proposed Changes
- Document INV-6 in codexAppServerManager.ts and any Claude adapter code
- Ensure server startup explicitly resets all session projections to "idle"
- Add test: kill server mid-session -> restart -> verify sessions are idle, thread history intact, resumeCursor available for next session start
- Document the session state machine in
.plans/21-system-design-spec.md (done) and in code comments
Acceptance Criteria
References
- System Design Spec:
.plans/21-system-design-spec.md Section 5 (Session State Machine)
- Audit finding: "Session-Thread coupling creates an implicit distributed state problem"
Context
From the system design audit, the Session-Thread coupling creates an implicit distributed state problem. Session state lives in-process while Thread state lives in the event store, but the boundary is not documented.
Design Decision (from spec)
INV-6: Session state is ephemeral; does not survive process restarts. On restart, all sessions initialize to idle.
The
resumeCursor(provider thread ID) is stored in the event store, enabling a new session to pick up from the last completed turn. The session process is ephemeral; the turn/message context is durable.Session State Machine (from spec)
Proposed Changes
.plans/21-system-design-spec.md(done) and in code commentsAcceptance Criteria
References
.plans/21-system-design-spec.mdSection 5 (Session State Machine)