fix(logs): exclude same-thread events after scan completion - #607
Open
Drewwb wants to merge 1 commit into
Open
Conversation
readScanLogs() uses a saved scan's completedAt to reject independent sessions that start after the scan, but once a session was selected it appended every event without applying the same boundary. A post-scan prompt runs on the same Codex thread after complete-scan, so its later events surfaced in `codex-security scans logs` as if they belonged to the completed scan. Apply the completion boundary to individual events too: skip any event whose timestamp parses to a time after completedAt. Events without a parseable timestamp (such as session_meta) and every event at or before completedAt are preserved, so ordinary scan activity is unaffected. Add a regression test covering a same-thread event emitted after the saved completion time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
readScanLogs()uses a saved scan'scompletedAttimestamp to reject independent worker sessions that start after the scan, but it does not apply that same completion boundary to events inside sessions that were already selected. A post-scan prompt runs on the same Codex thread aftercomplete-scan, so its later events can appear incodex-security scans logsas if they belonged to the completed security scan.Changes
src/scan-logs.ts, parse the saved scan'scompletedAtonce, then skip any event whose owntimestampparses to a time strictly after that boundary before it is appended. Events without a parseable timestamp (such assession_meta) and every event at or beforecompletedAtare preserved, and anull/undefined/unparseablecompletedAtdisables the filter, so running-scan and legacy behavior is unchanged.tests-ts/scan-logs.test.tsthat puts a during-scan event (12:01) and a same-thread post-completion event (12:03) in the scan's own session with acompletedAtof 12:02, and asserts the 12:01 event is kept while the 12:03 event is dropped.Testing
bun test tests-ts/scan-logs.test.ts— 8 pass, 0 failpnpm run types— cleannpx prettier --check src/scan-logs.ts tests-ts/scan-logs.test.ts— cleanRisk and rollout
Low risk. The change only narrows saved-log projection to a scan's recorded lifetime; it never adds events, and events without a timestamp or at/before
completedAtare untouched. No public CLI surface, schema, or default changes.Public disclosure review
Fixes #555