Summary
readScanLogs() uses a saved scan's completedAt timestamp to reject independent worker sessions that start after the scan, but it does not apply the same completion boundary to events inside sessions that were already selected.
A post-scan prompt runs on the same Codex thread after complete-scan, so its later events can appear in codex-security scans logs as if they belonged to the completed security scan.
Reproduction / evidence
Current upstream main at 37bf87a692fc72d41f7312cc48808d699d204fba does this in readScanLogs():
belongsToScan() parses completedAt and excludes independent sessions whose startedAt >= completedAt;
- after the session set is selected, the event loop appends every event from each included session without checking
completedAt.
The SDK scan lifecycle completes/persists the scan first, then, when postScanPrompt is configured, invokes the follow-up on the same thread through runPostScan.
A deterministic saved-log fixture is therefore:
- root session starts at
12:00:00;
- a scan event is timestamped
12:01:00;
- saved scan
completedAt is 12:02:00;
- a same-thread post-scan event is timestamped
12:03:00;
readScanLogs() currently returns both events.
Expected behavior: the 12:03:00 event is outside the saved scan's lifetime and should not be projected as scan activity.
Root cause
The completion boundary is enforced only while deciding which independent sessions belong to a Deep scan. It is not enforced at the per-event projection boundary for root, child, or already-selected worker sessions.
Suggested fix
Parse a finite completedAt once for log projection and omit timestamped events strictly after that instant. Preserve existing behavior for running scans (completedAt: null) and for legacy events that do not carry a usable timestamp.
Add a focused regression with before/after completion events in the same root session.
Impact
This is history/observability correctness. scans logs can mix post-scan assistant/tool activity into the evidence shown for a completed scan, making the saved activity timeline extend beyond the scan record it claims to describe.
Summary
readScanLogs()uses a saved scan'scompletedAttimestamp to reject independent worker sessions that start after the scan, but it does not apply the same completion boundary to events inside sessions that were already selected.A post-scan prompt runs on the same Codex thread after
complete-scan, so its later events can appear incodex-security scans logsas if they belonged to the completed security scan.Reproduction / evidence
Current upstream
mainat37bf87a692fc72d41f7312cc48808d699d204fbadoes this inreadScanLogs():belongsToScan()parsescompletedAtand excludes independent sessions whosestartedAt >= completedAt;completedAt.The SDK scan lifecycle completes/persists the scan first, then, when
postScanPromptis configured, invokes the follow-up on the samethreadthroughrunPostScan.A deterministic saved-log fixture is therefore:
12:00:00;12:01:00;completedAtis12:02:00;12:03:00;readScanLogs()currently returns both events.Expected behavior: the
12:03:00event is outside the saved scan's lifetime and should not be projected as scan activity.Root cause
The completion boundary is enforced only while deciding which independent sessions belong to a Deep scan. It is not enforced at the per-event projection boundary for root, child, or already-selected worker sessions.
Suggested fix
Parse a finite
completedAtonce for log projection and omit timestamped events strictly after that instant. Preserve existing behavior for running scans (completedAt: null) and for legacy events that do not carry a usable timestamp.Add a focused regression with before/after completion events in the same root session.
Impact
This is history/observability correctness.
scans logscan mix post-scan assistant/tool activity into the evidence shown for a completed scan, making the saved activity timeline extend beyond the scan record it claims to describe.