Skip to content

Commit 5e1a90f

Browse files
opencodeclaude
andcommitted
fix(monitor): nullish, not truthy, checks on epoch-millis timestamp fields
Henry (via Copilot's suppressed-but-verified finding, 4913451058): fromRow read time_started/time_checked/time_finished with a truthy check, so an epoch-millis value of 0 -- a real timestamp -- misread as unset. Live under TestClock (starts at epoch 0), silently, because no existing assertion touched a timestamp field. Fixed to `!= null`. Added one assertion (recover marks every starting/ running row orphaned) asserting time.finished is defined on the orphaned rows -- confirmed it fails without the fix (TestClock's epoch-0 time_finished read back as undefined) and passes with it. Co-Authored-By: Claude <[email protected]>
1 parent 5af6f0c commit 5e1a90f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎packages/core/src/monitor.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ const fromRow = (row: Row): Info => ({
4343
profileSnapshotID: row.profile_snapshot_id ?? undefined,
4444
time: {
4545
created: DateTime.makeUnsafe(row.time_created),
46-
started: row.time_started ? DateTime.makeUnsafe(row.time_started) : undefined,
47-
checked: row.time_checked ? DateTime.makeUnsafe(row.time_checked) : undefined,
48-
finished: row.time_finished ? DateTime.makeUnsafe(row.time_finished) : undefined,
46+
// Nullish, not truthy -- epoch millis 0 is a real timestamp (TestClock starts there), and a
47+
// truthy check would read it back as unset.
48+
started: row.time_started != null ? DateTime.makeUnsafe(row.time_started) : undefined,
49+
checked: row.time_checked != null ? DateTime.makeUnsafe(row.time_checked) : undefined,
50+
finished: row.time_finished != null ? DateTime.makeUnsafe(row.time_finished) : undefined,
4951
},
5052
revision: row.revision,
5153
})

‎packages/core/test/monitor.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ describe("Monitor", () => {
122122
const orphanedIDs = orphaned.map((o) => o.id).sort()
123123

124124
expect(orphanedIDs).toEqual([starting.id, running.id].sort())
125+
// TestClock starts at epoch 0, so this is exactly the case a truthy (rather than nullish)
126+
// check on time_finished would misread as unset -- a real timestamp of 0 is still a
127+
// timestamp.
128+
expect(orphaned.every((o) => o.time.finished !== undefined)).toBe(true)
125129

126130
const stillCompleted = yield* monitor.get(completed.id)
127131
expect(stillCompleted?.status).toBe("completed")

0 commit comments

Comments
 (0)