Skip to content

fix: release Codex locks and improve GitHub diagnostics - #1109

Closed
KarlvonPoncet wants to merge 8 commits into
kunchenguid:mainfrom
KarlvonPoncet:fm/fix-codex-lock-gh-diagnostics-20260727
Closed

KarlvonPoncet wants to merge 8 commits into
kunchenguid:mainfrom
KarlvonPoncet:fm/fix-codex-lock-gh-diagnostics-20260727

Conversation

@KarlvonPoncet

Copy link
Copy Markdown

Intent

Ship two related Firstmate reliability fixes based on reproduced end-user failures. Make clean Codex /quit release the per-home session lock through supported native lifecycle integration while preserving fail-closed exclusion of live sessions, same-thread behavior, verified stale recovery, and PID-isolated compatibility. Distinguish genuine GitHub authentication failure from API network or DNS failure, inaccessible credential storage, and combined sandbox isolation without leaking credentials or requiring live GitHub in tests. Update authoritative headers and help plus narrowly relevant docs under the one-owner rule, keep scripts shellcheck-clean, and validate with focused real and deterministic regressions. Include the approved follow-up decisions: structured GitHub CLI state=timeout maps to GH_NETWORK with regression coverage, GROK_AGENT takes precedence over inherited CODEX_THREAD_ID with regression coverage, and publication uses the KarlvonPoncet/firstmate fork while the PR targets kunchenguid/firstmate.

What Changed

  • Release per-home Codex session locks through native SessionStart and SessionEnd hooks while preserving same-thread access, live-session exclusion, stale recovery, and PID-isolated fail-closed behavior.
  • Classify GitHub authentication checks into invalid credentials, network or DNS failures, inaccessible credential storage, combined sandbox isolation, and generic inspection failures.
  • Preserve Grok identity when GROK_AGENT and an inherited Codex thread marker coexist, with focused deterministic and live regressions plus updated operator documentation.

Risk Assessment

✅ Low: The follow-up now enforces Grok-over-Codex marker precedence at the shared session-lock owner boundary with deterministic regression coverage, and the complete branch remains well-bounded with no other substantiated source or intent-conformance defects.

Testing

No baseline commands were supplied; focused lock, bootstrap, and session-start regressions passed, and a real Codex CLI 0.145.0 PTY session confirmed that clean /quit fires SessionEnd and removes the per-home lock. The first live attempt was blocked by the runner's unsupported TERM=dumb setting, then passed unchanged with TERM=xterm-256color. CLI logs were captured instead of screenshots because the changed user surfaces are terminal lifecycle and diagnostic output, not rendered UI.

Evidence: Real Codex /quit lifecycle evidence

ok - codex-cli 0.145.0 live /quit fired SessionEnd and released the per-home lock

ok - codex-cli 0.145.0 live /quit fired SessionEnd and released the per-home lock
Evidence: Codex lock regression evidence

Covers matching release, same-thread preservation, stale recovery, live-session exclusion, PID-isolated fail-closed behavior, and malformed/symlinked lock preservation.

ok - Codex registers one bounded SessionEnd release and one SessionStart owner claim
ok - matching Codex SessionEnd releases the lock used by /quit
ok - Codex SessionStart retains a verified harness PID when ancestry is visible
ok - same Codex thread preserves its existing owner across PID-isolated tool calls
ok - a verified Codex harness PID that is provably dead is reclaimed
ok - a different live Codex thread remains excluded
ok - a different thread cannot weaken the PID-isolated fallback boundary
ok - SessionEnd leaves numeric, different, malformed, and symlinked owners untouched
Evidence: GitHub diagnostic regression evidence

Covers deterministic missing/invalid auth, network/DNS, structured timeout, inaccessible credential storage, combined sandbox isolation, and inspection failure without live GitHub.

ok - bootstrap reports treehouse lease + tasks-axi/quota-axi bootstrap contracts
ok - bootstrap distinguishes authenticated, invalid, network, credential-store, and sandbox GitHub states without live access
ok - bootstrap enforces no-mistakes minimum version
ok - bootstrap requires git with an install instruction
ok - bootstrap: backend=orca gates the Orca CLI without requiring it on the default backend
ok - bootstrap: session-provider backends require their own CLI + jq + treehouse, never tmux
ok - bootstrap: a session-provider backend gates its own CLI, never a false tmux requirement
ok - bootstrap: Herdr manual-install guidance is never executed as a shell command
ok - bootstrap: the bundled cmux CLI satisfies the active backend dependency
ok - bootstrap: unknown resolved backends fail closed with an actionable diagnostic
ok - bootstrap: JSON-emitting backends require jq (their genuine dep), never tmux
ok - bootstrap: the treehouse lease check follows the resolved backend's worktree provider
ok - bootstrap computes a fleet-size-aware default timeout and preserves partial fleet-sync output
ok - bootstrap keeps the quick 20s default for small fleets
ok - bootstrap preserves FM_FLEET_SYNC_BOOTSTRAP_TIMEOUT as an explicit override
ok - bootstrap treats a blank timeout override as unset
ok - bootstrap computes the timeout before launching fleet sync
ok - bootstrap keeps routine tasks-axi, harness, dispatch, and already-live liveness confirmations silent
ok - bootstrap routine contract runs under system /bin/bash
ok - bootstrap diagnostics trigger excludes benign lines and keeps actionable prefixes
ok - bootstrap surfaces active crew-dispatch rules only as verbose BOOTSTRAP_INFO
ok - bootstrap validates crew-dispatch.json and reports malformed or unverified configs
Evidence: Session-start regression evidence

