tests/claim-next-task-test.sh: the deadline-derived cap check is a 1-in-8 wall-clock flake #166

Closed
opened 2026-09-22 20:02:28 +00:00 by ben · 4 comments
Owner

Symptom

tests/claim-next-task-test.sh fails roughly 1 run in 8, always on the same check:

FAIL: walk cap is deadline-derived (20/5 = 4s), not the old flat 10s

Measured on matou-dev-server-01 (laptop checkout), 8 runs per tree, on
origin/main at dc9b3e0 and on an unrelated branch: 7 pass / 1 fail in
both. It is not caused by any particular change — it is in the assertion.

Cause

The per-call cap is derived from the clock (T-idss#1195b): roughly
(CLAIM_NEXT_DEADLINE - SECONDS) / CLAIM_CANDIDATE_CALLS. The test pins the
exact integer:

CLAIM_NEXT_DEADLINE=20 CLAIM_CANDIDATE_CALLS=5 bash "$script" >/dev/null 2>&1
check "walk cap is deadline-derived (20/5 = 4s), not the old flat 10s" \
  'grep -q -- "--max-time 4 " "$FAKE_DIR/argv.log" || grep -q -- "--max-time 4$" "$FAKE_DIR/argv.log"'

20/5 = 4 holds only while SECONDS is still 0 when the derivation runs. On a
loaded host the script crosses a second boundary first, derives (20-1)/5 = 3,
and the exact-match check fails — on a value that is more conservative, i.e.
the safety property the test exists to protect is satisfied either way.

Suggested fix

Assert the property, not the literal: the cap must be >= CLAIM_CALL_FLOOR, and
cap * CLAIM_CANDIDATE_CALLS must be <= CLAIM_NEXT_DEADLINE. The check
directly below it (worst-case candidate (calls x cap) fits inside the deadline)
already has that shape and does not flake. Keeping a "not the old flat 10s"
assertion is still worth it — cap < 10 covers the regression the literal was
guarding against.

Why it matters

A 1-in-8 flake in the factory's own suite trains everyone to re-run rather than
read a red, and tests/*.sh is what CI loops.

out_of_scope

The derivation itself (it is correct); every other case in the file.

## Symptom `tests/claim-next-task-test.sh` fails roughly 1 run in 8, always on the same check: ``` FAIL: walk cap is deadline-derived (20/5 = 4s), not the old flat 10s ``` Measured on `matou-dev-server-01` (laptop checkout), 8 runs per tree, on `origin/main` at `dc9b3e0` **and** on an unrelated branch: 7 pass / 1 fail in both. It is not caused by any particular change — it is in the assertion. ## Cause The per-call cap is derived from the clock (`T-idss#1195b`): roughly `(CLAIM_NEXT_DEADLINE - SECONDS) / CLAIM_CANDIDATE_CALLS`. The test pins the exact integer: ```bash CLAIM_NEXT_DEADLINE=20 CLAIM_CANDIDATE_CALLS=5 bash "$script" >/dev/null 2>&1 check "walk cap is deadline-derived (20/5 = 4s), not the old flat 10s" \ 'grep -q -- "--max-time 4 " "$FAKE_DIR/argv.log" || grep -q -- "--max-time 4$" "$FAKE_DIR/argv.log"' ``` `20/5 = 4` holds only while `SECONDS` is still `0` when the derivation runs. On a loaded host the script crosses a second boundary first, derives `(20-1)/5 = 3`, and the exact-match check fails — on a value that is *more* conservative, i.e. the safety property the test exists to protect is satisfied either way. ## Suggested fix Assert the property, not the literal: the cap must be `>= CLAIM_CALL_FLOOR`, and `cap * CLAIM_CANDIDATE_CALLS` must be `<= CLAIM_NEXT_DEADLINE`. The check directly below it (`worst-case candidate (calls x cap) fits inside the deadline`) already has that shape and does not flake. Keeping a "not the old flat 10s" assertion is still worth it — `cap < 10` covers the regression the literal was guarding against. ## Why it matters A 1-in-8 flake in the factory's own suite trains everyone to re-run rather than read a red, and `tests/*.sh` is what CI loops. ## out_of_scope The derivation itself (it is correct); every other case in the file.

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: bug + ready-for-agent. The reporter's diagnosis holds up against the code path, and the fix is a test-only assertion change — revertible by a later commit, provable by an existing drive (the repaired check must stop flaking while still catching the old flat-cap regression), and nowhere near the one-way-door list (no creds, no security posture, no trust accept, no data loss, no spend). So it is a two-way door I can land straight to ready-for-agent.

Verification. Confirmed both the flake and its cause:

  • The per-call cap in the claim walk is derived from the clock — remaining = CLAIM_NEXT_DEADLINE - SECONDS, cap = remaining / CLAIM_CANDIDATE_CALLS. With SECONDS=0 this yields 20/5 = 4; once the run crosses a one-second boundary under load it derives 19/5 = 3 — more conservative, so the safety property still holds, but the literal --max-time 4 exact-match check fails.
  • Reproduced directly: 16 back-to-back runs of tests/claim-next-task-test.sh produced 6 failures, every one on exactly FAIL: walk cap is deadline-derived (20/5 = 4s), not the old flat 10s and no other check. (This host is loaded enough to fail well above the reporter's 1-in-8; that only sharpens the point.)

Agent Brief

Category: bug
Summary: The "deadline-derived cap" check in the claim-next-task suite pins the literal --max-time 4, which flakes whenever the wall clock crosses a second boundary before the cap is derived. Assert the safety property instead of the exact integer.

Current behavior:
One check in the claim-next-task test suite asserts the derived per-call cap is exactly --max-time 4 for CLAIM_NEXT_DEADLINE=20 CLAIM_CANDIDATE_CALLS=5. Because the derivation subtracts elapsed SECONDS from the deadline, a loaded host that has ticked past one second derives cap 3 (from 19/5) and the exact-match check reds — on a value that is strictly more conservative than the one it demands. Result: a ~1-in-8 (worse under load) flake on green code.

Desired behavior:
The check asserts the invariant the derivation exists to protect, not a clock-dependent literal, so it is green for any admissible cap:

  • the derived cap is at least the call floor (cap >= CLAIM_CALL_FLOOR), and
  • a full candidate's worth of calls fits the deadline (cap * CLAIM_CANDIDATE_CALLS <= CLAIM_NEXT_DEADLINE), and
  • the regression guard the literal used to provide is preserved: the cap is below the old flat value (cap < 10), so a reintroduced flat-10s cap still reds the suite.

The derived cap is read off the real argv the script emitted (the same argv.log the current check greps), not from a re-derivation in the test.

Key interfaces:

  • tests/claim-next-task-test.sh, the T-idss#1195b block — the check labelled "walk cap is deadline-derived (20/5 = 4s), not the old flat 10s". The sibling check immediately below it ("worst-case candidate (calls x cap) fits inside the deadline") already reads the cap off argv.log via sed/sort -n and does not flake — reuse that extraction shape.
  • claim-next-task.sh derivation (remaining = CLAIM_NEXT_DEADLINE - SECONDS, cap = remaining / CLAIM_CANDIDATE_CALLS, floored at CLAIM_CALL_FLOOR) — the code under test. Do not change it; the derivation is correct.

Acceptance criteria:

  • The repaired check passes for both cap == 4 (SECONDS=0) and cap == 3 (SECONDS crossed one boundary) — i.e. it no longer depends on which second the derivation runs in.
  • The check still reds if the cap regresses to a flat >= 10s value.
  • tests/claim-next-task-test.sh passes across many consecutive runs (e.g. 20+) with no flake on this check.
  • No change to claim-next-task.sh behavior; the offline test discipline holds (shimmed curl/claude, no network/docker).

Out of scope:

  • The derivation itself in claim-next-task.sh — it is correct and must not change.
  • Every other check in the file; only the one flaky assertion is in play.
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** `bug` + `ready-for-agent`. The reporter's diagnosis holds up against the code path, and the fix is a test-only assertion change — revertible by a later commit, provable by an existing drive (the repaired check must stop flaking while still catching the old flat-cap regression), and nowhere near the one-way-door list (no creds, no security posture, no trust accept, no data loss, no spend). So it is a two-way door I can land straight to `ready-for-agent`. **Verification.** Confirmed both the flake and its cause: - The per-call cap in the claim walk is derived from the clock — `remaining = CLAIM_NEXT_DEADLINE - SECONDS`, `cap = remaining / CLAIM_CANDIDATE_CALLS`. With `SECONDS=0` this yields `20/5 = 4`; once the run crosses a one-second boundary under load it derives `19/5 = 3` — *more* conservative, so the safety property still holds, but the literal `--max-time 4` exact-match check fails. - Reproduced directly: 16 back-to-back runs of `tests/claim-next-task-test.sh` produced 6 failures, every one on exactly `FAIL: walk cap is deadline-derived (20/5 = 4s), not the old flat 10s` and no other check. (This host is loaded enough to fail well above the reporter's 1-in-8; that only sharpens the point.) --- ## Agent Brief **Category:** bug **Summary:** The "deadline-derived cap" check in the claim-next-task suite pins the literal `--max-time 4`, which flakes whenever the wall clock crosses a second boundary before the cap is derived. Assert the safety property instead of the exact integer. **Current behavior:** One check in the claim-next-task test suite asserts the derived per-call cap is exactly `--max-time 4` for `CLAIM_NEXT_DEADLINE=20 CLAIM_CANDIDATE_CALLS=5`. Because the derivation subtracts elapsed `SECONDS` from the deadline, a loaded host that has ticked past one second derives cap `3` (from `19/5`) and the exact-match check reds — on a value that is strictly *more* conservative than the one it demands. Result: a ~1-in-8 (worse under load) flake on green code. **Desired behavior:** The check asserts the invariant the derivation exists to protect, not a clock-dependent literal, so it is green for any admissible cap: - the derived cap is at least the call floor (`cap >= CLAIM_CALL_FLOOR`), and - a full candidate's worth of calls fits the deadline (`cap * CLAIM_CANDIDATE_CALLS <= CLAIM_NEXT_DEADLINE`), and - the regression guard the literal used to provide is preserved: the cap is below the old flat value (`cap < 10`), so a reintroduced flat-10s cap still reds the suite. The derived cap is read off the real argv the script emitted (the same `argv.log` the current check greps), not from a re-derivation in the test. **Key interfaces:** - `tests/claim-next-task-test.sh`, the T-idss#1195b block — the check labelled "walk cap is deadline-derived (20/5 = 4s), not the old flat 10s". The sibling check immediately below it ("worst-case candidate (calls x cap) fits inside the deadline") already reads the cap off `argv.log` via `sed`/`sort -n` and does not flake — reuse that extraction shape. - `claim-next-task.sh` derivation (`remaining = CLAIM_NEXT_DEADLINE - SECONDS`, `cap = remaining / CLAIM_CANDIDATE_CALLS`, floored at `CLAIM_CALL_FLOOR`) — the code under test. Do not change it; the derivation is correct. **Acceptance criteria:** - [ ] The repaired check passes for both `cap == 4` (SECONDS=0) and `cap == 3` (SECONDS crossed one boundary) — i.e. it no longer depends on which second the derivation runs in. - [ ] The check still reds if the cap regresses to a flat `>= 10s` value. - [ ] `tests/claim-next-task-test.sh` passes across many consecutive runs (e.g. 20+) with no flake on this check. - [ ] No change to `claim-next-task.sh` behavior; the offline test discipline holds (shimmed curl/claude, no network/docker). **Out of scope:** - The derivation itself in `claim-next-task.sh` — it is correct and must not change. - Every other check in the file; only the one flaky assertion is in play.

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

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

close-report for #166 — status success

⛔ close-report gates REFUSED this close — the following claims did not verify:

  • commit da4dd50775 is not reachable from origin/main (not landed)
  • changed_files: 'tests/claim-next-task-test.sh' is not in the diff of the claimed commits
envelope
{
  "issue": 166,
  "status": "success",
  "commits": [
    "da4dd5077593951d27897f3503b1a50cdd23ad7c"
  ],
  "changed_files": [
    "tests/claim-next-task-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/claim-next-task-test.sh (x25)",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do bash $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Repaired check passes for both cap==4 (SECONDS=0) and cap==3 (boundary crossed)": "The check now asserts cap>=2 && cap*5<=20 && cap<10, read off argv.log's smallest --max-time; both 3 and 4 satisfy it (verified with the invariant across cap 2/3/4).",
    "Check still reds if the cap regresses to a flat >= 10s value": "cap<10 clause reds at 10; also cap*5<=20 reds any cap>=5 that would overrun the deadline (verified: cap=9,10 RED).",
    "claim-next-task-test.sh passes across many consecutive runs (20+) with no flake on this check": "25 back-to-back runs: 0 flakes on 'walk cap'; pass=44 fail=0.",
    "No change to claim-next-task.sh; offline test discipline holds": "Only tests/claim-next-task-test.sh changed; suite runs with shimmed curl/claude, no network/docker."
  },
  "summary": "Replaced the flaky literal --max-time 4 assertion in the claim-walk cap check with the deadline-derived invariant, ending a ~1-in-8 wall-clock flake.",
  "blockers": []
}
**close-report** for #166 — status `success` :no_entry: **close-report gates REFUSED this close** — the following claims did not verify: - commit da4dd5077593951d27897f3503b1a50cdd23ad7c is not reachable from origin/main (not landed) - changed_files: 'tests/claim-next-task-test.sh' is not in the diff of the claimed commits <details><summary>envelope</summary> ```json { "issue": 166, "status": "success", "commits": [ "da4dd5077593951d27897f3503b1a50cdd23ad7c" ], "changed_files": [ "tests/claim-next-task-test.sh" ], "tests": [ { "command": "bash tests/claim-next-task-test.sh (x25)", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do bash $t; done", "exit_code": 0 } ], "criteria": { "Repaired check passes for both cap==4 (SECONDS=0) and cap==3 (boundary crossed)": "The check now asserts cap>=2 && cap*5<=20 && cap<10, read off argv.log's smallest --max-time; both 3 and 4 satisfy it (verified with the invariant across cap 2/3/4).", "Check still reds if the cap regresses to a flat >= 10s value": "cap<10 clause reds at 10; also cap*5<=20 reds any cap>=5 that would overrun the deadline (verified: cap=9,10 RED).", "claim-next-task-test.sh passes across many consecutive runs (20+) with no flake on this check": "25 back-to-back runs: 0 flakes on 'walk cap'; pass=44 fail=0.", "No change to claim-next-task.sh; offline test discipline holds": "Only tests/claim-next-task-test.sh changed; suite runs with shimmed curl/claude, no network/docker." }, "summary": "Replaced the flaky literal --max-time 4 assertion in the claim-walk cap check with the deadline-derived invariant, ending a ~1-in-8 wall-clock flake.", "blockers": [] } ``` </details>

close-report for #166 — status success

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

envelope
{
  "issue": 166,
  "status": "success",
  "commits": [
    "da4dd5077593951d27897f3503b1a50cdd23ad7c"
  ],
  "changed_files": [
    "tests/claim-next-task-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/claim-next-task-test.sh (x25)",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do bash $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Repaired check passes for both cap==4 (SECONDS=0) and cap==3 (boundary crossed)": "The check now asserts cap>=2 && cap*5<=20 && cap<10, read off argv.log's smallest --max-time; both 3 and 4 satisfy it (verified with the invariant across cap 2/3/4).",
    "Check still reds if the cap regresses to a flat >= 10s value": "cap<10 clause reds at 10; also cap*5<=20 reds any cap>=5 that would overrun the deadline (verified: cap=9,10 RED).",
    "claim-next-task-test.sh passes across many consecutive runs (20+) with no flake on this check": "25 back-to-back runs: 0 flakes on 'walk cap'; pass=44 fail=0.",
    "No change to claim-next-task.sh; offline test discipline holds": "Only tests/claim-next-task-test.sh changed; suite runs with shimmed curl/claude, no network/docker."
  },
  "summary": "Replaced the flaky literal --max-time 4 assertion in the claim-walk cap check with the deadline-derived invariant, ending a ~1-in-8 wall-clock flake.",
  "blockers": []
}
**close-report** for #166 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 166, "status": "success", "commits": [ "da4dd5077593951d27897f3503b1a50cdd23ad7c" ], "changed_files": [ "tests/claim-next-task-test.sh" ], "tests": [ { "command": "bash tests/claim-next-task-test.sh (x25)", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do bash $t; done", "exit_code": 0 } ], "criteria": { "Repaired check passes for both cap==4 (SECONDS=0) and cap==3 (boundary crossed)": "The check now asserts cap>=2 && cap*5<=20 && cap<10, read off argv.log's smallest --max-time; both 3 and 4 satisfy it (verified with the invariant across cap 2/3/4).", "Check still reds if the cap regresses to a flat >= 10s value": "cap<10 clause reds at 10; also cap*5<=20 reds any cap>=5 that would overrun the deadline (verified: cap=9,10 RED).", "claim-next-task-test.sh passes across many consecutive runs (20+) with no flake on this check": "25 back-to-back runs: 0 flakes on 'walk cap'; pass=44 fail=0.", "No change to claim-next-task.sh; offline test discipline holds": "Only tests/claim-next-task-test.sh changed; suite runs with shimmed curl/claude, no network/docker." }, "summary": "Replaced the flaky literal --max-time 4 assertion in the claim-walk cap check with the deadline-derived invariant, ending a ~1-in-8 wall-clock flake.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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#166
No description provided.