Skip to content

fix(bin): publish queued process-event results once - #7762

Open
zestysoft wants to merge 3 commits into
kunchenguid:mainfrom
zestysoft:fm/firstmate-procevent-publish-once
Open

zestysoft wants to merge 3 commits into
kunchenguid:mainfrom
zestysoft:fm/firstmate-procevent-publish-once

Conversation

@zestysoft

@zestysoft zestysoft commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #8410

Intent

The fix that stops one captured notification from being re-announced on every monitoring pass - the flood that filled the captain's screen and falsely reported nine jobs in flight - is open as a pull request and has now been reviewed by the upstream maintainers, who accept the diagnosis: they confirmed that on the current release every pass re-publishes the downtime marker, that our fix closes that under the queue lock and still retries once the row is answered, and that the change touches no workflow, network, or credential surface. They also flagged a competing pull request from another contributor fixing the same block, and said which one lands is their captain's decision, so ours is one of two candidates.

Two things are asked of us before it can be considered at all. The submission must go through the validation pipeline, because it was submitted with the pipeline skipped and that check blocks the merge; and six serial test jobs went red on the current head - most look like timing or runner trouble outside the changed file, but several are wake-queue tests, which is exactly the area we touched, so they need a real look rather than a shrug.

Deliverable: the same pull request, carrying a head that has been through the pipeline, with those jobs reported honestly.

What Changed

  • bin/fm-procevent.sh: reconcile no longer re-appends a captured but unhandled result on every pass. Under the wake-queue lock, it checks for a queued check row with the same procevent:<id>:<seq> key and payload. If that row is there, it does nothing, so the downtime marker is not touched either. If the row is gone, it appends the result again, so a result is still retried until it gets a handled acknowledgement.
  • tests/fm-procevent.test.sh: added tests for:
    • concurrent reconciles against an already queued row, which leave the queue at one line and the recovery marker unchanged
    • a row removed under the queue lock while publication waits, which is published again
    • rows whose key or payload does not match, which do not suppress publication; repeated generic wakes also stay distinct
  • tests/fm-watch-recovery-loop.test.sh: added tests for repeated re-arms through the real Pi host. One re-arms a captured but unhandled result; the other is an empty-queue control using an idle long-poll source. Comments in bin/fm-procevent.sh and the docs in docs/configuration.md, docs/verification/process-event-sources.md and docs/watcher-continuity.md now describe the queued-row check.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The fix only changes procevent result publication. It checks for an existing row and appends under the same wake-queue lock that drain acknowledgement uses, and it keeps the existing source-lock-then-queue-lock order. A missing row is still retried, and the success and "published" count meaning does not change for callers (capture autohandle, the reconcile output, and remote-reply and extension tests). The round-1 fix that isolates the claim root is correctly applied: the claim root is passed to register, to the node command() calls through process.env, and to the sweep registry.

Testing

The Test agent exceeded its invocation budget before live validation completed; no evidence was gathered for this head.

  • Outcome: ⚠️ 1 warning across 1 run (30m2s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ tests/fm-watch-recovery-loop.test.sh:178 - The new run_repeated_rearm_case never sets FM_PROCEVENT_CLAIM_ROOT. So its register, its reconcile calls and the node command() calls all use the default claim root ${XDG_STATE_HOME:-$HOME/.local/state}/firstmate/procevent-claims (bin/fm-procevent-lib.sh:35). Claim and lock files are keyed only by source id (fm-procevent-lib.sh:330-336). Both cases use the same ids, idle and review. Here is what goes wrong: the captured case starts an idle runner that lives up to 180s. That runner is reaped only by the file's EXIT cleanup (tests/lib.sh:345), so it still holds idle.claim when the empty case registers idle in a different home. The empty case's reconcile cannot claim it, because a live owner from another home holds it. Then fm-procevent.sh list reports live from the pid state alone (cmd_list -> fm_procevent_claim_state_locked, fm-procevent.sh:2431). So the T5 assertion that the idle long-poll source is live (line 256) passes off the T4 runner, not its own. The test also writes claim and lock files into the developer's real ~/.local/state, and generic ids like review/idle can contend with a live install's sources. Fix: in run_repeated_rearm_case, export FM_PROCEVENT_CLAIM_ROOT=&#34;$dir/claims&#34; before the register and node steps (process.env already carries it into command()). Also call fm_test_track_procevent_home &#34;$home&#34; &#34;$dir/claims&#34; so the sweep uses the same root, the way tests/fm-procevent.test.sh:21 and the bearings tests do.
  • ℹ️ bin/fm-procevent.sh:898 - The inline awk presence check (lines 898-901) re-implements fm_wake_queued_carries_locked (bin/fm-wake-lib.sh:2423). That helper already exists to check, under the held queue lock, whether a queued row of <kind> for exactly <key> carries <payload>. Calling fm_wake_queued_carries_locked check &#34;$key&#34; &#34;$payload&#34; || fm_wake_append_locked check &#34;$key&#34; &#34;$payload&#34; would drop the second copy of the queue-row matching rule and add the helper's NF>=5 guard. The helper matches by substring rather than exact payload. That makes no difference here, because the key already pins source id and sequence, and the payload is built from the validated procevent &lt;adapter&gt; &lt;id&gt; &lt;seq&gt; line.

🔧 Fix applied.
1 info still open:

  • ℹ️ bin/fm-procevent.sh:898 - The inline awk presence check (lines 898-901) re-implements fm_wake_queued_carries_locked (bin/fm-wake-lib.sh:2423). That helper already exists to check, under the held queue lock, whether a queued row of <kind> for exactly <key> carries <payload>. Calling fm_wake_queued_carries_locked check &#34;$key&#34; &#34;$payload&#34; || fm_wake_append_locked check &#34;$key&#34; &#34;$payload&#34; would drop the second copy of the queue-row matching rule and add the helper's NF>=5 guard. The helper matches by substring rather than exact payload. That makes no difference here, because the key already pins source id and sequence, and the payload is built from the validated procevent &lt;adapter&gt; &lt;id&gt; &lt;seq&gt; line.
⚠️ **Test** - 1 warning
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s (silent budget; no still-working cap is set; ran 30m1s): agent last produced output 1s ago (60 observed); agent reported: claude parse events: context deadline exceeded. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely stay quiet longer than the default 30m0s, raise test_agent_timeout in global config. If the turn was still producing output or running a child process, set or raise test_agent_working_timeout there instead: a turn runs past test_agent_timeout only up to that still-working cap. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Thank you @zestysoft. This is a real defect, and the reproduction you described (7 announcements for one unhandled result) is a convincing regression to pin it with.

What I checked on b89306cf against main 2b46ed1f. On main, publish_result calls fm_wake_append on every reconcile, and every append re-publishes the .watcher-down downtime marker. So one unhandled result keeps adding rows and reopening recovery. Your fix checks and appends under the wake-queue lock, skips the append when the identical check row (same key and same payload) is already queued, and still retries once the row is gone. That looks right. The diff touches bin/fm-procevent.sh and two test files only, with no workflow, network, or credential surface. It's MERGEABLE.

Overlap: #7764 from @niks0501 fixes the same thing. Both PRs change the same publish_result block, so only one can land as written. The differences I see:

Which one goes in is Kun's call. I'm not closing either.

Contract class: new-default (my read). The reconcile header on main spells out the current behavior: republish every unhandled result "on every call regardless of any earlier publication." Both PRs replace that specified default with "publish once while queued." It's a sensible fix that aligns with VISION (less noise, and a queued wake is still retired only by its answering record), but it changes a documented default path, so it goes to Kun rather than auto-merge. VISION: one-captain aligns (less recovery noise), authority aligns (no new autonomy), scripts aligns (exact lock-held check), restart aligns (retry after the row is consumed, handled ack still the only stop), spine/vendor/scope align.

What this needs from you:

  1. no-mistakes: the PR must be raised via no-mistakes check failed on this head, and your description says the pipeline was skipped. That check blocks the merge, so could you re-raise through git push no-mistakes? That also gives CI a fresh run.
  2. CI: six serial jobs went red on run 40264141694: serial 1 latch hand-back, serial 3 "a wake whose line could not be written must stay queued", serial 4 contribution re-ring, serial 6 watcher checkpoint, serial 7 PR-health re-wake, and serial 9 checkpoint exit 137. Most look like timing and runner trouble outside fm-procevent.sh, but a few are wake-queue tests, so please glance at them on the re-raised head. If they come back green, there's nothing more to do there.

So this is waiting on you for the no-mistakes re-raise. Once a head is green with the attestation bound to it, it goes to Kun alongside #7764 as a pick-one decision.

@zestysoft
zestysoft force-pushed the fm/firstmate-procevent-publish-once branch from b89306c to 0543dd2 Compare October 26, 2026 07:19
@zestysoft zestysoft changed the title Make queued process-event result publication idempotent fix(bin): publish queued process-event results once Oct 26, 2026
@zestysoft

Copy link
Copy Markdown
Contributor Author

Re-raised through no-mistakes as asked: this PR now carries 0543dd207c5f30406ce3a1f6bd7765c2f26b87af, rebased onto main 127f0f30, and PR must be raised via no-mistakes passes.

The product change is unchanged: dedupe on exact key + payload under the wake-queue lock.
The pipeline added two follow-ups.
One isolates the new re-arm regression's procevent claim root, so it no longer shares claims with ~/.local/state or with the other test case.
The other is a comment and docs wording update.

What I compared. CI run 40285140146 on this head, against CI run 40280579086 on main 127f0f30 without this PR:

  • Serial 1, 3, 4, 5, 6, 7 and 9 fail on main too, in the same test files: fm-supervision-host, fm-public-followup, fm-contributions, fm-fleet-ledger / fm-herdr-groups (watcher checkpoint did not run), fm-record-export, fm-remote-secondmate-lifecycle-e2e, fm-pr-health / fm-backend-rex, and fm-watch-checkpoint (exit 137).
    For serial 1, a different wait_until times out on each run.
  • None of those files touch process events.
    The watcher only calls fm-procevent.sh reconcile when state/procevent exists, and none of them register a source.
  • The files this PR touches all pass on the runner: fm-watch-recovery-loop, fm-procevent (the whole file) and fm-wake-queue.
  • Serial 2 and 8 were cancelled at the 30-minute job timeout, with no failing test.
    They need their own rerun, not a code change.

Regression proof on this head. With main's bin/fm-procevent.sh restored, the re-arm regression fails with "recovery flood for one unresolved result: 5 announcements".
With the fix, the same file passes 5 of 5.

One note on the pipeline record: its test step hit its 30-minute agent budget and was approved past, so the outcome reads passed-with-override, not a clean test pass.
Before the cut it ran fm-watch-recovery-loop (5/5), fm-wake-queue (70/70) and fm-procevent (144 passed, then it stopped at a pre-existing setsid call at line 5121 that macOS lacks, which this diff does not touch).
The CI step was also approved past the red jobs above, since main already fails them.

@zestysoft

Copy link
Copy Markdown
Contributor Author

Closing and immediately reopening this PR to get a fresh CI run on the unchanged head 0543dd207c5f30406ce3a1f6bd7765c2f26b87af. No new commit, and the no-mistakes attestation still binds this head (PR must be raised via no-mistakes passes).

Why: the red shards on run 40285140146 came from its merge commit against main 127f0f30, and main itself failed the same tests at that commit (run 40280579086, serials 3, 4, 5, 6, 7, 9 and fm-supervision-host in serial 1, all on ubuntu-26.04). Main has since fixed that: #7798 pins Linux jobs to ubuntu-24.04, and #7838 splits the monolithic supervision-host test and adds a 10th serial shard. A re-run would reuse the old merge commit, so a reopened event is needed to build a new one against current main. The head still merges cleanly onto current main.

Also for context: #7764, the alternative fix, was closed by its author on 2026-10-28 without merging, and main has no bin/fm-procevent.sh change since, so the duplicate-publish bug is still open there.

@zestysoft zestysoft closed this Oct 29, 2026
@zestysoft zestysoft reopened this Oct 29, 2026
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes appear safe to merge; no actionable defects were found.

Reviews (1) · Last reviewed commit: "no-mistakes(document): Document queued-r..." · Reviewed by Greptile

@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 12, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @zestysoft, and sorry for the slow follow-up. Your 10-26 and 10-29 replies answer both of my asks.

What I checked on head 0543dd20 against main a9ae3c0c: publish_result now checks for an identical queued check row (same procevent:<id>:<seq> key and payload) and appends under the wake-queue lock. A duplicate never reopens the recovery marker, and a row that's gone is published again until the handled acknowledgement arrives. Main still has the "republishes on every call" behavior, and #7764 closed without merging, so this is still needed (#8410). No workflow, network or credential changes. It merges cleanly.

Gates: the no-mistakes attestation binds this head with every step completed. You disclosed that the test step was approved past its 30-minute budget. The "PR must be raised via no-mistakes" check passes. The 10-29 CI run on this head was green on every lane. Greptile is 5/5 with no open threads. Your regression proof covers it (main's file gives 5 announcements, the fix passes 5/5 through the real Pi host fixture).

Contract class (my read): new-default. It replaces main's documented "republish every unhandled result on every call" with "publish once while queued". I've queued the full suite. If it's green, this goes to Kun for a merge-or-leave call. Nothing more is needed from you right now.

@kunchenguid kunchenguid added full-ci Maintainer go-ahead: run the full CI suite on this outside pull request and removed full-ci Maintainer go-ahead: run the full CI suite on this outside pull request labels Nov 12, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @zestysoft. The full suite is green on 0543dd20 (run 43331794317, all 22 jobs pass). Nothing else has changed since my last comment. The no-mistakes attestation still binds this head with no skipped steps, Greptile is 5/5 with no open threads, and it merges cleanly with current main ed7fbb84.

Status: with the captain for a decision. This isn't waiting on you. Contract class (my own read): new-default. publish_result changes from main's documented "republish every unhandled result on every call" to "publish once while that row is queued". That changes default behavior, so Kun makes the merge-or-leave call himself. VISION.md: every rule aligns. There's nothing more for you to do here unless Kun asks.

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

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Captured process-event result is re-published on every reconcile pass, flooding notifications

2 participants