close-report gate compares against the stale pre-push head in push mode — a landed commit is refused as "not landed" #244

Closed
opened 2026-10-16 15:57:42 +00:00 by ben · 5 comments
Owner

Filed from the #237 stall (Ben's Claude Code session, 2026-10-16).

Symptom

The #237 worker pushed 53793ce to main (push mode; git push reported b3fcc11..53793ce HEAD -> main, and git ls-remote origin refs/heads/main returned 53793ce). Every subsequent close-report.sh run (four envelopes on #237, 17:25Z to 17:32Z on 2026-10-15) refused with:

commit 53793cef… is not reachable from b3fcc11f… (not landed)

b3fcc11 is the origin/main the run started from. gate_head="${CR_MAIN_HEAD:-origin/main}" (close-report.sh:73) resolved to the startup value, not the live remote head, so a descendant of the start head can never pass gate 1. The worker reported that exporting CR_MAIN_HEAD=origin/main did not change the result, and that running cr_violations <envelope> <root> origin/main against a freshly fetched origin/main passed with zero violations. It escalated to agent-blocked; #238/#239/#241 sat blocked for 22 hours until #237 was closed by hand.

Likely cause

The origin/main ref the gate reads is not refreshed after the worker's push: either the gate runs in a checkout (or worktree) whose remote-tracking ref was never fetched after the push, or the landing head is pinned at startup and injected. Either way gate 1 needs git fetch origin main (or git ls-remote) immediately before the reachability check, in the same checkout it evaluates.

