feat(FN-1147): rehydrate AI sessions across server restarts

- Add recoverable-session querying in AiSessionStore and cover it with targeted store tests
- Persist resume context (ip, initial plan, mission metadata) and rebuild planning/subtask/mission sessions from SQLite rows
- Rehydrate recoverable sessions at server startup and resume planning/mission interviews by recreating agents with replayed conversation context
- Update API flows to pass project root context and clean in-memory sessions when persisted sessions are deleted, with comprehensive regression tests
This commit is contained in:
gsxdsm
2026-04-08 08:26:57 -07:00
parent 2a923ea1a0
commit 69621e78dc
11 changed files with 1287 additions and 129 deletions

View File

@@ -168,6 +168,30 @@ export class AiSessionStore extends EventEmitter<AiSessionStoreEvents> {
.all() as unknown as AiSessionSummary[];
}
/**
* List recoverable sessions for in-memory rehydration.
* Returns full rows for sessions still in progress.
*/
listRecoverable(projectId?: string): AiSessionRow[] {
if (projectId) {
return this.db
.prepare(
`SELECT * FROM ai_sessions
WHERE status IN ('generating', 'awaiting_input') AND projectId = ?
ORDER BY updatedAt DESC`,
)
.all(projectId) as unknown as AiSessionRow[];
}
return this.db
.prepare(
`SELECT * FROM ai_sessions
WHERE status IN ('generating', 'awaiting_input')
ORDER BY updatedAt DESC`,
)
.all() as unknown as AiSessionRow[];
}
/**
* Delete a session by ID. Emits `ai_session:deleted`.
*/