Skip to content

fix(guard): advisory-only turn end in lock-refused sessions - #81

Merged
adibirzu merged 2 commits into
mainfrom
fm/fm-turnend-guard-lock-refused-loop
Sep 14, 2026
Merged

adibirzu merged 2 commits into
mainfrom
fm/fm-turnend-guard-lock-refused-loop

Conversation

@adibirzu

@adibirzu adibirzu commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

fix(guard): advisory-only turn end in lock-refused sessions

Problem

The Claude turn-end guard (bin/fm-turnend-guard.sh --claude) re-blocked EVERY turn end forever in a lock-refused (read-only) session.

Causal split (trigger / mask / symptom):

  • Trigger: a turn ends while supervision is needed with no healthy watcher.
  • Mask: in a lock-refused session the Stop-owned auto-arm (bin/fm-claude-stop-autoarm.sh) stays inert by design, so state/.claude-autoarm-epoch never advances. The guard's re-block budget keys off epoch change: with a stale epoch the counter freezes (observed: count=1 across 5 consecutive blocks); with no epoch the counter grows but terminal fail-open never verifies (no failure episode exists). Either way the guard exits 2 forever.
  • Symptom: every turn end gets the full TURN WOULD END BLIND repair banner, instructing a read-only session to perform repairs it must not perform.

Fix

bin/fm-turnend-guard.sh now detects the lock-refused state once, before any blocking branch: the session lock names a live harness pid that is not this session's (same idiom the auto-arm and Cursor park already use). Such a turn ends with advisory wording only (exit 0, READ-ONLY SESSION WITHOUT LOCK OWNERSHIP) and zero shared-state mutation: no budget write, no epoch write, no failure-episode reset, no legacy-acceptance log.

Untouched backstop: missing, malformed, or dead-owner locks keep blocking exactly as before, and the lock-owning session's own guard is unchanged.

docs/turnend-guard.md gains one invariant sentence plus regression-coverage pointer (one sentence per line, per repo style).

Verification (local runs are the CI evidence: Actions minutes are exhausted on this fork)

Red without fix: tests/fm-turnend-guard.test.sh against the unpatched guard fails at the first new test:

not ok - lock-refused --claude turn 1 must end without a block: expected exit 0, got 2

plus the stale-epoch fixture reproduction (exit 2 x5, budget frozen at count=1, epoch=7).

Green with fix:

$ bash tests/fm-turnend-guard.test.sh
suite_exit=0
93 x ^ok lines, 0 x ^not ok lines
ok - fm-turnend-guard --claude: lock-refused turns end with advisory wording only, forever, mutating nothing
ok - fm-turnend-guard --claude: a stale epoch in a lock-refused session never re-blocks
ok - fm-turnend-guard: default mode ends a lock-refused turn with advisory wording only
ok - fm-turnend-guard --claude: the lock-owning session still blocks an unhealthy unclaimed stop
ok - fm-turnend-guard --claude: a dead lock owner never reads as a lock-refused session

$ bash tests/fm-claude-stop-autoarm.test.sh
suite_exit=0
41 x ^ok lines, 0 x ^not ok lines

$ bin/fm-lint.sh bin/fm-turnend-guard.sh tests/fm-turnend-guard.test.sh  # ShellCheck 0.11.0
lint_exit=0
$ bin/fm-doc-audience-check.sh
fm-doc-audience-check: ok surfaces=131 local_links=403

Branch already merges fork main at d49dee6 (PR 76 attestation path), so the required "PR must be raised via no-mistakes" check can run from this branch workflow.

Code Review (Stage 1)

# Code Review Verdict
**Stage 1: Deterministic Review (zero LLM tokens)**
- Files reviewable: 2 / 3
- Changes: +181 / -3 (184 lines)
- Linter: ran, 0 finding(s)
- LLM tokens: 0
No escalation: Stage 1 alone gates this change.

Command: bin/fm-review.sh worktree --from d49dee6 --to HEAD with ShellCheck 0.11.0 on PATH (exit 0). The unscoped run escalates only on the upstream merge content (2299 lines, already reviewed on fork main) and on the host's ambient ShellCheck 0.9.0 version refusal; neither touches this change.

Independent Second-Level Review

Reviewer: opencode-go/deepseek-v4.1-flash (independent of the authoring lane opencode-go/muse-spark-1.3-contributor)
Report: data/fm-pr81-second-level-review/report.md
Verdict: PASS at head 2e52e57 (one Low-severity malformed-binding gap noted in the report; no blocker)

adi added 2 commits September 14, 2026 18:27
The Claude turn-end guard re-blocked every turn end forever in a
lock-refused session: the Stop-owned auto-arm stays inert there, so the
epoch ledger never advances and the epoch-keyed re-block budget never
consumes toward fail-open (frozen counter with a stale epoch, unverified
episode without one).

Detect the live-other-owner lock before any blocking branch and report
the lapse as advisory wording only (exit 0, no budget/epoch/episode/lock
mutation), preserving the backstop for owned, missing, malformed, and
dead-owner locks. Regression tests cover both epoch shapes plus default
mode, with owned-lock and dead-owner blocking negatives.
…t-hygiene PR75) into fm/fm-turnend-guard-lock-refused-loop
@adibirzu
adibirzu merged commit da2f810 into main Sep 14, 2026
15 of 16 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.

2 participants