fix(agent): synchronize ConfirmDelayGate.shownAt against a data race#169
Merged
Conversation
The 2-second anti-clickjacking confirm-delay gate stores shownAt as a plain time.Time. Show() runs on the agent's Run goroutine (the prompt is rendered from a tool-status callback) while Remaining()/Open() run on the REPL's key-reading goroutine — an unsynchronized read/write of shownAt, i.e. a data race (go test -race flags it). The race is benign in effect — a zero/torn shownAt reads as the full delay, so the gate fails CLOSED (it would only ever delay the window, never open it early) — but it is a real race on a safety-adjacent component and trips -race. Adds a sync.Mutex guarding shownAt; delay and now are construction-time and never mutated, so they stay lock-free. Show() locks the write; Remaining() snapshots shownAt under the lock then computes outside it. Found via the internal audit sweep. Test: TestConfirmDelayGate_ConcurrentShowAndCheck races Show() against Open()/Remaining(); proven to report WARNING: DATA RACE on the pre-fix code under -race and to pass after. Verified: task ci green (lint 0 / vet / build / test:full 0 fail / govulncheck clean); task eval 17/17. The race test passes under -race (which task test:full runs).
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.
The confirm-delay anti-clickjacking gate stored shownAt as a plain time.Time; Show() (Run goroutine) raced Remaining()/Open() (REPL goroutine). Benign (fails closed — a torn read reads as the full delay, never opens early) but a real -race-flagged data race on a safety-adjacent component. Added a mutex guarding shownAt (delay/now stay lock-free). Race test proven to report DATA RACE pre-fix under -race. task ci green; eval 17/17. Found via the internal audit sweep.