Skip to content

fix(opencode): retry undetermined primacy probes - #54

Merged
levelupself merged 3 commits into
mainfrom
fm/watcher-extension-post-release-transitio-e9
Aug 14, 2026
Merged

levelupself merged 3 commits into
mainfrom
fm/watcher-extension-post-release-transitio-e9

Conversation

@levelupself

Copy link
Copy Markdown
Owner

Intent

Fix an abandonment defect in .opencode/plugins/fm-primary-watch-arm.js: a primacy probe that could not complete must be distinguishable from a genuine not-primary result, and the undetermined case must spend its existing bounded retries.

BACKGROUND AND SUPERSESSION. This task was originally briefed as a test-side change: replace a deadline-based post-release wait in tests/fm-pi-watch-extension.test.sh with a signalled checkpoint, on the theory that the post-release child-close and restoration chain was completing late and overrunning a fixed five-second poll. That instruction has been explicitly WITHDRAWN and must NOT be implemented. Instrumented measurement disproved the scheduling theory: the post-release transition completes in 30-41ms against the unchanged 5000ms bound (50-160x margin), and 36/36 runs passed under 12-way parallelism. The real defect is coordinator state, not scheduling.

THE DEFECT. isPrimaryRoot() answered a three-way question with a bare boolean: "this is not a primary checkout" and "primacy could not be determined right now" both returned false, because runProcess() maps a failed git spawn to a non-zero code. restoreAfterActionableClose() treats not-primary as a settled verdict and breaks out of its retry loop, so one transient git spawn failure under process pressure permanently abandoned watcher continuity with the retry budget untouched. The same transient failure class one step later, when the successor arm's own spawn fails, is already retried and recovers - that asymmetry is the proof it was unintended.

THE ACCEPTED FIX (option a, scoped). classifyPrimaryRoot() returns primary, not-primary, or primacy-undetermined. Only settled verdicts (not-primary, read-only, skipped) end restoration; primacy-undetermined falls through to the ordinary bounded retries. A new regression test drives the coordinator through its public hook against a real git that fails --git-dir exactly once after the first arm has run, and asserts the injected fault actually fired so the case cannot pass vacuously. docs/watcher-continuity.md records the distinction at its existing owner paragraph.

HARD EXCLUSIONS. Do not enlarge the five-second poll, add a retry, insert a sleep, or relax any assertion in tests/fm-pi-watch-extension.test.sh - the existing deadline is deliberately untouched, because leaving it untouched is what proves the deadline was never the defect. Do not undertake a file-wide sweep of the other deadline-based waits in that file (31 bounded polls and 10 unconditional sleeps remain); that is real and is being filed as separate work, and bundling it here would turn a one-line correctness fix into an unreviewable change. Do not convert this into a test-only change.

VERIFICATION ALREADY ESTABLISHED. Previously failing assertion, same machine, existing 5000ms poll, with a real git failing rev-parse once at the post-release transition: before the fix, close observed at 8.6ms, restoration finished at 21.9ms and then stopped, poll expired at 5053.6ms holding 2 arm rows (FAIL); after the fix, the same condition recovers at 39.4ms with 3 rows (PASS). With no fault injected the transition takes 30.0ms against the unchanged 5000ms bound. The new regression test was confirmed red-first: reverting only the plugin to HEAD yields "restoration abandoned its successor after an undetermined primacy probe" with a single arm row.

PRE-EXISTING SUITE STATE. The full suite at this commit reports total=153 failed=6 skipped_gate=20. All six failing scripts (fm-remote-job-orphan-reap, fm-remote-secondmate-lifecycle-e2e, fm-secondmate-sync, fm-startup-memory-budget, fm-bootstrap, fm-cockpit-herdr-e2e) fail identically at the base commit db7a847 and are unrelated to this change; the watcher-wake-lock family containing the changed test reports failed=0.

ARTIFACT STYLE CONSTRAINT. Pipeline-authored risk rationales, fix summaries, and PR bodies must use role-neutral prose with no second person and no captain, user, firstmate, or crewmate role nouns. This constraint does not apply to product code, prompts, or user-facing copy.

What Changed

  • Distinguish transient primacy-undetermined probe failures from settled not-primary results so watcher restoration uses its existing bounded retries.
  • Add regression coverage that injects a one-time real Git primacy failure and verifies successor restoration without changing the existing deadline.
  • Document which restoration verdicts terminate retries and which consume the retry budget.

Risk Assessment

✅ Low: The change is narrowly scoped and correctly preserves settled primacy verdicts while routing an undetermined probe through the existing bounded restoration retries, with behavioral regression coverage and no forbidden deadline changes.

Testing

Scope inspection, diff validation, and the targeted watcher-extension behavioral family all passed; the public OpenCode coordinator hook demonstrably spent its bounded retry after an injected one-shot Git primacy-probe failure and restored watcher continuity, with the transcript preserved as reviewer evidence.

