Skip to content

fix(agent): synchronize ConfirmDelayGate.shownAt against a data race#169

Merged
xunholy merged 1 commit into
mainfrom
fix/confirm-delay-gate-race
Jun 30, 2026
Merged

fix(agent): synchronize ConfirmDelayGate.shownAt against a data race#169
xunholy merged 1 commit into
mainfrom
fix/confirm-delay-gate-race

Conversation

@xunholy

@xunholy xunholy commented Jun 30, 2026

Copy link
Copy Markdown
Owner

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.

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).
@xunholy xunholy merged commit a41843c into main Jun 30, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant