Skip to content

Commit bd173f3

Browse files
committed
fix(daemon): preserve run lifecycle timestamps across stale message PUTs
The stale-snapshot guard protected events/content/run-status/ownership but a snapshot that omits startedAt/endedAt still nulled the daemon-written run timestamps via upsertMessage — and saved.endedAt feeds persisted-run telemetry, so a terminal message lost its timing data (looper review on #6418). Preserve stored startedAt/endedAt alongside the other daemon-owned fields in the stale-write branch, and assert in the regression test that the timestamps survive repeated stale PUTs.
1 parent b1087fb commit bd173f3

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

apps/daemon/src/routes/project/conversations.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ export function registerProjectConversationRoutes(app: Express, ctx: RegisterPro
245245
content: stored.content ?? '',
246246
lastRunEventId: stored.lastRunEventId,
247247
runStatus: stored.runStatus,
248+
// Daemon-written lifecycle timestamps; a stale snapshot that omits them
249+
// would otherwise null out started_at / ended_at (and endedAt feeds
250+
// persisted-run telemetry).
251+
startedAt: stored.startedAt,
252+
endedAt: stored.endedAt,
248253
};
249254
};
250255

apps/daemon/tests/stale-message-snapshot-preserves-daemon-events.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type StoredMessage = {
4343
lastRunEventId?: string | null;
4444
events?: PersistedEvent[];
4545
feedback?: { rating?: number };
46+
startedAt?: number;
47+
endedAt?: number;
4648
};
4749

4850
type RunHandles = {
@@ -160,6 +162,9 @@ describe('stale web message snapshot does not wipe daemon-owned run events', ()
160162
'early daemon-persisted event should survive stale web snapshot PUTs',
161163
).toBe(true);
162164
expect(after?.runStatus).toBe('succeeded');
165+
// Daemon-written lifecycle timestamps survive the stale PUTs too.
166+
expect(after?.startedAt).toBe(before?.startedAt);
167+
expect(after?.endedAt).toBe(before?.endedAt);
163168
// Client-owned metadata writes still land on daemon-backed messages.
164169
expect(after?.feedback?.rating).toBe(1);
165170
});

0 commit comments

Comments
 (0)