Evidence: Targeted watcher-extension behavioral transcript
ok - Pi primary watcher extension is tracked, self-hashing, and self-locating
ok - Pi secondmate launch wiring includes both tracked primary extensions
ok - Pi extension reports external healthy watcher output
ok - Pi custom tool exposes repair-only metadata and returns automatic-continuation guidance
ok - Pi redundant tool call returns ownership guidance and spawns no second child
ok - Pi scheduled retry remains extension-owned after another tool call
ok - Pi actionable close starts one successor before wake delivery settles
ok - Pi hung successor falls back to one typed actionable wake
ok - Pi unretired successor falls back without an overlapping retry
ok - Pi late unretired closes resume classified supervision
ok - Pi clean empty close triggers a bounded continuity retry
ok - Pi established clean closes stop at the configured retry limit
ok - Pi close handler verifies session-lock ownership before successor launch
ok - Pi watcher arm distinguishes all session lock ownership states
ok - Pi session transitions use a generation owner across /new /resume /fork, stale callbacks, and quit
ok - Pi process-exit cleanup listener remains singular across session replacement
ok - Pi process-exit cleanup stops the attached arm child
ok - OpenCode plugins have an explicit ESM boundary even under a typeless parent package
ok - OpenCode watcher plugin uses the effective FM_HOME state
ok - OpenCode watcher plugin sources the effective config
ok - OpenCode watcher plugin requires session lock ownership
ok - OpenCode watcher coordinator respects primary scope
ok - OpenCode watcher plugin starts one successor before wake prompt delivery settles
ok - OpenCode pre-ready actionable close preserves its successor
ok - OpenCode undetermined primacy probe retries instead of abandoning continuity
ok - OpenCode hung successor falls back to one typed actionable wake
ok - OpenCode unretired successor falls back without an overlapping retry
ok - OpenCode late unretired closes resume classified supervision
ok - OpenCode clean empty close triggers a bounded continuity retry
ok - OpenCode established clean closes stop at the configured retry limit
ok - OpenCode close handler verifies session-lock ownership before successor launch
ok - OpenCode watcher plugin coordinates with the turn-end guard
ok - OpenCode healthy arm output does not suppress the turn-end guard

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • git diff --check a5fb89d1d4d020d4de8a29f87033be80b70fe686..a8f095e3078d0758ba0148f6f388d4847b0ea575
  • Inspected git diff a5fb89d1d4d020d4de8a29f87033be80b70fe686..a8f095e3078d0758ba0148f6f388d4847b0ea575 to confirm the withdrawn deadline/sleep/assertion changes were absent
  • bash tests/fm-pi-watch-extension.test.sh 2>&1 | tee /tmp/no-mistakes-evidence/01KZZV0YM8P1GD6M2DNFTMXT1P/fm-pi-watch-extension-targeted.log
  • Verified the test left the git worktree free of transient test artifacts with git status --short
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

An actionable arm close restores continuity by re-checking that the root is a
primary checkout. isPrimaryRoot() answered that question with a bare boolean,
so "this is not a primary checkout" and "primacy could not be determined right
now" collapsed into the same false. restoreAfterActionableClose() treats
not-primary as a settled verdict and breaks out of its retry loop, so a single
transient git spawn failure under process pressure permanently abandoned
watcher continuity with the retry budget untouched.

classifyPrimaryRoot() now returns primary, not-primary, or
primacy-undetermined. Only the settled verdicts end restoration; an
undetermined probe spends the ordinary bounded retries, which is the behaviour
the same failure class already gets one step later when the successor arm's own
spawn fails.

Measured on one machine against the existing five-second poll in
test_opencode_pre_ready_actionable_close_preserves_its_successor, with a real
git failing rev-parse once at the post-release transition: before, the close
completed in 8.6ms, restoration finished in 21.9ms and then stopped, and the
poll expired at 5053.6ms holding two arm rows; after, the same condition
recovers in 39.4ms with three rows. With no fault the transition takes 30.0ms
against that unchanged 5000ms bound, so the deadline was never the constraint.

The new regression test drives the coordinator through its public hook with a
real git that fails --git-dir exactly once after the first arm has run, and
asserts the fault actually fired so the case cannot pass vacuously.
@levelupself
levelupself merged commit 6fcf0ee into main Aug 14, 2026
14 checks passed
levelupself pushed a commit that referenced this pull request Aug 16, 2026
origin/main advanced by two commits while this branch waited on a merge
decision: #55 (render fleet panes to drawn geometry) and #57 (require local
suite evidence when CI is unavailable). The opencode primacy-probe fix (#54)
was already an ancestor of this branch.

One conflict, in bin/fm-brief.sh, and it lands on a file this branch had
already resolved once. #57 replaces the literal no-mistakes deliverable
sentence with a $READY_DELIVERABLE variable selected by whether the repository
can demonstrate a working CI check gate. The incoming variable is kept, because
that feature is the point of #57 - but both of its definitions reintroduced
"This project ships", silently reverting the per-task noun this branch had
unified across the direct-PR, local-only and no-mistakes blocks. The noun is
re-applied to both definitions, so the generated brief stays internally
consistent.

The other four files touched by the incoming work had also been resolved once
on this branch (AGENTS.md, bin/backends/herdr.sh, docs/herdr-backend.md,
tests/fm-brief.test.sh). Each auto-merged, and each round-one decision was
re-verified as still present rather than assumed.
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