session-runner: re-check landing_mode_for at push time so a landing-pr ticket can't reach main via a stale push (idss #2181) #344

Open
matou-build-agent wants to merge 1 commit from session-runner-land-mode-recheck-2181 into main

Re-check landing_mode_for at push time (idss #2181 / #2177, ADR 0267)

The hazard

A standing session-runner session resolves a ticket's landing mode
(landing_mode_for) at pick time and injects it into the prompt as
Landing mode for this ticket (resolved by the runner): push|pr. The session
then runs for up to SESSION_RUNNER_TIMEOUT (2h). If a landing-pr label is
added to the ticket during that window — an app-report descendant must land
by a human-merged PR, never a push to main (ADR 0267) — the injected line is a
stale push, and a push-mode session pushes external-origin work straight to
main.

This is exactly what idss #2177 hit: the session pushed the fix to main
(6454feb4) before detecting the marker, then reverted (43ee3181) and re-landed
via PR #2179. No net harm that time, but the window is real. idss #2181 asks that
the session re-check landing_mode_for at land time rather than trust the
pick-time snapshot.

The fix — close the window at the last revertible moment (the push)

  • git-hooks/pre-push — Gate 0. When SESSION_RUNNER_LAND_TICKET is set
    (exported by session-runner.sh for the session subprocess; unset for
    swarm reconcile and human pushes, so a no-op there) and the push targets
    refs/heads/main, re-resolve landing_mode_for and block only on a
    CONFIRMED pr verdict
    , pointing at land-pr.sh. Fail-OPEN on any
    resolution error (unreadable tracker / missing libs): the ticket was picked
    push-mode, so under a forge blip the likeliest truth is still push, and a
    fail-CLOSED gate here would wedge every push-mode session on a transient
    fault — the inverse, larger hazard.
  • session-runner.sh. Export SESSION_RUNNER_LAND_TICKET=$pick before the
    claude call so the hook (and the git push the session runs in that checkout,
    where core.hooksPath is already wired to .sandcastle/git-hooks) can see the
    ticket.
  • prompts/session-runner-prompt.md. Tell the push-branch session to
    re-check landing_mode_for before pushing, so it lands cleanly as a PR
    instead of hitting the hook wall.

Why a hard hook guard (design note for review)

idss #2181 offered two options: (a) the session re-checks at land time, or (b)
the runner resolves the line later. (b) alone can't close the window — the runner
hands off to a 2h claude session and can't resolve later than prompt-build. (a)
via prompt text alone is soft (relies on the LLM complying). The pre-push hook is
already wired into the session checkout and runs on the session's push to main,
so it is the natural hard enforcement point: it realises (a) without trusting
the model. The prompt change is kept as the cooperative path. Happy to drop
either half if you'd prefer a lighter touch.

Tests

tests/prepush-land-mode-gate-test.sh drives real git pushes to a local bare
remote with a stubbed landing-lib:

  1. push-mode ticket → push to main allowed (today's behaviour);
  2. now-pr ticket → push to main blocked, naming #2181 + land-pr.sh;
  3. un-scoped push (no SESSION_RUNNER_LAND_TICKET — swarm/human) → allowed;
  4. a pr landing's own agent/issue-<N> push → allowed (only main is gated);
  5. unresolvable mode (lib absent) → fail-open, push allowed.

The full offline suite was run; the only failure is the pre-existing
gate-lib-test.sh gofmt-version mismatch on the runner host, reproducible on an
unmodified checkout and untouched by this change.

Landing into consumers

This is factory-vendored machinery (ADR 0180); consumers pick it up by bumping
FACTORY_REF and re-vendoring. git-hooks/pre-push, session-runner.sh and
prompts/** are already in the vendor manifest; the new test rides tests/**.

Context: idss #2181 (this ask), idss #2177 / PR #2179 (the incident), ADR 0267
(landing-pr). Filed by the idss standing session-runner working #2181.

🤖 Generated with Claude Code

## Re-check `landing_mode_for` at push time (idss #2181 / #2177, ADR 0267) ### The hazard A standing `session-runner` session resolves a ticket's landing mode (`landing_mode_for`) at **pick** time and injects it into the prompt as `Landing mode for this ticket (resolved by the runner): push|pr`. The session then runs for up to `SESSION_RUNNER_TIMEOUT` (2h). If a `landing-pr` label is added to the ticket **during** that window — an app-report descendant must land by a human-merged PR, never a push to `main` (ADR 0267) — the injected line is a stale `push`, and a push-mode session pushes external-origin work straight to `main`. This is exactly what idss #2177 hit: the session pushed the fix to `main` (`6454feb4`) before detecting the marker, then reverted (`43ee3181`) and re-landed via PR #2179. No net harm that time, but the window is real. idss #2181 asks that the session re-check `landing_mode_for` at land time rather than trust the pick-time snapshot. ### The fix — close the window at the last revertible moment (the push) - **`git-hooks/pre-push` — Gate 0.** When `SESSION_RUNNER_LAND_TICKET` is set (exported by `session-runner.sh` for the session subprocess; **unset** for swarm reconcile and human pushes, so a no-op there) **and** the push targets `refs/heads/main`, re-resolve `landing_mode_for` and **block only on a CONFIRMED `pr` verdict**, pointing at `land-pr.sh`. **Fail-OPEN** on any resolution error (unreadable tracker / missing libs): the ticket was picked push-mode, so under a forge blip the likeliest truth is still push, and a fail-CLOSED gate here would wedge *every* push-mode session on a transient fault — the inverse, larger hazard. - **`session-runner.sh`.** Export `SESSION_RUNNER_LAND_TICKET=$pick` before the claude call so the hook (and the `git push` the session runs in that checkout, where `core.hooksPath` is already wired to `.sandcastle/git-hooks`) can see the ticket. - **`prompts/session-runner-prompt.md`.** Tell the push-branch session to re-check `landing_mode_for` *before* pushing, so it lands cleanly as a PR instead of hitting the hook wall. ### Why a hard hook guard (design note for review) idss #2181 offered two options: (a) the session re-checks at land time, or (b) the runner resolves the line later. (b) alone can't close the window — the runner hands off to a 2h claude session and can't resolve later than prompt-build. (a) via prompt text alone is soft (relies on the LLM complying). The pre-push hook is already wired into the session checkout and runs on the session's push to `main`, so it is the natural **hard** enforcement point: it realises (a) without trusting the model. The prompt change is kept as the cooperative path. Happy to drop either half if you'd prefer a lighter touch. ### Tests `tests/prepush-land-mode-gate-test.sh` drives real `git push`es to a local bare remote with a stubbed `landing-lib`: 1. push-mode ticket → push to `main` allowed (today's behaviour); 2. now-`pr` ticket → push to `main` **blocked**, naming #2181 + `land-pr.sh`; 3. un-scoped push (no `SESSION_RUNNER_LAND_TICKET` — swarm/human) → allowed; 4. a `pr` landing's own `agent/issue-<N>` push → allowed (only `main` is gated); 5. unresolvable mode (lib absent) → **fail-open**, push allowed. The full offline suite was run; the only failure is the pre-existing `gate-lib-test.sh` gofmt-version mismatch on the runner host, reproducible on an unmodified checkout and untouched by this change. ### Landing into consumers This is factory-vendored machinery (ADR 0180); consumers pick it up by bumping `FACTORY_REF` and re-vendoring. `git-hooks/pre-push`, `session-runner.sh` and `prompts/**` are already in the vendor manifest; the new test rides `tests/**`. Context: idss #2181 (this ask), idss #2177 / PR #2179 (the incident), ADR 0267 (`landing-pr`). Filed by the idss standing session-runner working #2181. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
session-runner: re-check landing_mode_for at PUSH time, not only the injected pick-time snapshot (idss #2181/#2177)
All checks were successful
ci / static (pull_request) Successful in 3m23s
ci / test (pull_request) Successful in 7m47s
53a37db2c1
A standing session-runner session resolves a ticket's landing mode
(landing_mode_for) at PICK time and injects it into the prompt as a
"Landing mode for this ticket (resolved by the runner): push|pr" line.
The session then runs for up to SESSION_RUNNER_TIMEOUT (2h). If a
`landing-pr` label is added to the ticket DURING that window — an
app-report descendant must land by a human-merged PR, never a push to
main (ADR 0267) — the injected line is stale `push`, and a push-mode
session pushes external-origin work straight to `main` (idss #2177;
it self-corrected only after the bad push by reverting + re-landing as
PR #2179).

Close the window at the last revertible moment — the push itself:

- git-hooks/pre-push gains Gate 0: when SESSION_RUNNER_LAND_TICKET is set
  (exported by session-runner.sh for the session subprocess; UNSET for
  swarm reconcile and human pushes, so a no-op there) AND the push targets
  refs/heads/main, re-resolve landing_mode_for and BLOCK on a CONFIRMED
  `pr` verdict, pointing at land-pr.sh. Fail-OPEN on any resolution error
  (unreadable tracker / missing libs): the ticket was picked push-mode, so
  a forge blip's likeliest truth is still push, and a fail-CLOSED gate here
  would wedge every push-mode session on a transient fault.
- session-runner.sh exports SESSION_RUNNER_LAND_TICKET=$pick before the
  claude call so the hook (and the `git push` the session runs in that
  checkout, where core.hooksPath is already wired) can see the ticket.
- prompts/session-runner-prompt.md tells the push-branch session to
  re-check landing_mode_for before pushing, so it lands cleanly as a PR
  instead of hitting the hook wall. The committed rendered copies that the
  render-prompts cutover test pins — .sandcastle/session-runner-prompt.md
  (this repo's self-vendor) and onboarding/tests/fixtures/idss-prompts/
  session-runner-prompt.md — are regenerated from the edited skeleton.

Test: tests/prepush-land-mode-gate-test.sh drives real `git push`es to a
local bare remote with a stubbed landing-lib — a now-pr ticket is blocked
from pushing main; a push-mode ticket, an un-scoped (swarm/human) push, a
pr landing's own agent-branch push, and an unresolvable mode (fail-open)
all pass. onboard-lib-test's render cutover proof re-passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
All checks were successful
ci / static (pull_request) Successful in 3m23s
ci / test (pull_request) Successful in 7m47s
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin session-runner-land-mode-recheck-2181:session-runner-land-mode-recheck-2181
git switch session-runner-land-mode-recheck-2181

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff session-runner-land-mode-recheck-2181
git switch session-runner-land-mode-recheck-2181
git rebase main
git switch main
git merge --ff-only session-runner-land-mode-recheck-2181
git switch session-runner-land-mode-recheck-2181
git rebase main
git switch main
git merge --no-ff session-runner-land-mode-recheck-2181
git switch main
git merge --squash session-runner-land-mode-recheck-2181
git switch main
git merge --ff-only session-runner-land-mode-recheck-2181
git switch main
git merge session-runner-land-mode-recheck-2181
git push origin main
Sign in to join this conversation.
No reviewers
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!344
No description provided.