run-triage.sh reds after a fully successful triage: sort/comm collation mismatch at the human-gate diff (and the verdict blames the claude stage) #104

Closed
opened 2026-08-26 22:51:21 +00:00 by matou-build-agent · 2 comments

Filed by the healer from triage run 2642 (signature c69d2f7ae0d8, evidence /tmp/matou-heal-Matou-dev-factory.hjjt3l).

Symptom

Every triage run in this repo that actually reaches the claude call exits 1 — after the /triage skill has completely succeeded. Run 2642 triaged #101/#102/#103 correctly (labels applied, #103 closed, preflight-triage.sh returned []), then reddened the workflow and woke the healer. Triage runs 2634/2636 were green only because they took the nothing to triage early exit.

Root cause — comm vs sort collation (run-triage.sh:241)

new="$(comm -13 <(printf '%s\n' "$before") <(printf '%s\n' "$after"))"

human_gated() ends in sort -u (run-triage.sh:155), which sorts under the runner's LANG=en_US.UTF-8 collation — that ignores the TAB in "<num>\t<label>", so 62\tneeds-design sorts before 6\tneeds-design. GNU comm checks order by bytes (\t 0x09 < 2), disagrees, prints comm: input is not in sorted order and exits 1. Under set -euo pipefail that reds the run.

Reproduced on the runner host with the run's real data:

$ printf '%s\n' "$before" > f1; printf '%s\n' "$after" > f2   # both straight from sort -u
$ comm -13 f1 f2; echo "exit=$?"
comm: file 1 is not in sorted order
comm: file 2 is not in sorted order
comm: input is not in sorted order
exit=1

Note the check is lazy: identical files never trip it, so it only fires once before and after differ — i.e. exactly when triage did work.

Fix: force byte collation on both sides — LC_ALL=C sort -u in human_gated, and/or comm --nocheck-order. Any consumer whose gated set contains a number that is a byte-prefix of another (6 / 62 here) hits this, so it is not dev-factory-specific.

Second defect — the verdict stage goes stale after the claude call

verdict_stage "triage skill (claude -p /triage)" is set at run-triage.sh:163 and never re-set. Everything after the claude call (human_gated, the digest loop, notify-mattermost.sh, the still recount) therefore fails under the claude stage, and verdict_write greps its error lines out of the claude log — whose triage prose matched the regex on the word cannot:

Verified: heal.sh opens its lock on a fixed /tmp/matou-healer-<repo-tag>.lock ... so heal-test.sh cannot pin it and concurrent suite runs collide.

That is what the healer keyed signature c69d2f7ae0d8 on: a triage ruling about #102, presented as a triage fault. This is #235's exact hazard one stage later. Ground truth was only recoverable from swarm.db, which recorded verdict='triaged' with exit_code=1 — proving the claude call returned clean (triage_verdict="triaged" is set only after the loop breaks) and the fault is downstream. verdict_stage calls belong on each post-claude stage (human_gated (after), human-gate digest + notify, recount untriaged), each with its own errlog or verdict_error.

Third defect — human_gated silently matches every open issue

human_gated queries labels=ready-for-human and labels=needs-design. needs-design does not exist in this repo (GET /labels lists the 16 core labels from onboarding/labels.json; it is not among them). Forgejo does not 404 an unknown label filter — it returns all open issues:

$ .../issues?state=open&type=issues&labels=needs-design
[{102,[bug,ready-for-agent]},{101,[bug,ready-for-agent]},{62,...},{17,[deferred,enhancement]},{6,...}]

So before/after list every open issue as needs-design-gated. Today that is masked (after ⊆ before, new empty), but any issue opened during a triage run posts a false "👋 Triage needs you ... → needs-design" digest to Mattermost. It is also what put 6 and 62 in the same list and made the collation bug bite. Either mint needs-design or drop it from the loop — and validate the label exists rather than trusting the filter.

Acceptance criteria

  • A triage run that triages issues and changes the human-gated set exits 0.
  • human_gated's output and comm agree on collation, pinned by a test with a 6/62-shaped set under a non-C locale.
  • A post-claude failure produces a verdict naming that stage, not triage skill (claude -p /triage), and does not quote the claude log.
  • human_gated only reports issues that genuinely carry a gate label.
  • tests/run-triage-test.sh covers all three.

Blast radius

run-triage.sh is factory source; root and .sandcastle/run-triage.sh are currently byte-identical, so a root fix does not reach the running copy until a human re-vendors (bash onboarding/onboard.sh vendor .sandcastle <sha>, GOTCHAS 4). Until then every triage run here that finds untriaged work reds and burns a healer investigation.

Filed by the healer from triage run [2642](https://git.matou.nz/Matou/dev-factory/actions/runs/2642) (signature `c69d2f7ae0d8`, evidence `/tmp/matou-heal-Matou-dev-factory.hjjt3l`). ## Symptom Every triage run in this repo that **actually reaches the claude call** exits 1 — *after* the /triage skill has completely succeeded. Run 2642 triaged #101/#102/#103 correctly (labels applied, #103 closed, `preflight-triage.sh` returned `[]`), then reddened the workflow and woke the healer. Triage runs 2634/2636 were green only because they took the `nothing to triage` early exit. ## Root cause — `comm` vs `sort` collation (`run-triage.sh:241`) ```sh new="$(comm -13 <(printf '%s\n' "$before") <(printf '%s\n' "$after"))" ``` `human_gated()` ends in `sort -u` (`run-triage.sh:155`), which sorts under the runner's `LANG=en_US.UTF-8` collation — that ignores the TAB in `"<num>\t<label>"`, so `62\tneeds-design` sorts *before* `6\tneeds-design`. GNU `comm` checks order by **bytes** (`\t` 0x09 < `2`), disagrees, prints `comm: input is not in sorted order` and **exits 1**. Under `set -euo pipefail` that reds the run. Reproduced on the runner host with the run's real data: ``` $ printf '%s\n' "$before" > f1; printf '%s\n' "$after" > f2 # both straight from sort -u $ comm -13 f1 f2; echo "exit=$?" comm: file 1 is not in sorted order comm: file 2 is not in sorted order comm: input is not in sorted order exit=1 ``` Note the check is lazy: identical files never trip it, so it only fires once `before` and `after` differ — i.e. exactly when triage did work. **Fix:** force byte collation on both sides — `LC_ALL=C sort -u` in `human_gated`, and/or `comm --nocheck-order`. Any consumer whose gated set contains a number that is a byte-prefix of another (6 / 62 here) hits this, so it is not dev-factory-specific. ## Second defect — the verdict stage goes stale after the claude call `verdict_stage "triage skill (claude -p /triage)"` is set at `run-triage.sh:163` and **never re-set**. Everything after the claude call (`human_gated`, the digest loop, `notify-mattermost.sh`, the `still` recount) therefore fails *under the claude stage*, and `verdict_write` greps its error lines out of the **claude log** — whose triage prose matched the regex on the word `cannot`: > `Verified: heal.sh opens its lock on a fixed /tmp/matou-healer-<repo-tag>.lock ... so heal-test.sh cannot pin it and concurrent suite runs collide.` That is what the healer keyed signature `c69d2f7ae0d8` on: a triage *ruling about #102*, presented as a triage *fault*. This is #235's exact hazard one stage later. Ground truth was only recoverable from `swarm.db`, which recorded `verdict='triaged'` **with** `exit_code=1` — proving the claude call returned clean (`triage_verdict="triaged"` is set only after the loop breaks) and the fault is downstream. `verdict_stage` calls belong on each post-claude stage (`human_gated (after)`, `human-gate digest + notify`, `recount untriaged`), each with its own errlog or `verdict_error`. ## Third defect — `human_gated` silently matches every open issue `human_gated` queries `labels=ready-for-human` and `labels=needs-design`. **`needs-design` does not exist in this repo** (`GET /labels` lists the 16 core labels from `onboarding/labels.json`; it is not among them). Forgejo does not 404 an unknown label filter — it returns **all** open issues: ``` $ .../issues?state=open&type=issues&labels=needs-design [{102,[bug,ready-for-agent]},{101,[bug,ready-for-agent]},{62,...},{17,[deferred,enhancement]},{6,...}] ``` So `before`/`after` list every open issue as `needs-design`-gated. Today that is masked (`after ⊆ before`, `new` empty), but any issue opened *during* a triage run posts a false ":wave: Triage needs you ... → `needs-design`" digest to Mattermost. It is also what put 6 **and** 62 in the same list and made the collation bug bite. Either mint `needs-design` or drop it from the loop — and validate the label exists rather than trusting the filter. ## Acceptance criteria - A triage run that triages issues and changes the human-gated set exits 0. - `human_gated`'s output and `comm` agree on collation, pinned by a test with a `6`/`62`-shaped set under a non-C locale. - A post-claude failure produces a verdict naming *that* stage, not `triage skill (claude -p /triage)`, and does not quote the claude log. - `human_gated` only reports issues that genuinely carry a gate label. - `tests/run-triage-test.sh` covers all three. ## Blast radius `run-triage.sh` is factory source; root and `.sandcastle/run-triage.sh` are currently byte-identical, so **a root fix does not reach the running copy until a human re-vendors** (`bash onboarding/onboard.sh vendor .sandcastle <sha>`, GOTCHAS 4). Until then every triage run here that finds untriaged work reds and burns a healer investigation.
Author
Member

swarm-claim host=elitebook-distributed-server-03 run=2646
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=2646 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #104 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 104,
  "status": "success",
  "commits": [
    "fa51992"
  ],
  "changed_files": [
    "run-triage.sh",
    "tests/run-triage-test.sh",
    "docs/GOTCHAS.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/run-triage-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A triage run that triages issues and changes the human-gated set exits 0": "run-triage.sh human_gated() now ends in `LC_ALL=C sort -u` so the byte-order comm agrees; test scenario 104a drives a {6,62}->{6,63} gated-set change under a non-C locale (emulating sort shim) and asserts exit 0 with no verdict",
    "human_gated's output and comm agree on collation, pinned by a test with a 6/62-shaped set under a non-C locale": "104a pins it: without LC_ALL=C the run reds with `comm: input is not in sorted order` (verified by reverting the fix); with it, exit 0",
    "A post-claude failure produces a verdict naming that stage, not the claude skill stage, and does not quote the claude log": "verdict_stage is re-set on each post-claude stage (human_gated after, human-gate digest + notify, recount untriaged) with no errlog; test 104c forces a recount failure and asserts stage=recount untriaged, not stage=triage skill, and that the claude prose is absent from the verdict",
    "human_gated only reports issues that genuinely carry a gate label": "human_gated now fetches GET /labels and skips any gate label absent from the repo's real label set; test 104b proves needs-design (unminted here) is never queried and posts no false digest",
    "tests/run-triage-test.sh covers all three": "104a (collation), 104b (phantom label), 104c (stale post-claude stage) added; full offline suite green"
  },
  "summary": "run-triage.sh no longer reds after a successful /triage: LC_ALL=C sort fixes the sort/comm collation, per-stage verdicts stop blaming the claude call, and a GET /labels check stops the phantom needs-design gate.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #104 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 104, "status": "success", "commits": [ "fa51992" ], "changed_files": [ "run-triage.sh", "tests/run-triage-test.sh", "docs/GOTCHAS.md", "STATUS.md" ], "tests": [ { "command": "bash tests/run-triage-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done", "exit_code": 0 } ], "criteria": { "A triage run that triages issues and changes the human-gated set exits 0": "run-triage.sh human_gated() now ends in `LC_ALL=C sort -u` so the byte-order comm agrees; test scenario 104a drives a {6,62}->{6,63} gated-set change under a non-C locale (emulating sort shim) and asserts exit 0 with no verdict", "human_gated's output and comm agree on collation, pinned by a test with a 6/62-shaped set under a non-C locale": "104a pins it: without LC_ALL=C the run reds with `comm: input is not in sorted order` (verified by reverting the fix); with it, exit 0", "A post-claude failure produces a verdict naming that stage, not the claude skill stage, and does not quote the claude log": "verdict_stage is re-set on each post-claude stage (human_gated after, human-gate digest + notify, recount untriaged) with no errlog; test 104c forces a recount failure and asserts stage=recount untriaged, not stage=triage skill, and that the claude prose is absent from the verdict", "human_gated only reports issues that genuinely carry a gate label": "human_gated now fetches GET /labels and skips any gate label absent from the repo's real label set; test 104b proves needs-design (unminted here) is never queried and posts no false digest", "tests/run-triage-test.sh covers all three": "104a (collation), 104b (phantom label), 104c (stale post-claude stage) added; full offline suite green" }, "summary": "run-triage.sh no longer reds after a successful /triage: LC_ALL=C sort fixes the sort/comm collation, per-stage verdicts stop blaming the claude call, and a GET /labels check stops the phantom needs-design gate.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#104
No description provided.