Skip to content

fix(bin): relisten when a remote delta read exits 0 with no output - #7822

Closed
trillium wants to merge 2 commits into
kunchenguid:mainfrom
trillium:fix/remote-reply-empty-read
Closed

trillium wants to merge 2 commits into
kunchenguid:mainfrom
trillium:fix/remote-reply-empty-read

Conversation

@trillium

Copy link
Copy Markdown
Contributor

Intent

Contribute to upstream kunchenguid/firstmate a single fix: in bin/fm-procevent-remote-reply.sh cmd_source, a remote delta read (fm-on.sh fm-remote-delta-read.sh) that exits 0 but prints nothing carries no delta; capturing it publishes an empty, unclassifiable result that wakes firstmate forever. Capture the read's output and, when the exit is 0 and the output is empty, treat it as an empty window (WINDOW_CLOSED_EMPTY, 75) so the source relistens. Regression test in tests/fm-remote-reply.test.sh via a fake remote that exits 0 with no output. One change only, forked from upstream main, no bundling; PR is opened against kunchenguid/firstmate from the trillium fork. No AI attribution or co-author trailers. Never merge.

What Changed

  • cmd_source in bin/fm-procevent-remote-reply.sh now captures the output of the fm-remote-delta-read.sh read to a temp file. If the read exits 0 and printed nothing, it treats the result as an empty window and returns the preempted code, so the source relistens. Otherwise it passes the output through unchanged. Previously this case published an empty, unclassifiable result that woke firstmate repeatedly.
  • This empty-output case records no caught-up watermark, because it does not show the channel is caught up.
  • tests/fm-remote-reply.test.sh adds a regression test that uses a fake remote exiting 0 with no output.

Risk Assessment

✅ Low: This is a small, bounded change to cmd_source: an exit-0 read with empty output now returns 75 without writing a watermark, as the user instructed, and every other exit code and non-empty output passes through as before.

Testing

I ran the changed regression test file; it passed, including the new exit-0 empty-read case. I then drove the real source CLI and the real process-event runner, on the change and on the base-commit adapter, with a fake ssh transport. On the base commit, an exit-0 empty read returned 0, so the runner published an empty 0-byte result and stopped listening with 1 pending. With the change, it returned 75 with no output and no watermark, and the runner stayed live. That run made 7 relisten reads and published 0 results. With the change, a genuine quiet window still returned 75 and recorded the caught-up watermark, and a real reply line still came through as an intact delta with rc 0. I ran the base-commit comparison only for the exit-0 empty case and the runner. Its other two cases failed on a temp-path setup check, so the evidence for those comes from the change side only. There is no UI surface. All temp copies were removed and the worktree is clean. The regression test file run is a unit test, not a live product drive, so it is recorded as untested for live purposes.

  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Remote read exits 0 with no output: source returns 75 (empty window) with empty stdout ✅ pass live source-cli-transcript.txt S1: after rc=75 stdout_bytes=0; before rc=0
Adversarial: exit-0 empty read must NOT record a caught-up watermark (user decision) ✅ pass live source-cli-transcript.txt S1 watermark=[]; tests/fm-remote-reply.test.sh new case asserts no epoch
Runner keeps relistening and never publishes an empty result to wake firstmate ✅ pass live procevent-runner-transcript.txt: after live/0 results/7 reads; before 1 empty 0-byte result, pending=1, stopped listening
No regression: genuine quiet window via real fm-remote-delta-read.sh still returns 75 and records the watermark ✅ pass live source-cli-transcript.txt S2: rc=75 watermark=[1793059107]
No regression: a real reply line is still delivered as an intact delta ✅ pass live source-cli-transcript.txt S3: rc=0 status=delta payload_bytes=46 with the reply line
Regression test in tests/fm-remote-reply.test.sh passes ⏸️ untested no The prior payload recorded this as a test-file run with live=false, so it did not establish a live result against the running product. The live behavior is covered by the other scenarios.
Evidence: source CLI transcript (after vs before)

Source: source CLI transcript (after vs before)

AFTER: S1 exit-0 empty -> rc=75 stdout_bytes=0 watermark=[] | S2 genuine quiet -> rc=75 watermark=[1793059107] | S3 reply line -> rc=0 status=delta payload_bytes=46 ... BEFORE: S1 exit-0 empty -> rc=0 stdout_bytes=0 (S2/S3 hit a temp-path setup check in the base copy and were not compared)

\### AFTER (8dcbaf5f)
== S1: remote read exits 0 with empty output (MODE=empty0)
rc=75 stdout_bytes=0 stdout=[] watermark=[]
== S2: genuine quiet window via real fm-remote-delta-read.sh
rc=75 stdout_bytes=0 watermark=[1793059107]
== S3: real reply line present in remote log
rc=0
schema=fm-remote-delta.v1
status=delta
path=state/parent-replies.status
from_offset=0
to_offset=46
from_prefix_sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
to_prefix_sha256=d36f1ca5731633e2bea3a26f9c543e4cdbabff6962809413b1f134a58fe3e835
payload_sha256=d36f1ca5731633e2bea3a26f9c543e4cdbabff6962809413b1f134a58fe3e835
payload_bytes=46
reason=

report=data/reply/report.md hello from remote
\### BEFORE (30e185d1 adapter)
== S1: remote read exits 0 with empty output (MODE=empty0)
rc=0 stdout_bytes=0 stdout=[] watermark=[]
== S2: genuine quiet window via real fm-remote-delta-read.sh
rc=64 stdout_bytes=51 watermark=[]
== S3: real reply line present in remote log
rc=64
error: remote root is not a safe existing directory
Evidence: process-event runner transcript (after vs before)

Source: process-event runner transcript (after vs before)

AFTER: owner=live pending=0, remote reads in 8s: 7, published results: 0 BEFORE: owner=none pending=1, remote reads in 8s: 1, published results: 1 (remote-reply-ios.1.result bytes=0)

\### AFTER (8dcbaf5f)
source-id=remote-reply-ios
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=0
SOURCE                       ADAPTER      OWNER      PENDING
remote-reply-ios             remote-reply live       0
remote reads attempted in 8s:        7
published results: 0
\### BEFORE (30e185d1 adapter)
source-id=remote-reply-ios
registered: remote-reply-ios (remote-reply)
armed: remote-reply-ios offset=0
SOURCE                       ADAPTER      OWNER      PENDING
remote-reply-ios             remote-reply none       1
remote reads attempted in 8s:        1
published results: 1
/private/tmp/fm-drv-run.7O8XBY/parent/state/procevent-inbox/remote-reply-ios.1.result bytes=       0
Evidence: regression test file log

Source: regression test file log

ok - an exit-0 empty remote read is an empty window, not a captured result ... ALL TESTS PASSED

ok - default delta reader waits 0.5 seconds then delivers a non-destructive complete-line delta
ok - override delta reader waits 0.07 seconds then delivers a non-destructive complete-line delta
ok - a blocking non-destructive remote delta reaches durable process-event capture
ok - a captured delta is applied, acknowledged, and re-armed without a handler
ok - ingest appends one validated line, fetches its document, and advances the cursor
ok - replayed capture has one deduplicated append and one durable handling identity
ok - later generations cannot invalidate an unacknowledged ingested result
ok - the remote status and decision model mirrors and the cursor advances
ok - a remote mate's new decision folds open exactly as a local mate's does
ok - a replayed mirrored delta is idempotent in both the stream and the cursor
ok - transported control bytes are normalized in place and never stop the stream
ok - payload protocol-field names cannot collide with transport metadata
ok - NUL bytes are normalized in place before shell line processing
ok - local document storage failures remain retryable until delivery succeeds
ok - a structured pointer must end at its token boundary
ok - adjacent pointers are fetched while malformed tokens remain unchanged
ok - a rejected candidate never gives the following text a false leading boundary
ok - nested remote reports relay while an undeliverable foreign pointer fails open
ok - the reported incident raises no standing decision and still delivers the report
ok - an undeliverable structured offer fails open with one note and never a decision
ok - a remote refusal surfaces its own reason without opening a decision
ok - a failed pointer extraction never commits a partial delta
ok - a failed mirror write never drops status content or advances the cursor
ok - source-line identity survives commit failure and cursor-loss recapture
ok - a mirrored reserved-key line cannot squat or clear the parent's own decision
ok - a reply that arrives after escalation resolves it and clears the open decision
ok - a remote reply listener stays owned across empty waits and a delta
ok - a failed remote read exits instead of relistening
ok - persistent ingestion failure leaves exactly one durable capture
ok - a preempted reply poll reports a closed window without publishing channel freshness
ok - a preempted reply poll keeps its listener and reconcile launches nothing
ok - a quiet reply window publishes the caught-up watermark the reply guard reads
ok - an exit-0 empty remote read is an empty window, not a captured result
ok - a cursor-loss whole-log recapture is acknowledged quietly with no duplicate wake
ok - truncation is detected, escalated once, and not silently rebased
ok - a repeated continuity break after an operator resolve appends nothing
ok - remote reply retirement quiesces and refuses unhandled captured results
ok - a later continuity break after repair and re-advance opens the decision again
ok - an old-format continuity line does not swallow the next break
ok - a later continuity break after the cursor moves without retirement opens the decision again
ok - a continuity break after retirement and an identical restore opens the decision once
ok - a failed cursor removal does not increase the retirement count
ok - a retirement that stops after removing the cursor leaves the old count
ALL TESTS PASSED

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-procevent-remote-reply.sh:319 - The new code rewrites an exit-0 empty read to rc=$WINDOW_CLOSED_EMPTY before the existing branch runs, so it also calls fm_pending_reply_note_remote_channel_caught_up and records a caught-up watermark at started. An exit-0 empty read is an anomaly: the real fm-remote-delta-read.sh exits 75 itself when a window closes empty, so this output usually means the read never really ran (for example, a transport glitch in fm-on.sh). That proves nothing about the channel being caught up, which is the same reason JOB_PREEMPTED deliberately skips the watermark. Failure path: a correlated report is sitting unread in the remote log, fm-on.sh returns 0 with no output, and the watermark is written with epoch >= since. The reply guard in fm-pending-reply-lib.sh:945 then treats the channel as caught up and can send a premature 'REPOST REQUIRED' recovery for a report that actually exists. Smallest remedy: send this case down the JOB_PREEMPTED-style path (return 75, record no watermark). It still meets the intent's 'empty window (75), relisten' requirement. Asking because the intent's wording 'treat it as an empty window' could be read to include the watermark.
  • ℹ️ bin/fm-procevent-remote-reply.sh:317 - The new mktemp capture file is removed only on the normal path. If the source is terminated while it blocks in the long-poll, the file stays in TMPDIR. The files are small and empty or bounded, and the impact is minor.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Remote read exits 0 with no output: source returns 75 (empty window) with empty stdout ✅ pass live source-cli-transcript.txt S1: after rc=75 stdout_bytes=0; before rc=0
Adversarial: exit-0 empty read must NOT record a caught-up watermark (user decision) ✅ pass live source-cli-transcript.txt S1 watermark=[]; tests/fm-remote-reply.test.sh new case asserts no epoch
Runner keeps relistening and never publishes an empty result to wake firstmate ✅ pass live procevent-runner-transcript.txt: after live/0 results/7 reads; before 1 empty 0-byte result, pending=1, stopped listening
No regression: genuine quiet window via real fm-remote-delta-read.sh still returns 75 and records the watermark ✅ pass live source-cli-transcript.txt S2: rc=75 watermark=[1793059107]
No regression: a real reply line is still delivered as an intact delta ✅ pass live source-cli-transcript.txt S3: rc=0 status=delta payload_bytes=46 with the reply line
Regression test in tests/fm-remote-reply.test.sh passes ⏸️ untested no The prior payload recorded this as a test-file run with live=false, so it did not establish a live result against the running product. The live behavior is covered by the other scenarios.
  • bash tests/fm-remote-reply.test.sh (whole file, includes the new 'an exit-0 empty remote read is an empty window, not a captured result' case): ALL TESTS PASSED
  • Manual driver: called the real fm-procevent-remote-reply.sh source ios through the real fm-on.sh / fm-remote-entrypoint.sh / fm-remote-delta-read.sh path with a fake ssh transport. Ran 3 cases (exit-0 empty, genuine quiet window, real reply line) on the change and on the base-commit adapter
  • Manual driver: fm-procevent-remote-reply.sh arm ios + fm-procevent.sh start remote-reply-ios for 8s with an ssh transport that always exits 0 with no output, then fm-procevent.sh list and a count of published .result files; ran on the change and on the base-commit adapter
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A remote delta read that exits 0 yet prints nothing carries no delta.
Capturing it published an empty, unclassifiable result that woke
firstmate forever. Capture the read's output and report an empty window
(75) when it is empty, so the source relistens instead.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge and matches the stated intent.

Reviews (1) · Last reviewed commit: "no-mistakes(review): Skip caught-up wate..." · Reviewed by Greptile

@trillium

trillium commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Trillium Firstmate here 🤖

Closing as superseded:

  • Current main already classifies a remote read that exits 0 with no output as malformed and stops it from being published. That fixes the endless-wake bug this PR addressed.
  • Main deliberately exits rather than relistening on a failed read, so this change is no longer needed.

@trillium trillium closed this Nov 7, 2026
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.

1 participant