Skip to content

fix(bin): keep a merge poll armed after a task record is written to - #3615

Open
svycka wants to merge 4 commits into
kunchenguid:mainfrom
svycka:fm/fm-hold-meta-order
Open

svycka wants to merge 4 commits into
kunchenguid:mainfrom
svycka:fm/fm-hold-meta-order

Conversation

@svycka

@svycka svycka commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The bug

bin/fm-captain-hold.sh complete appended its two bookkeeping keys to the end of state/<id>.meta:

printf 'decisions_reviewed=1\ndecision_keys=%s\n' "$keys" >> "$meta"

When the task already carried a pr= line - armed earlier by bin/fm-pr-check.sh - those keys landed after it. fm_pr_metadata_identity_parse in bin/fm-pr-lib.sh treated any line after pr= that was not pr_head= or one of the whitelisted x_* keys as evidence of tampering and returned 1. fm_pr_poll_artifacts_valid then failed, and bin/fm-watch.sh classified the task's own armed merge poll as an unauthenticated check:

check: rejected unauthenticated state checks: /path/state/<id>.check.sh

The merge poll stayed disarmed for the rest of that task's life, so the merge was never detected or reported, and the operator was handed a security-shaped wake naming the wrong problem.

The ordinary documented lifecycle produces this every time: arm the poll when the PR opens, then attest the captain-call inventory. Both are required by AGENTS.md section 7. Reproduced in the field on two consecutive tasks before this fix.

The fix

fm_pr_metadata_identity_parse no longer binds a task record's PR identity to line position. Position carries no meaning in that file: a task record has several legitimate writers that add or rewrite their own unrelated keys at the end, and no reader can require an ordering that every future writer would have to know about.

What the identity actually depends on is checked instead, from either side of pr=: exactly one pr= that parses to a canonical URL, and at most one pr_head=, always validated.

That is stronger than the rule it replaces, not weaker:

  • the positional rule skipped a pr_head= written before pr=, while every consumer reads that value with tail -1; the new rule validates it wherever it appears
  • a second, differing pr_head= was previously accepted; it is now refused
  • newline injection through either value - which the positional rule caught only by accident - is refused at bin/fm-pr-check.sh, the only path that writes them

fm_meta_set is added as the shared, tested writer for task records, replacing the last bare append. It sets keys in place atomically, so a re-attestation no longer grows the record. bin/fm-promote.sh and bin/fm-x-lib.sh have the same append shape; with the reader fixed, neither can reproduce this.

No recovery path is needed, and that is the point: records carrying the keys after pr= were never invalid, the reader was wrong. They read correctly now, so nothing exists that could be tricked into accepting a genuinely untrusted check.

Tests

  • tests/fm-captain-hold-lifecycle.test.sh - the two-step lifecycle through the real watcher, red before this change and green after (verified by reverting the fix, both with and without the writer change)
  • tests/fm-pr-check-security.test.sh - the parser's semantics in both directions, and the write path's refusals
  • tests/fm-backlog-atomicity.test.sh - fm_meta_set

🤖 Generated with Claude Code

https://claude.ai/code/session_01VY412eng1vpDbK3Kv2vgKg

The ordinary no-mistakes lifecycle requires two steps of every ship task:
arm the merge poll when the PR opens, then attest the captain-call
inventory. Doing both silently and permanently disarmed the poll.

The attestation appended `decisions_reviewed=1` and `decision_keys=` to
the end of the task record, landing them after the `pr=` line the poll
had already recorded. The PR identity reader treated any unrecognised
line after `pr=` as tampering, so the armed, legitimate poll failed
authentication for the rest of the task's life: the merge was never
detected, and the operator got a security-shaped notice naming the wrong
problem instead of the merged PR.

Line order is not a property a shared record can hold. A task record has
several writers that legitimately rewrite or add their own keys at the
end, and the reader had already been patched once to whitelist one such
writer's keys. Bind the identity to what it actually depends on instead:
exactly one `pr=` that parses, at most one `pr_head=`, always validated,
and every other key ignored wherever it sits.

That is a relaxation in one direction and a tightening in two. A head
written before `pr=` used to escape validation entirely while every
consumer reads it back with `tail -1`, and two valid but differing heads
used to be accepted with no way to say which one the record meant. The
positional rule's one real guarantee - that a forge-supplied value with
an embedded line break cannot smuggle a second key into the record - now
sits explicitly at bin/fm-pr-check.sh, the only writer of those values.

Because the record was never actually invalid, this also repairs every
record already broken in the field with no recovery path to get wrong.

On the writer side, add fm_meta_set as the one owner of setting a key in
a task record: it replaces prior lines for the keys it sets, publishes
through the same atomic path a record change already uses, and refuses a
key or value that would write an unattributable line. The attestation
uses it, so the last bare append into a task record is gone along with
the unbounded growth it caused on re-attestation.
bin/fm-backlog-transition-lib.sh runs under the curated PATH the spawn and
teardown lifecycle scripts pin, so the staged file is named by parameter
expansion, and a record path with no directory component resolves to the
working directory instead of composing a path from itself.
@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no concrete blocking or non-blocking defects identified in the changed behavior.

The new metadata writer preserves unrelated fields under the existing lock and atomic publication boundary, while poll authentication continues to bind canonical PR identity to hashed sidecar data despite allowing unrelated metadata lines in any position.

Reviews (1): Last reviewed commit: "no-mistakes(document): document shared t..." | Re-trigger Greptile

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