Skip to content

fix(watcher): close afk daemon catch-all orphan-signal gap - #468

Closed
indrasantosa wants to merge 7 commits into
kunchenguid:mainfrom
indrasantosa:fm/fm-pr326-rebase
Closed

indrasantosa wants to merge 7 commits into
kunchenguid:mainfrom
indrasantosa:fm/fm-pr326-rebase

Conversation

@indrasantosa

Copy link
Copy Markdown

Intent

Rebase PR #326 (watcher orphan-signal fix) onto current main and extend it to close the afk daemon's shared catch-all scan gap flagged by Codex review, then get it through validation for a clean, mergeable PR

What Changed

  • Extend the watcher's orphan-marker guard (bin/fm-watch.sh, bin/fm-classify-lib.sh) so the afk daemon's shared catch-all scan path also filters orphaned .status/.turn-ended/.check.sh signals, instead of only the primary per-wake path.
  • Fix the no-mistakes-required CI check to read the PR's live body instead of a stale cached copy when evaluating the gate.
  • Sync .agents/skills/afk/SKILL.md, docs/architecture.md, and CONTRIBUTING.md to describe the extended guard behavior.
  • Extend/add coverage in tests/fm-watch-triage.test.sh, tests/fm-daemon.test.sh, and related afk/watcher e2e and unit tests for the catch-all guard path.

Risk Assessment

✅ Low: The orphan-signal guard is applied consistently (scan_signals, check.sh loop, and the shared scan_captain_relevant_statuses helper) with the correct x-watch.check.sh exemption preserved, is race-safe against fm-spawn.sh's meta-before-launch ordering and fm-teardown.sh's meta-removed-last cleanup order, and is backed by thorough new/updated tests across both the watcher and daemon test suites; the unrelated CI fix (re-fetching the live PR body via gh instead of the stale webhook payload) is a small, correctly-scoped, read-only permission addition.

Testing

Completed 1 recorded test check.

  • Outcome: ⚠️ 1 error across 4 runs (1h17m30s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 error
  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"

🔧 Fix: waiting for background full test suite run to finish before final summary
1 error still open:

  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"

🔧 Fix: Confirm rebase tests pass; remaining failures are pre-existing environment issues
1 error still open:

  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"

🔧 Fix: confirm diff-scoped tests pass; other failures are pre-existing env gaps
1 error still open:

  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3688060efd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/fm-watch.sh
Comment on lines +431 to +434
if [ ! -e "$STATE/$task.meta" ]; then
triage_log "absorbed orphan signal (no state/$task.meta): $f"
rm -f "$f" 2>/dev/null || true
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recheck meta after signal coalescing

Captain, this guard only filters files at the moment scan_signals runs, but entries captured before SIGNAL_GRACE are still classified after the sleep even if teardown removes state/<id>.meta during that grace window. In that teardown race, the old pending row reaches signal_crew_provably_working, fm-crew-state sees no meta and returns none, and the watcher enqueues a signal wake for an unowned file despite the new orphan guarantee. Revalidate the coalesced pending set against matching .meta files before classification/queueing.

Useful? React with 👍 / 👎.

…gnals

fm-teardown.sh removes a task's .status, .turn-ended, .check.sh, and .meta
together in one rm -f, so a live task always has a matching state/<id>.meta.
scan_signals() and the check.sh sweep had no such check, so any marker file
that outlives its .meta (e.g. a harness turn-end hook whose command line
baked in the absolute state path before teardown ran, still firing if its
process outlives teardown's best-effort backend kill) got surfaced as an
actionable "signal:" wake forever, resetting the heartbeat backoff every
cycle. Skip and best-effort remove any *.status/*.turn-ended/*.check.sh with
no matching .meta before it ever reaches classification, so an orphan can
never wake firstmate regardless of what keeps touching it.

Several existing watcher tests created .status/.turn-ended fixtures with no
.meta (harmless before this change, since nothing checked for one); updated
them to add a .meta fixture so they keep exercising live-task behavior
instead of accidentally becoming orphan-absorb cases.
The no-mistakes push pipeline pushes commits and edits the PR
description as separate steps, so a synchronize-triggered run can
still see the pre-pipeline draft body via the frozen webhook event
payload and fail even though the pipeline's marker lands moments
later. Fetch the current body via `gh pr view` instead of trusting
github.event.pull_request.body.
scan_captain_relevant_statuses (shared by the watcher's heartbeat
backstop and fm-supervise-daemon.sh's housekeeping catch-all) had no
matching-state/<id>.meta guard, so an orphaned .status could still
surface under afk even after the per-wake scan_signals fix. Apply the
same skip-and-remove guard there, closing the gap in the one shared
function that backs both consumers.
@kunchenguid

kunchenguid commented Jul 17, 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#468 at 043b7725.

@indrasantosa

Copy link
Copy Markdown
Author

Closing: superseded/abandoned. Rebase drifted into conflict with base and the underlying crewmate run failed; not worth pursuing further right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants