Skip to content

fix: prefilter inbox history for idempotent remote steering - #7905

Merged
kunchenguid merged 3 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-7785
Oct 30, 2026
Merged

kunchenguid merged 3 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-7785

Conversation

@WTF-Am-ID

@WTF-Am-ID WTF-Am-ID commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #7785

Intent

ok same instructions i gave you before pick high value issues from scan, in all the repos you scanning and use codex only to close them

Context: this task is scan pick P9: upstream issue #7785 in kunchenguid/firstmate. Idempotent remote steering scans every handled message under the lock and can exceed its delivery budget. Triage contract class: restore. Scan notes for this pick:
Issue: #7785

Idempotent remote steering scans every handled message under the lock and can exceed its delivery budget.
Maintainer-approved bounded prefilter removes a measured scaling cost without deleting records.
Size M.
Contract class: restore.
Maintainer triage.

Evidence: bin/fm-task-inbox-lib.sh:254-304 still parses and compares every inbox/handled record. The issue reports 11 seconds at 1,000 records and 41 seconds at 2,500. These are upstream measurements, not fresh timings by this scout.

Competing work: No exact target or scale fix found. #7453 adds read receipts and #6095 repairs framing. Neither targets the full-history scan cost. The maintainer explicitly invites an exact-match prefilter and forbids conflating it with pruning.

Closure test: Build large synthetic pending/handled histories, including same first line but different bodies, multiline bodies, empty/unterminated legacy bodies and both delivery modes. Exact retries must reuse the correct record and different requests must not collapse. Measure parser/comparison invocations so a mostly unrelated history is prefiltered instead of parsed record by record. Compare bounded runtime with baseline on this Mac, retain all records, and run tests/fm-task-inbox.test.sh through bin/fm-test-run.sh.
The owner approved fixing the scan's high-value picks upstream through PRs, written and reviewed by Codex only.

What Changed

  • Prefilter pending and handled inbox records using the requested body's first line before exact body and delivery-mode checks, retaining all records.
  • Fall back to a full scan on prefilter errors. Add regression coverage for large histories, distinct multiline bodies, empty and unterminated legacy bodies, and both delivery modes.

Risk Assessment

✅ Low: The bounded prefilter preserves exact-body and delivery-mode comparisons, retains all records, and handles acknowledgement moves and grep errors without expanding scope.

Testing

Follow-up head: 5923ff358d7a0e1c4b518489ac34a6d27ef5440b.

The no-mistakes CI repair added test_idempotent_write_follows_ack_before_prefilter_open.
It moves the matching record before pending grep opens it, then checks pending-before-handled ordering, the handled result, exact body bytes and retained history in both delivery modes.
The focused suite and canonical lint passed.
Reversing only the directory scan order in a disposable copy made the new regression fail.

A separate reviewer cloned the exact follow-up head afresh and ran bash bin/fm-test-run.sh tests/fm-task-inbox.test.sh, exit 0 with no skips.
The result was FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=93333.

The author drove the actual Bash enqueue functions in a marked disposable home on that exact head, with guards enabled.
Exact retries reused the pending record and its handled path after acknowledgement.
The same body with a different delivery mode remained a separate record.
With 1,000 records created through the real writer, pending and handled retries took 0.087s and 0.093s, retained all 1,000 records, and left each before/after inventory hash unchanged.
The author follow-up contains the detailed transcript.

The original managed Test result remains inconclusive with its recorded exception.
This CI repair used the existing pipeline's continuity path and did not rerun its Test phase.
The fresh evidence above is an author-run real product probe and an independent local closure run.
It does not repeat the baseline comparison or every originally listed live scenario.

Greptile and current-head no-mistakes compliance pass.
The full-suite CI run is not green because a maintainer must add the full-ci label before the behavioral jobs run.
Its only failure is the Full suite approval gate, with FM_CI_FULL=false.
No check or test exception was newly approved for this follow-up.

Review remains single-family Codex under the owner's campaign exception.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 2 warnings
  • ⚠️ The command guard rejected the isolated product driver and baseline benchmark with 'Indirect command execution not allowed.' Focused regression passed, but live behavior and fresh baseline performance remain unverified. Provide a guard-approved execution path for these probes before treating live validation as complete.
  • ⚠️ live validation verdict: inconclusive (0 of 4 scenarios were driven live against the product); untested: Exact retries reuse pending and handled records while distinct bodies and delivery modes remain separate, Empty, multiline, and unterminated legacy messages retain exact retry identity, Retries across 1,000 and 2,500 unrelated records avoid per-record parsing, outperform baseline, and retain history, Prefilter errors and concurrent acknowledgements preserve retries without duplicate records
  • Live validation: ⚠️ inconclusive - 0 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Exact retries reuse pending and handled records while distinct bodies and delivery modes remain separate ⏸️ untested no Focused fixture tests passed. The separate driver invoking the real enqueue function in disposable homes was rejected by the command guard. A guard-approved product-driving path is required; rerouting…
Empty, multiline, and unterminated legacy messages retain exact retry identity ⏸️ untested no Focused fixture tests passed. Live probes were part of the guard-rejected isolated driver and did not execute. A guard-approved execution path is required.
Retries across 1,000 and 2,500 unrelated records avoid per-record parsing, outperform baseline, and retain history ⏸️ untested no The focused regression passed its operation-count and retention checks. The fresh baseline comparison and product timing probes were rejected by the command guard. No baseline timings were measured in…
Prefilter errors and concurrent acknowledgements preserve retries without duplicate records ⏸️ untested no Focused tests passed simulated filter-error and acknowledgement-race cases. A real filesystem-error probe was included in the rejected driver and did not execute. Live confirmation requires a guard-ap…
  • git diff 417cec2feb4e2976c0acdb2527b87b3ccc71535f 1fc3c031244beccaff1d5da81f74da884d2802c9 -- bin/fm-task-inbox-lib.sh tests/fm-task-inbox.test.sh
  • TMPDIR="$PWD/.test-7785/tmp" bash bin/fm-test-run.sh tests/fm-task-inbox.test.sh --per-script-timeout-secs 300 --json ~/.no-mistakes-upstream-codex/evidence/01M615QHKDGG5Y2RA6EJ9T9Z1F/inbox-focused-timing.json exited 0 with no skips.
  • Attempted isolated product driver and baseline benchmark; the command guard rejected the command before execution.
  • Inspected regression output, retained evidence, removed transient worktree directories, and confirmed a clean working tree.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings.

Reviews (2) · Last reviewed commit: "test(inbox): cover acknowledgement befor..." · Reviewed by Greptile

Comment thread tests/fm-task-inbox.test.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @WTF-Am-ID. Your 37.68s → 0.30s numbers at 1,000 records are a big win.

What I checked (tip 7c794350 vs main): fm_task_inbox_write_idempotent now prefilters each directory with one grep -lFx --null on the body's first line (-- for empty bodies), scans pending before handled, and still requires the exact mode and body before deduping. With no match, grep returns 1 and the scan is skipped. An error (rc ≥ 2) falls back to the full listing, and an empty glob still goes through the existing missing-path branch. Nothing is pruned from handled/. CI is 20/20 on Actions and the NM attestation binds the head.

Contract-class: restore. Exact-retry idempotent remote steering is the existing default path, and history growth was pushing it past its delivery budget. Same dedup semantics, no new surface.

Two asks before merge:

  1. Live evidence: live validation came out 0/4, inconclusive, because your guard refused the product driver. Could you drive the real enqueue in a disposable home (exact retry reuses the pending/handled record, a different mode stays separate, and the 1k-record timing) and post the transcript? Re-raising through git push no-mistakes with those scenarios driven works too.
  2. Greptile P2 (tests/fm-task-inbox.test.sh:557): add a regression that moves the matching record to handled/ before the pending grep opens it. That protects the new pending-then-handled ordering guarantee, and it also clears the red Greptile check.

Waiting on you for these.

@WTF-Am-ID

Copy link
Copy Markdown
Contributor Author

The requested regression is in 5923ff358d7a0e1c4b518489ac34a6d27ef5440b, and the real enqueue probes passed on that exact revision.

test_idempotent_write_follows_ack_before_prefilter_open moves the matching record inside the actual prefilter invocation, before command grep opens the pending path.
It asserts pending-before-handled ordering, the handled result, exact body bytes, and unchanged history for ordinary and fire-and-forget modes.
Reversing only the directory scan order in a disposable copy makes the new regression fail.

The real Bash enqueue functions were driven in a marked disposable home on that exact revision, with guards enabled and no replacement CLI.
The identity case returned the same pending record, returned that record from handled/ after acknowledgement, and kept a separate record for the same body in a different delivery mode.
The scale history was built through the real writer.

The probe sourced bin/fm-task-inbox-lib.sh and called fm_task_inbox_write_idempotent directly.
The history setup used fm_task_inbox_write for 999 unrelated records, followed by one matching record.
The recorded launch commands were:

bash bin/fm-lab-home.sh create "$PWD/.ci-7905/lab"
FM_HOME="$PWD/.ci-7905/lab" bash .ci-7905/enqueue-probe.sh
revision=5923ff358d7a0e1c4b518489ac34a6d27ef5440b
product=bin/fm-task-inbox-lib.sh
driver=direct Bash, disposable FM_HOME
pending_exact_retry=same_record
acknowledged_exact_retry=handled_record
different_delivery_mode=distinct_record
identity_record_count=2
1000_record_pending_retry_seconds=0.087
pending_retained_count=1000
pending_hash_before=aff6ae038d7111b5711cf4dbbbb81c27bb507a9f30c3776957eba89c00857cdd
pending_hash_after=aff6ae038d7111b5711cf4dbbbb81c27bb507a9f30c3776957eba89c00857cdd
1000_record_handled_retry_seconds=0.093
handled_retained_count=1000
handled_hash_before=d0876b9d47d5a5a934487748f05d0f26cb39f2cf782b00bde2f59bd159a9392a
handled_hash_after=d0876b9d47d5a5a934487748f05d0f26cb39f2cf782b00bde2f59bd159a9392a
real_enqueue_probe=PASS
exit=0

The inventory hashes cover sorted SHA256-per-record rows including each path.
The acknowledgement move occurs between the pending and handled snapshots.
These are observed retry times, not a new baseline comparison or an enforced timing ceiling.

The focused suite and canonical lint passed in the no-mistakes CI repair.
A separate reviewer also cloned this exact revision afresh and ran bash bin/fm-test-run.sh tests/fm-task-inbox.test.sh, exit 0, with no skips and FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=93333.
That is fresh independent local closure evidence.
The original managed Test exception remains recorded, because the repair used the existing pipeline's continuity path and did not rerun its Test phase.

Greptile and the current-head no-mistakes compliance check pass.
The current CI run requires a maintainer to add full-ci before the behavioral jobs run.
Its only failure is the Full suite approval gate, with FM_CI_FULL=false.
Please add that label to run the required suite.

@kunchenguid

kunchenguid commented