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:
@@ -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`.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user