Acceptance

  • close-report.sh fetches the live remote head before gate 1 in push mode, and the refusal message names the head it compared against and when it was fetched.
  • tests/close-report-test.sh (or the closest existing suite) gains a scenario: start head H0, worker pushes H1 descending from H0, gate passes without any manual CR_MAIN_HEAD.
  • Consider: a landing reconcile sweep that closes a ready-for-agent/agent-blocked ticket whose claimed commits are already on main (the worker's own suggestion on #237).

#197 / #206 (gate tightening landed 2026-10-15, likely the regression window), #193 (host-lands design will move this check host-side).

_Filed from the #237 stall (Ben's Claude Code session, 2026-10-16)._ ## Symptom The #237 worker pushed `53793ce` to `main` (push mode; `git push` reported `b3fcc11..53793ce HEAD -> main`, and `git ls-remote origin refs/heads/main` returned `53793ce`). Every subsequent `close-report.sh` run (four envelopes on #237, 17:25Z to 17:32Z on 2026-10-15) refused with: ``` commit 53793cef… is not reachable from b3fcc11f… (not landed) ``` `b3fcc11` is the `origin/main` the run started from. `gate_head="${CR_MAIN_HEAD:-origin/main}"` (`close-report.sh:73`) resolved to the startup value, not the live remote head, so a descendant of the start head can never pass gate 1. The worker reported that exporting `CR_MAIN_HEAD=origin/main` did not change the result, and that running `cr_violations <envelope> <root> origin/main` against a freshly fetched `origin/main` passed with zero violations. It escalated to `agent-blocked`; #238/#239/#241 sat blocked for 22 hours until #237 was closed by hand. ## Likely cause The `origin/main` ref the gate reads is not refreshed after the worker's push: either the gate runs in a checkout (or worktree) whose remote-tracking ref was never fetched after the push, or the landing head is pinned at startup and injected. Either way gate 1 needs `git fetch origin main` (or `git ls-remote`) immediately before the reachability check, in the same checkout it evaluates. ## Acceptance - `close-report.sh` fetches the live remote head before gate 1 in push mode, and the refusal message names the head it compared against **and** when it was fetched. - `tests/close-report-test.sh` (or the closest existing suite) gains a scenario: start head H0, worker pushes H1 descending from H0, gate passes without any manual `CR_MAIN_HEAD`. - Consider: a landing reconcile sweep that closes a `ready-for-agent`/`agent-blocked` ticket whose claimed commits are already on `main` (the worker's own suggestion on #237). ## Related #197 / #206 (gate tightening landed 2026-10-15, likely the regression window), #193 (host-lands design will move this check host-side).

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: ready-for-agent. This is a two-way door: the fix is a localised change to one harness lib plus a test, revertible by a later commit, and provable by the new test scenario the acceptance already specifies (start head H0, worker pushes H1 descending from H0, gate passes with no manual CR_MAIN_HEAD). It is not on the one-way-door list — no credentials, no security-posture change, no data destruction, no spend.

Verification (confirmed against the code): in push mode close-report.sh resolves the gate head to ${CR_MAIN_HEAD:-origin/main} and only refetches when HEAD is a sandcastle/worker/* branch. For any other checkout it compares against the checkout's origin/main tracking ref as it stood at run start, with no git fetch origin main beforehand — so a commit pushed to main during the run is a descendant of a head the gate never refreshed, and gate 1 refuses it as "not landed" exactly as the #237 stall showed. The claim holds.


Agent Brief

Category: bug
Summary: In push mode, close-report's gate 1 compares claimed commits against a stale origin/main tracking ref captured at run start; refresh the live remote head before the reachability check.

Current behavior:
When the run lands on main (push mode) and the checkout is not a sandcastle/worker/* branch, gate 1 resolves the landing head to the checkout's origin/main tracking ref without fetching it first. If main advanced during the run (e.g. the worker's own push), that ref is stale: a commit now reachable from the live main is refused as "not reachable … (not landed)". Setting CR_MAIN_HEAD=origin/main does not help, because origin/main itself is the unrefreshed ref. The #237 stall left #238/#239/#241 blocked for ~22h.

Desired behavior:
In push mode, before gate 1 evaluates reachability, close-report refreshes the live remote main head (e.g. git fetch origin main, or resolve via git ls-remote) in the same checkout it evaluates, and gates against that. The refusal message, when it fires, names the head it compared against and when that head was fetched, so a future stall is diagnosable from the message alone. An explicit CR_MAIN_HEAD override still wins (tests rely on pinning it); the refresh applies only when the caller has not pinned it.

Key interfaces:

  • The push-mode branch of the landing-head resolution in close-report — the gate_head assignment path that currently defaults to origin/main. Keep the existing sandcastle/worker/* branch handling; add a live-main refresh for the non-worker-branch push-mode case.
  • The refusal/violation message emitted by gate 1 — extend it to name the compared head and its fetch time.
  • Consider (secondary, see scope): a landing-reconcile step that closes a ready-for-agent/agent-blocked ticket whose claimed commits are already on main — the #237 worker's own suggestion.

Acceptance criteria:

  • In push mode, close-report fetches the live remote main head before gate 1 and gates the reachability check against it.
  • The gate-1 refusal message names the head it compared against and when that head was fetched.
  • An explicit CR_MAIN_HEAD still overrides the refresh (no regression to the test seam).
  • tests/close-report-test.sh gains a scenario: start head H0, worker pushes H1 descending from H0 to main, gate 1 passes with no manual CR_MAIN_HEAD.
  • The offline suite (for t in tests/*.sh onboarding/tests/*.sh; …) is green; the lib change and its test land in the same commit (CLAUDE.md).

Out of scope:

  • The pr-mode landing-head path (open/merged/superseded PR resolution) — unchanged.
  • The #193 host-lands redesign that will eventually move this check host-side — this fix stands until then.
  • The landing-reconcile sweep is a consider, not required; if it grows non-trivial, split it to its own ticket rather than bloating this one.
> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** `ready-for-agent`. This is a two-way door: the fix is a localised change to one harness lib plus a test, revertible by a later commit, and provable by the new test scenario the acceptance already specifies (start head H0, worker pushes H1 descending from H0, gate passes with no manual `CR_MAIN_HEAD`). It is not on the one-way-door list — no credentials, no security-posture change, no data destruction, no spend. **Verification (confirmed against the code):** in push mode `close-report.sh` resolves the gate head to `${CR_MAIN_HEAD:-origin/main}` and only refetches when `HEAD` is a `sandcastle/worker/*` branch. For any other checkout it compares against the checkout's `origin/main` *tracking ref as it stood at run start*, with no `git fetch origin main` beforehand — so a commit pushed to `main` during the run is a descendant of a head the gate never refreshed, and gate 1 refuses it as "not landed" exactly as the #237 stall showed. The claim holds. --- ## Agent Brief **Category:** bug **Summary:** In push mode, close-report's gate 1 compares claimed commits against a stale `origin/main` tracking ref captured at run start; refresh the live remote head before the reachability check. **Current behavior:** When the run lands on `main` (push mode) and the checkout is not a `sandcastle/worker/*` branch, gate 1 resolves the landing head to the checkout's `origin/main` tracking ref without fetching it first. If `main` advanced during the run (e.g. the worker's own push), that ref is stale: a commit now reachable from the live `main` is refused as "not reachable … (not landed)". Setting `CR_MAIN_HEAD=origin/main` does not help, because `origin/main` itself is the unrefreshed ref. The #237 stall left #238/#239/#241 blocked for ~22h. **Desired behavior:** In push mode, before gate 1 evaluates reachability, close-report refreshes the live remote `main` head (e.g. `git fetch origin main`, or resolve via `git ls-remote`) in the same checkout it evaluates, and gates against that. The refusal message, when it fires, names the head it compared against **and** when that head was fetched, so a future stall is diagnosable from the message alone. An explicit `CR_MAIN_HEAD` override still wins (tests rely on pinning it); the refresh applies only when the caller has not pinned it. **Key interfaces:** - The push-mode branch of the landing-head resolution in close-report — the `gate_head` assignment path that currently defaults to `origin/main`. Keep the existing `sandcastle/worker/*` branch handling; add a live-main refresh for the non-worker-branch push-mode case. - The refusal/violation message emitted by gate 1 — extend it to name the compared head and its fetch time. - Consider (secondary, see scope): a landing-reconcile step that closes a `ready-for-agent`/`agent-blocked` ticket whose claimed commits are already on `main` — the #237 worker's own suggestion. **Acceptance criteria:** - [ ] In push mode, close-report fetches the live remote `main` head before gate 1 and gates the reachability check against it. - [ ] The gate-1 refusal message names the head it compared against and when that head was fetched. - [ ] An explicit `CR_MAIN_HEAD` still overrides the refresh (no regression to the test seam). - [ ] `tests/close-report-test.sh` gains a scenario: start head H0, worker pushes H1 descending from H0 to `main`, gate 1 passes with no manual `CR_MAIN_HEAD`. - [ ] The offline suite (`for t in tests/*.sh onboarding/tests/*.sh; …`) is green; the lib change and its test land in the same commit (CLAUDE.md). **Out of scope:** - The pr-mode landing-head path (open/merged/superseded PR resolution) — unchanged. - The #193 host-lands redesign that will eventually move this check host-side — this fix stands until then. - The landing-reconcile sweep is a *consider*, not required; if it grows non-trivial, split it to its own ticket rather than bloating this one.

⏩ independent reviewer for #244 — verdict unauthenticated

review JSON
{
  "verdict": "unauthenticated",
  "findings": []
}
:fast_forward: **independent reviewer** for #244 — verdict `unauthenticated` <details><summary>review JSON</summary> ```json { "verdict": "unauthenticated", "findings": [] } ``` </details>

close-report for #244 — status success

✅ close-report gates passed — every claim verified against the PR head. PR #271 (#271) is open and green; a human merges it and the merge closes this issue via closes #244 (MERGE_AUTHORITY=human).

envelope
{
  "issue": 244,
  "status": "success",
  "commits": [
    "ba80432ad87f53d23e948a04df8318b3dfc77a12"
  ],
  "changed_files": [
    "STATUS.md",
    "close-report-lib.sh",
    "close-report.sh",
    "docs/GOTCHAS.md",
    "docs/gotchas/75-push-mode-close-report-gates-against-a-stale-origin-main.md",
    "docs/journal/2026-10-16-244.md",
    "tests/close-report-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/close-report-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/close-report-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Push mode fetches the live remote main head before gate 1 and gates against it": "close-report.sh non-worker-branch push-mode case runs `git fetch --quiet origin main` and sets gate_head to the FETCH_HEAD sha (commit ba80432)",
    "The gate-1 refusal message names the head compared against and when it was fetched": "close-report-lib.sh appends CR_HEAD_FETCHED_AT to the 'not reachable from $head (not landed)' message; proven by ST-2 grep for 'fetched at' and 'not reachable from <h1>'",
    "An explicit CR_MAIN_HEAD still overrides the refresh": "the fetch path is guarded by `[ -z \"${CR_MAIN_HEAD:-}\" ]`; existing T1-T6 (CR_MAIN_HEAD=main) and WB tests still pass",
    "tests/close-report-test.sh gains the H0->H1-during-run scenario passing with no manual CR_MAIN_HEAD": "ST-1 in tests/close-report-test.sh (verified it reds without the fetch)",
    "The offline suite is green; lib change + test in the same commit": "only pre-existing unrelated tests/rehearsal-heal-lib-test.sh reds (fails on clean tree, #231/#223 Factory-Account trailer); all touched suites green; all in commit ba80432"
  },
  "summary": "Push-mode close-report now refetches the live main head before gate 1 so a commit that landed during the run is no longer refused as not landed, and the refusal names the head + fetch time.",
  "blockers": []
}
**close-report** for #244 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against the PR head. PR #271 (https://git.matou.nz/Matou/dev-factory/pulls/271) is open and green; a human merges it and the merge closes this issue via `closes #244` (MERGE_AUTHORITY=human). <details><summary>envelope</summary> ```json { "issue": 244, "status": "success", "commits": [ "ba80432ad87f53d23e948a04df8318b3dfc77a12" ], "changed_files": [ "STATUS.md", "close-report-lib.sh", "close-report.sh", "docs/GOTCHAS.md", "docs/gotchas/75-push-mode-close-report-gates-against-a-stale-origin-main.md", "docs/journal/2026-10-16-244.md", "tests/close-report-test.sh" ], "tests": [ { "command": "bash tests/close-report-test.sh", "exit_code": 0 }, { "command": "bash tests/close-report-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 } ], "criteria": { "Push mode fetches the live remote main head before gate 1 and gates against it": "close-report.sh non-worker-branch push-mode case runs `git fetch --quiet origin main` and sets gate_head to the FETCH_HEAD sha (commit ba80432)", "The gate-1 refusal message names the head compared against and when it was fetched": "close-report-lib.sh appends CR_HEAD_FETCHED_AT to the 'not reachable from $head (not landed)' message; proven by ST-2 grep for 'fetched at' and 'not reachable from <h1>'", "An explicit CR_MAIN_HEAD still overrides the refresh": "the fetch path is guarded by `[ -z \"${CR_MAIN_HEAD:-}\" ]`; existing T1-T6 (CR_MAIN_HEAD=main) and WB tests still pass", "tests/close-report-test.sh gains the H0->H1-during-run scenario passing with no manual CR_MAIN_HEAD": "ST-1 in tests/close-report-test.sh (verified it reds without the fetch)", "The offline suite is green; lib change + test in the same commit": "only pre-existing unrelated tests/rehearsal-heal-lib-test.sh reds (fails on clean tree, #231/#223 Factory-Account trailer); all touched suites green; all in commit ba80432" }, "summary": "Push-mode close-report now refetches the live main head before gate 1 so a commit that landed during the run is no longer refused as not landed, and the refusal names the head + fetch time.", "blockers": [] } ``` </details>

Blocked — agent-blocked (broken environment: git worktree corruption)

What blocks it: mid-run, this sandbox's git worktree was corrupted by a shared-admin-dir wipe (the hazard CLAUDE.md rule 8 warns about). Concretely:

  • /home/agent/workspace/.git (the worktree pointer file) vanished and every tracked file was removed from the working tree — only directories survive.
  • The backing repo is intact at …/dev-factory/.git, but its .git/worktrees/ admin directory is entirely gone — no admin entry for any worktree remains, so my worktree sandcastle-worker-20261017-050614-fc0976 lost its backing. This is the classic "a parallel worker mutated the shared .git/worktrees/ admin dir and corrupted a sibling worktree" failure.

Per rule 8 this is a harness bug and must not be repaired by hand, so I cannot commit, push to the worker branch, land, or run the close-report gate (all need a working git). I am releasing the claim and parking agent-blocked.

Good news — the #244 fix already exists and was re-verified this run before the corruption:

  • A prior run (while dev-factory was still LANDING=pr) completed the full fix on branch agent/issue-244 (commit ba80432) and opened PR #271, still open.
  • This run re-applied the identical code to a fresh worker branch and the touched suites were green before the wipe: tests/close-report-test.sh → 135 checks passed (incl. the new ST-1/ST-2 scenarios), tests/close-report-lib-test.sh → 77 passed, tests/docs-budget-test.sh → pass. The only red in the full offline loop was the pre-existing, unrelated tests/rehearsal-heal-lib-test.sh (fails on a clean tree; #231/#223 Factory-Account trailer).

What a human must do to re-arm:

  1. Resolve the worktree corruption (it likely hit sibling runs on this host too — elitebook-distributed-server-03): reset/recreate the sandbox worktrees from a clean .git.
  2. Land the #244 fix. Since dev-factory is now LANDING=push again (#276), the simplest path is to re-apply ba80432's diff on top of current main (its STATUS.md header + journal need refreshing to today / push-landing — PR #271's copy is stale from the pr era and still says LANDING=pr), or merge PR #271 and follow up with a STATUS/journal correction. The code changes (close-report.sh *) push-mode refetch branch, close-report-lib.sh gate-1 refusal message carrying CR_HEAD_FETCHED_AT, and the ST-1/ST-2 tests) are unchanged and correct.
  3. Re-add ready-for-agent only if a fresh pass is still wanted; otherwise close via the merge/land of the existing work.

No code landed from this run (git was unusable), so there is nothing of mine to revert.

## Blocked — `agent-blocked` (broken environment: git worktree corruption) **What blocks it:** mid-run, this sandbox's git worktree was corrupted by a shared-admin-dir wipe (the hazard CLAUDE.md rule 8 warns about). Concretely: - `/home/agent/workspace/.git` (the worktree pointer file) vanished and every tracked file was removed from the working tree — only directories survive. - The backing repo is intact at `…/dev-factory/.git`, but its `.git/worktrees/` admin directory is **entirely gone** — no admin entry for any worktree remains, so my worktree `sandcastle-worker-20261017-050614-fc0976` lost its backing. This is the classic "a parallel worker mutated the shared `.git/worktrees/` admin dir and corrupted a sibling worktree" failure. Per rule 8 this is a harness bug and must not be repaired by hand, so I cannot commit, push to the worker branch, land, or run the close-report gate (all need a working git). I am releasing the claim and parking `agent-blocked`. **Good news — the #244 fix already exists and was re-verified this run before the corruption:** - A prior run (while dev-factory was still `LANDING=pr`) completed the full fix on branch **`agent/issue-244`** (commit `ba80432`) and opened **PR #271**, still open. - This run re-applied the identical code to a fresh worker branch and the touched suites were green before the wipe: `tests/close-report-test.sh` → **135 checks passed** (incl. the new ST-1/ST-2 scenarios), `tests/close-report-lib-test.sh` → **77 passed**, `tests/docs-budget-test.sh` → pass. The only red in the full offline loop was the pre-existing, unrelated `tests/rehearsal-heal-lib-test.sh` (fails on a clean tree; #231/#223 Factory-Account trailer). **What a human must do to re-arm:** 1. Resolve the worktree corruption (it likely hit sibling runs on this host too — `elitebook-distributed-server-03`): reset/recreate the sandbox worktrees from a clean `.git`. 2. Land the #244 fix. Since dev-factory is now `LANDING=push` again (#276), the simplest path is to re-apply `ba80432`'s diff on top of current `main` (its STATUS.md header + journal need refreshing to today / push-landing — PR #271's copy is stale from the pr era and still says `LANDING=pr`), or merge PR #271 and follow up with a STATUS/journal correction. The code changes (`close-report.sh` `*)` push-mode refetch branch, `close-report-lib.sh` gate-1 refusal message carrying `CR_HEAD_FETCHED_AT`, and the ST-1/ST-2 tests) are unchanged and correct. 3. Re-add `ready-for-agent` only if a fresh pass is still wanted; otherwise close via the merge/land of the existing work. No code landed from this run (git was unusable), so there is nothing of mine to revert.
Author
Owner

Landed on main as 6b2062f (2026-10-17, Ben's session): PR #271's ba80432 rebased onto 655b7cf. Conflicts resolved: STATUS.md header (rewritten, 1840 bytes) and docs/GOTCHAS.md — the PR's gotcha was numbered 75, which #280/#282 had taken on main, so it is now GOTCHAS 77 (docs/gotchas/77-push-mode-close-report-gates-against-a-stale-origin-main.md; journal reference updated). close-report.sh and the tests auto-merged against #283's gate_head_desc changes. Verified on the rebased commit: tests/close-report-test.sh 137 checks passed, tests/close-report-lib-test.sh 77 passed, tests/docs-budget-test.sh 4/4, bash -n close-report.sh clean. The agent-blocked worktree corruption above was the sandbox, not the fix. PR #271 closed unmerged (superseded by the rebased commit). Root-only, INERT until re-vendor (GOTCHAS 4).

Landed on `main` as `6b2062f` (2026-10-17, Ben's session): PR #271's `ba80432` rebased onto `655b7cf`. Conflicts resolved: `STATUS.md` header (rewritten, 1840 bytes) and `docs/GOTCHAS.md` — the PR's gotcha was numbered 75, which #280/#282 had taken on main, so it is now **GOTCHAS 77** (`docs/gotchas/77-push-mode-close-report-gates-against-a-stale-origin-main.md`; journal reference updated). `close-report.sh` and the tests auto-merged against #283's `gate_head_desc` changes. Verified on the rebased commit: `tests/close-report-test.sh` 137 checks passed, `tests/close-report-lib-test.sh` 77 passed, `tests/docs-budget-test.sh` 4/4, `bash -n close-report.sh` clean. The agent-blocked worktree corruption above was the sandbox, not the fix. PR #271 closed unmerged (superseded by the rebased commit). Root-only, INERT until re-vendor (GOTCHAS 4).
ben 2026-10-17 19:40:47 +00:00
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#244
No description provided.