Includes PID-isolated Codex ownership and GROK_AGENT precedence over inherited CODEX_THREAD_ID.

ok - context digest distinguishes ABSENT, empty-but-present, and populated files
ok - session start accepts Codex's PID-isolated process marker
ok - Grok marker takes precedence over an inherited Codex marker in detection and lock ownership
ok - a lock refusal prints a loud read-only banner, skips every mutating step, and still completes the digest
ok - session start stays read-only when lock ownership cannot be published
ok - concurrent session-lock acquisition admits exactly one live harness
ok - digest sections are ordered diagnostics-first, bulk-context-last
ok - session start: configured and auto-detected Herdr homes never require tmux
ok - session start: an absent recorded tmux window relaunches its Pi secondmate exactly once
ok - session start: an existing ambiguous Pi process prevents duplicate recovery
ok - session start: transient tmux unreadability never licenses a relaunch
ok - session start: the proven bare-shell recovery path remains intact
ok - session start: a confirmed Herdr husk is closed and relaunched
ok - status tail is bounded to the configured line count, with the full log path always printed
ok - orphan status logs are printed once with bounded tails
ok - tmux endpoint liveness is reported per task: alive for a live window, dead for a gone one
ok - herdr endpoint liveness is reported per task: alive for a live pane, dead for a gone one
ok - fm-session-start.sh composes the real fm-lock.sh, fm-bootstrap.sh, and fm-wake-drain.sh output verbatim
ok - compatible tasks-axi backlog rendering is compact, bounded, and preserves recovery metadata
ok - manual backlog rendering prints only title lines with hold and blocker metadata
ok - unavailable or incompatible tasks-axi falls back to compact manual backlog rendering
ok - an empty fleet reports (none) for in-flight tasks and an absent AFK flag
ok - session start emits X-mode cadence guidance in the harness supervision block
ok - next step delegates watcher ownership to the AFK daemon
ok - session start emits exactly one detected harness block and reports Pi extension load state
ok - session start rejects stale Pi loaded markers
ok - session start accepts current Pi markers written before lock acquisition
ok - session start rejects Pi sessions missing the turn-end guard marker
ok - session start rejects Pi loaded markers from previous sessions

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 bin/fm-session-lock-lib.sh:49 - Intent requires "GROK_AGENT takes precedence over inherited CODEX_THREAD_ID", but fm_session_lock_owner still treats any non-empty CODEX_THREAD_ID as Codex without checking GROK_AGENT. A Grok session inheriting a Codex marker is correctly identified as Grok by fm-harness.sh, then fm-lock.sh writes a Codex owner anyway; same-session checks subsequently trust the inherited Codex thread and Grok has no Codex SessionEnd release. Enforce the precedence at the shared lock-owner boundary, not only in harness-name detection, and cover the resulting owner record in the Grok regression.

🔧 Fix: Honor Grok precedence in session lock ownership
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-codex-session-lock.test.sh
  • bash tests/fm-bootstrap.test.sh
  • bash tests/fm-session-start.test.sh
  • TERM=xterm-256color FM_CODEX_LOCK_LIVE_E2E=1 bash tests/fm-codex-session-lock-live-e2e.test.sh
  • git remote -v verified upstream fetch and fork push destinations
  • git status --short verified testing left no working-tree artifacts
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 127)

🔧 Fix: Validate lint with pinned ShellCheck 0.11.0
1 warning still open:

  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

@KarlvonPoncet
KarlvonPoncet force-pushed the fm/fix-codex-lock-gh-diagnostics-20260727 branch from 9fb3b36 to 9f2928a Compare July 28, 2026 06:59
@kunchenguid

kunchenguid commented Jul 29, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#1109 at b4586b79.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: this PR still looks blocked on a rebase or merge conflict fix.

If you are still interested, please rebase onto the current base branch, resolve the conflict, and push.

If I do not hear back, I may close this as inactive.

@kunchenguid kunchenguid removed the wheelhouse:pending-contributor-action Managed by Wheelhouse label Aug 11, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment. Reopen if you want to pick it back up.

@edpqa

edpqa commented Oct 20, 2026

Copy link
Copy Markdown

/qa-gate

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.

3 participants