Merge branch 'pr-1553' into integration/validation-batch
# Conflicts: # src/services/worker/session/SessionCompletionHandler.ts
This commit is contained in:
@@ -889,6 +889,16 @@ export class SessionStore {
|
||||
`).run(memorySessionId, sessionDbId);
|
||||
}
|
||||
|
||||
markSessionCompleted(sessionDbId: number): void {
|
||||
const nowEpoch = Date.now();
|
||||
const nowIso = new Date(nowEpoch).toISOString();
|
||||
this.db.prepare(`
|
||||
UPDATE sdk_sessions
|
||||
SET status = 'completed', completed_at = ?, completed_at_epoch = ?
|
||||
WHERE id = ?
|
||||
`).run(nowIso, nowEpoch, sessionDbId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures memory_session_id is registered in sdk_sessions before FK-constrained INSERT.
|
||||
* This fixes Issue #846 where observations fail after worker restart because the
|
||||
|
||||
@@ -40,7 +40,8 @@ export class SessionRoutes extends BaseRouteHandler {
|
||||
super();
|
||||
this.completionHandler = new SessionCompletionHandler(
|
||||
sessionManager,
|
||||
eventBroadcaster
|
||||
eventBroadcaster,
|
||||
dbManager.getSessionStore()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@
|
||||
|
||||
import { SessionManager } from '../SessionManager.js';
|
||||
import { SessionEventBroadcaster } from '../events/SessionEventBroadcaster.js';
|
||||
import { SessionStore } from '../../sqlite/SessionStore.js';
|
||||
import { logger } from '../../../utils/logger.js';
|
||||
|
||||
export class SessionCompletionHandler {
|
||||
constructor(
|
||||
private sessionManager: SessionManager,
|
||||
private eventBroadcaster: SessionEventBroadcaster
|
||||
private eventBroadcaster: SessionEventBroadcaster,
|
||||
private sessionStore: SessionStore
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -24,6 +26,9 @@ export class SessionCompletionHandler {
|
||||
* Used by DELETE /api/sessions/:id and POST /api/sessions/:id/complete
|
||||
*/
|
||||
async completeByDbId(sessionDbId: number): Promise<void> {
|
||||
// Persist completion to database before in-memory cleanup (fix for #1532)
|
||||
this.sessionStore.markSessionCompleted(sessionDbId);
|
||||
|
||||
// Delete from session manager (aborts SDK agent via SIGTERM)
|
||||
await this.sessionManager.deleteSession(sessionDbId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user