Skip to content

app: every lock in the guarded tree unlocks from a defer - #2172

Merged
santoshkumarradha merged 5 commits into
app/v3from
c34/guard
Nov 2, 2026
Merged

santoshkumarradha merged 5 commits into
app/v3from
c34/guard

Conversation

@santoshkumarradha

Copy link
Copy Markdown
Member

What changes

Every lock in the guarded tree is now released through a deferred unlock. This fixes the law TestEveryLockInTheGuardedTreeUnlocksFromADefer, which was red on app/v3. A lock with a hand-written unlock leaks when the code under it panics and the panic is absorbed. The next caller then waits forever, so a fault becomes a freeze.

Each critical section that did not run to the end of its function moved into a small function of its own, which holds the lock with defer:

  • remember → rememberHeld
  • Retry → knownWorkRefusalGated
  • traceAnswer → firstAnswers
  • MoveToTask → moveToTaskGated
  • factoryPower → currentHost
  • briefDebounce.take → claim
  • shared readers: stageAgentsWhere, recoveringAgents, currentSeam
  • the matching sites in internal/resident

Behaviour does not change. Work that must run outside the lock (for example ActOnTask, the startup trace and the brief write) still runs after the lock is released.

Evidence

  • Red on app/v3: the law fails with "these critical sections turn an absorbed panic into a deadlock" and lists each site.
  • Green on this branch: go test ./internal/guard/ ok. go vet and gofmt are clean. go test ./internal/resident/ ok. Full go test ./cmd/codeaf/: result below.

Limits

  • The sections were split along their existing boundaries; no locking order changed.

🤖 Generated with Claude Code

santoshkumarradha and others added 5 commits November 2, 2026 03:21
Uncommitted work of the guard lane, saved before the tip merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The guard law (every lock in the guarded tree unlocks from a defer) also
named briefDebounce.take, added on app/v3 after the guard lane started.
claim now holds the lock with a deferred unlock; the write fires outside.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@santoshkumarradha
santoshkumarradha marked this pull request as ready for review November 2, 2026 08:59
@santoshkumarradha
santoshkumarradha merged commit 37cc7f6 into app/v3 Nov 2, 2026
@santoshkumarradha
santoshkumarradha deleted the c34/guard branch November 2, 2026 08:59
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