Skip to content

Commit 3d90836

Browse files
committed
fix: address review comments in runtime and stop handler GIT-869c63k1e
Use CLOCK_SKEW_ALLOWANCE_MS constant and remove uninitialized handlerResult path. AI-Agent: Codex/0.92.0 AI-Model: gpt-5.3-codex AI-Decision: Clock skew allowance for runtime data validation is set to 1 minute (60,000ms) to handle minor timestamp discrepancies between systems. AI-Confidence: verified AI-Tags: error-handling, variable-initialization, session-stop-handler, runtime-service, clock-skew, timestamp-validation, constants, magic-numbers, code-quality, cleanup, finally-block AI-Lifecycle: project AI-Memory-Id: d6a8f851 AI-Source: llm-enrichment
1 parent c9980e7 commit 3d90836

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/application/handlers/SessionStopHandler.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export class SessionStopHandler implements ISessionStopHandler {
2121
) {}
2222

2323
async handle(event: ISessionStopEvent): Promise<IEventResult> {
24-
let handlerResult: IEventResult;
25-
2624
try {
2725
this.logger?.info('Session stop handler invoked', {
2826
sessionId: event.sessionId,
@@ -39,7 +37,7 @@ export class SessionStopHandler implements ISessionStopHandler {
3937
memoriesExtracted: result.memoriesExtracted,
4038
});
4139

42-
handlerResult = {
40+
return {
4341
handler: 'SessionStopHandler',
4442
success: true,
4543
output: result.summary,
@@ -50,7 +48,7 @@ export class SessionStopHandler implements ISessionStopHandler {
5048
error: err.message,
5149
stack: err.stack,
5250
});
53-
handlerResult = {
51+
return {
5452
handler: 'SessionStopHandler',
5553
success: false,
5654
error: err,
@@ -59,8 +57,6 @@ export class SessionStopHandler implements ISessionStopHandler {
5957
// Always deactivate runtime.json on session stop, even if capture fails
6058
this.deactivateRuntime(event.cwd);
6159
}
62-
63-
return handlerResult;
6460
}
6561

6662
/**

src/infrastructure/services/RuntimeService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const RUNTIME_FILE = 'runtime.json';
1616

1717
/** Default TTL: 2 hours in milliseconds. */
1818
const DEFAULT_TTL_MS = 2 * 60 * 60 * 1000;
19+
/** Allow up to 1 minute of future timestamp skew. */
20+
const CLOCK_SKEW_ALLOWANCE_MS = 60 * 1000;
1921

2022
export class RuntimeService implements IRuntimeService {
2123
activate(data: IRuntimeData, cwd?: string): void {
@@ -76,7 +78,7 @@ export class RuntimeService implements IRuntimeService {
7678
const age = Date.now() - timestamp;
7779

7880
// Reject future timestamps (with small skew allowance) or stale data
79-
if (age < -60000 || age > ttl) {
81+
if (age < -CLOCK_SKEW_ALLOWANCE_MS || age > ttl) {
8082
return undefined;
8183
}
8284

0 commit comments

Comments
 (0)