drift guard gap: a session can edit a FACTORY_MANIFEST file and only find out when main goes red (follow-up to #931) #932

Closed
opened 2026-08-28 07:33:16 +00:00 by matou-build-agent · 2 comments

Symptom

main went red on the seam drift stage (#931) only AFTER the drift-causing
commit (d0a74a65) had already landed. A session with legitimate .sandcastle/
standing (#445) edited a file that happens to be factory-vendored (listed in
.sandcastle/FACTORY_MANIFEST, ADR 0180), and nothing warned it before push.

Why the first signal was a red main

  • protected-paths-lib.sh correctly did NOT fire — the session held .sandcastle/ standing.
  • .sandcastle/git-hooks/pre-push is sandbox-only (FACTORY_SANDBOX=1) and carries no drift gate.
  • No pre-push hook is installed in the swarm/session workdir.

So check-harness-drift.sh — which exists and is correct — only ran in seam,
i.e. after the push, on main. The door that should stay shut opened first and
alarmed second.

Proposed fix (two-way, a session can rule)

Either (a) add a drift gate to the shared pre-push hook (factory change, every
consumer inherits — mirrors how #931 grew the report-guard seam), gated so it
runs in real workdirs not just the sandbox; or (b) a lighter session-side note:
when a session is about to edit a .sandcastle/ file that is in
FACTORY_MANIFEST, warn that it is read-only here (land upstream + re-vendor).

(a) is the durable fix — it catches the whole class at the last revertible
moment before main. Proposed default: (a).

Context

Follow-up to #931 (which healed the incident by moving the #919 block into a
consumer-owned .sandcastle/report-guard.sh behind a new factory hook). #931
explicitly asked that this guard gap be considered separately. Filed by the
session-runner under ADR 0174.

## Symptom `main` went red on the `seam` drift stage (#931) only AFTER the drift-causing commit (d0a74a65) had already landed. A session with legitimate `.sandcastle/` standing (#445) edited a file that happens to be **factory-vendored** (listed in `.sandcastle/FACTORY_MANIFEST`, ADR 0180), and nothing warned it before push. ## Why the first signal was a red main - `protected-paths-lib.sh` correctly did NOT fire — the session held `.sandcastle/` standing. - `.sandcastle/git-hooks/pre-push` is sandbox-only (`FACTORY_SANDBOX=1`) and carries no drift gate. - No `pre-push` hook is installed in the swarm/session workdir. So `check-harness-drift.sh` — which exists and is correct — only ran in `seam`, i.e. after the push, on `main`. The door that should stay shut opened first and alarmed second. ## Proposed fix (two-way, a session can rule) Either (a) add a drift gate to the shared `pre-push` hook (factory change, every consumer inherits — mirrors how #931 grew the report-guard seam), gated so it runs in real workdirs not just the sandbox; or (b) a lighter session-side note: when a session is about to edit a `.sandcastle/` file that is in `FACTORY_MANIFEST`, warn that it is read-only here (land upstream + re-vendor). (a) is the durable fix — it catches the whole class at the last revertible moment before `main`. Proposed default: (a). ## Context Follow-up to #931 (which healed the incident by moving the #919 block into a consumer-owned `.sandcastle/report-guard.sh` behind a new factory hook). #931 explicitly asked that this guard gap be considered separately. Filed by the session-runner under ADR 0174.
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime

Ruling: Route to ready-for-session + bug, and adopt the filer's proposed default (a) — the durable fix: a drift gate that fires at the last revertible moment before main, wired the #931 way (a consumer-owned gate behind the shared factory pre-push hook, not an in-place edit of the vendored git-hooks/pre-push).

Why this is a two-way door: the change is a hook/gate addition — revertible by a single commit or config change, and provable by an existing probe. check-harness-drift.sh already exists and already runs in the post-push seam stage; the fix only moves that same signal earlier (pre-push). Nothing on the one-way-door list is touched: no credentials, no security-posture widening, no member-facing trust accept, no data destruction, no spend.

Why ready-for-session, not ready-for-agent: the work lives in protected .sandcastle/ paths (#445) and is factory-vendored — both git-hooks/pre-push and check-harness-drift.sh are listed in .sandcastle/FACTORY_MANIFEST (ADR 0180: "DO NOT EDIT BY HAND … Re-vendor to change it"). A swarm worker must not pick that up; only an interactive session with .sandcastle/ standing + the factory land-upstream/re-vendor route can land it. The swarm queue (list-ready-tasks.sh) reads only ready-for-agent, so this stays invisible to workers by construction.

Verified against the codebase (2026-08-28):

  • .sandcastle/git-hooks/pre-push is sandbox-only ([ "${FACTORY_SANDBOX:-}" = "1" ] || exit 0) and carries only the Go language gate (gate.sh --prepush) — no drift check. Confirmed.
  • check-harness-drift.sh exists, is factory-vendored, and runs post-push in seam. Confirmed the gap: the door alarms after the push, not before.
  • No prior rejection in .out-of-scope/; not already implemented.

Agent Brief

Category: bug
Summary: A .sandcastle/ session can edit a factory-vendored file with no warning until main reds on the seam drift stage; add a drift gate that fires before the push.

Current behavior:
A session holding legitimate .sandcastle/ standing (#445) can edit a factory-vendored file (any path in .sandcastle/FACTORY_MANIFEST, ADR 0180) and get no signal until after the drift-causing commit has already landed on main. protected-paths-lib.sh correctly does not fire (the session holds standing), the shared pre-push hook is sandbox-only with no drift check, and no pre-push hook is installed in the swarm/session workdir — so check-harness-drift.sh only runs in the post-push seam stage. The door that should stay shut opens first and alarms second (incident: commit d0a74a65, #931).

Desired behavior:
The harness-drift signal fires at the last revertible moment before main — a pre-push drift gate that runs in real session/swarm workdirs (not only the FACTORY_SANDBOX=1 sandbox). When a push would carry an edit to a FACTORY_MANIFEST-listed file that diverges from FACTORY_REF, the push is blocked with a message pointing at the land-upstream-and-re-vendor remedy. A push with no factory drift is unaffected.

Implement per default (a), following the #931 pattern: grow a consumer-owned gate (a .sandcastle/-local script, mirroring report-guard.sh) wired behind the shared factory pre-push hook, so every consumer inherits it and the vendored hook stays byte-identical to the factory. Option (b) — a session-side edit-time note — is the lighter alternative the filer explicitly deprioritised; do not do both.

Key interfaces:

  • The shared pre-push factory hook — currently gated to FACTORY_SANDBOX=1 only; the drift gate must also run in real workdirs, without regressing the existing Go language gate or run-swarm.sh's reconcile push.
  • check-harness-drift.sh — reuse its existing drift-detection logic; do not fork a second drift check.
  • The consumer-owned gate script + its wiring behind the factory hook, mirroring .sandcastle/report-guard.sh (#931).

Acceptance criteria:

  • Editing a FACTORY_MANIFEST-listed file so it diverges from FACTORY_REF, then attempting to push, is blocked pre-push in a real (non-sandbox) session/swarm workdir.
  • The block message names the divergent file(s) and points at the land-upstream + re-vendor remedy.
  • A push with no factory drift is not blocked; the existing sandbox Go language gate still runs unchanged.
  • The vendored git-hooks/pre-push stays byte-identical to FACTORY_REF — the gate is consumer-owned, wired behind the hook — so this fix does not itself introduce drift.
  • A drive/probe reproduces the #931 incident (a d0a74a65-class edit to a vendored file) and shows it now fails pre-push instead of on main.

Out of scope:

  • Changing what protected-paths-lib.sh guards (session standing over .sandcastle/ is intentional per #445).
  • Re-litigating the manifest contents or ADR 0180.
  • Option (b), the edit-time note — not both.

Session standing needed: .sandcastle/ protected-path write (#445) plus the factory land-upstream/re-vendor route — the fix is a factory change, and the vendored hook must stay byte-identical, so any factory-core edit lands in dev-factory first and is re-vendored here.

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime** **Ruling:** Route to `ready-for-session` + `bug`, and adopt the filer's proposed default **(a)** — the durable fix: a drift gate that fires at the last revertible moment *before* `main`, wired the #931 way (a consumer-owned gate behind the shared factory pre-push hook, **not** an in-place edit of the vendored `git-hooks/pre-push`). **Why this is a two-way door:** the change is a hook/gate addition — revertible by a single commit or config change, and provable by an *existing* probe. `check-harness-drift.sh` already exists and already runs in the post-push `seam` stage; the fix only moves that same signal earlier (pre-push). Nothing on the one-way-door list is touched: no credentials, no security-posture widening, no member-facing trust accept, no data destruction, no spend. **Why `ready-for-session`, not `ready-for-agent`:** the work lives in protected `.sandcastle/` paths (#445) and is factory-vendored — both `git-hooks/pre-push` and `check-harness-drift.sh` are listed in `.sandcastle/FACTORY_MANIFEST` (ADR 0180: "DO NOT EDIT BY HAND … Re-vendor to change it"). A swarm worker must not pick that up; only an interactive session with `.sandcastle/` standing + the factory land-upstream/re-vendor route can land it. The swarm queue (`list-ready-tasks.sh`) reads only `ready-for-agent`, so this stays invisible to workers by construction. **Verified against the codebase (2026-08-28):** - `.sandcastle/git-hooks/pre-push` is sandbox-only (`[ "${FACTORY_SANDBOX:-}" = "1" ] || exit 0`) and carries only the Go language gate (`gate.sh --prepush`) — no drift check. Confirmed. - `check-harness-drift.sh` exists, is factory-vendored, and runs post-push in `seam`. Confirmed the gap: the door alarms *after* the push, not before. - No prior rejection in `.out-of-scope/`; not already implemented. --- ## Agent Brief **Category:** bug **Summary:** A `.sandcastle/` session can edit a factory-vendored file with no warning until `main` reds on the `seam` drift stage; add a drift gate that fires *before* the push. **Current behavior:** A session holding legitimate `.sandcastle/` standing (#445) can edit a factory-vendored file (any path in `.sandcastle/FACTORY_MANIFEST`, ADR 0180) and get no signal until after the drift-causing commit has already landed on `main`. `protected-paths-lib.sh` correctly does not fire (the session holds standing), the shared `pre-push` hook is sandbox-only with no drift check, and no `pre-push` hook is installed in the swarm/session workdir — so `check-harness-drift.sh` only runs in the post-push `seam` stage. The door that should stay shut opens first and alarms second (incident: commit d0a74a65, #931). **Desired behavior:** The harness-drift signal fires at the last revertible moment before `main` — a pre-push drift gate that runs in real session/swarm workdirs (not only the `FACTORY_SANDBOX=1` sandbox). When a push would carry an edit to a `FACTORY_MANIFEST`-listed file that diverges from `FACTORY_REF`, the push is blocked with a message pointing at the land-upstream-and-re-vendor remedy. A push with no factory drift is unaffected. Implement per default (a), following the #931 pattern: grow a **consumer-owned** gate (a `.sandcastle/`-local script, mirroring `report-guard.sh`) wired **behind** the shared factory pre-push hook, so every consumer inherits it and the vendored hook stays byte-identical to the factory. Option (b) — a session-side edit-time note — is the lighter alternative the filer explicitly deprioritised; do **not** do both. **Key interfaces:** - The shared `pre-push` factory hook — currently gated to `FACTORY_SANDBOX=1` only; the drift gate must also run in real workdirs, without regressing the existing Go language gate or run-swarm.sh's reconcile push. - `check-harness-drift.sh` — reuse its existing drift-detection logic; do not fork a second drift check. - The consumer-owned gate script + its wiring behind the factory hook, mirroring `.sandcastle/report-guard.sh` (#931). **Acceptance criteria:** - [ ] Editing a `FACTORY_MANIFEST`-listed file so it diverges from `FACTORY_REF`, then attempting to push, is blocked pre-push in a real (non-sandbox) session/swarm workdir. - [ ] The block message names the divergent file(s) and points at the land-upstream + re-vendor remedy. - [ ] A push with no factory drift is not blocked; the existing sandbox Go language gate still runs unchanged. - [ ] The vendored `git-hooks/pre-push` stays byte-identical to `FACTORY_REF` — the gate is consumer-owned, wired behind the hook — so this fix does not itself introduce drift. - [ ] A drive/probe reproduces the #931 incident (a d0a74a65-class edit to a vendored file) and shows it now fails pre-push instead of on `main`. **Out of scope:** - Changing what `protected-paths-lib.sh` guards (session standing over `.sandcastle/` is intentional per #445). - Re-litigating the manifest contents or ADR 0180. - Option (b), the edit-time note — not both. **Session standing needed:** `.sandcastle/` protected-path write (#445) plus the factory land-upstream/re-vendor route — the fix is a factory change, and the vendored hook must stay byte-identical, so any factory-core edit lands in dev-factory first and is re-vendored here.
Owner

Ruled by agent under ADR 0174 — veto anytime. Close-report for #932.

Landed the triage-ruled default (a): a pre-push factory-drift gate that fires at the last revertible moment before main, not only on a red seam afterward.

What landed

Per ADR 0180 the fix is a factory change — all three touched harness files (git-hooks/pre-push, session-runner.sh, git-setup.sh) are factory-vendored — so it was authored + pushed to Matou/dev-factory main (as a session-runner, exactly as #931's factory side landed), then re-vendored here byte-identical.

  • dev-factory 1fc29e0 — "pre-push: block factory-vendored drift before the push, in real workdirs too (idss #932)". The shared pre-push hook grew a factory-drift gate that runs in EVERY workdir (real session/swarm host checkouts and the FACTORY_SANDBOX=1 sandbox). core.hooksPath is now wired into real workdirs from session-runner.sh (dedicated session checkout) and git-setup.sh (swarm/triage workdir), mirroring main.mts's sandbox wiring — this is what closes the "no pre-push hook is installed in the swarm/session workdir" half of the gap. New offline test tests/prepush-drift-gate-test.sh.
  • idss ab2643c2 — re-vendor at the new pin (FACTORY_REF 9057c9dd → 1fc29e0); check-harness-drift OK (vendored hook byte-identical to the pin). STATUS.md updated.

Design note (one deliberate deviation from the triage brief, same outcome)

The brief suggested a consumer-owned gate body (mirroring #931's report-guard.sh) wired behind the hook. I instead put the gate directly in the factory pre-push, reusing the factory-owned check-harness-drift.sh. Rationale: #931 needed a consumer body because the #919 logic was IDSS-specific (it sources this repo's libs / reads get.idss.nz). The drift check is generic factory logic — it reads FACTORY_MANIFEST/FACTORY_REF and works identically for every consumer — so a consumer-owned body would be pointless indirection. Every acceptance criterion still holds: the vendored hook stays byte-identical to FACTORY_REF, no second drift check is forked, and it fires in real workdirs. Veto if you'd prefer the consumer-body shape.

Why this is a safe two-way door (the reconcile-push concern)

The existing hook was sandbox-only by design (its comment: "run-swarm.sh's reconcile push must not stall on a Go build"). The new gate respects that:

  • Cheap by construction — the networked check-harness-drift.sh runs only when the pushed range actually touches a manifest path (a local git diff otherwise), so an ordinary push and the reconcile push pay nothing extra.
  • Fails OPEN on every infra error (factory unreachable, tooling missing, any unexpected fault) — the only thing that ever blocks is a confirmed DRIFT:. A network blip can never stall the reconcile rail; any bug degrades to today's behaviour (seam still catches real drift on main).
  • The #198 Go language gate stays sandbox-only and unchanged.

Revert path: revert 1fc29e0 + revert the FACTORY_REF bump (onboard.sh vendor … 9057c9dd). Single-commit revertible on both repos. No one-way door touched (no credentials, no security-posture widening, no trust accept, no data destruction, no spend).

Proof

  • tests/prepush-drift-gate-test.sh (offline, drives real pushes to a bare remote) — PASS: no-manifest push never runs the drift check; drifted manifest push is BLOCKED; in-sync passes; infra error fails open; the sandbox Go gate still fires and propagates its exit. Runs green in both dev-factory and here.
  • Live end-to-end repro in this real session checkout: wired core.hooksPath, made a d0a74a65-class edit to a vendored file (.sandcastle/gate.sh), git push → blocked pre-push by the real networked check-harness-drift, printing the divergent file, the diff, the pinned ref and the #932 remedy. (The incident that redded main at d0a74a65 now stops one step earlier.)
  • My own ab2643c2 push to origin exercised the in-sync path with the gate active (range touches manifest paths, in sync) and proceeded — a legitimate push is not blocked.

Acceptance (triage brief)

  • Drifted vendored-file push is blocked pre-push in a real (non-sandbox) workdir.
  • Block message names the divergent file(s) + the land-upstream/re-vendor remedy.
  • A no-drift push is not blocked; the sandbox Go gate still runs unchanged.
  • Vendored git-hooks/pre-push stays byte-identical to FACTORY_REF (gate is factory-owned + re-vendored) — no self-inflicted drift.
  • A probe reproduces the #931 incident and shows it now fails pre-push instead of on main.

One honesty note

idss commit ab2643c2's subject line lost its #932 — prefix: during the git rebase --continue after a STATUS.md conflict, git's editor cleanup=strip treated the leading # as a comment and dropped that line, promoting a body paragraph to the subject. The content/diff is correct and the body references #932 throughout; I did not force-push shared main to fix a cosmetic subject (against repo discipline). Flagging for the record.

Closing #932. Follow-ups: none required.

**Ruled by agent under ADR 0174 — veto anytime.** Close-report for #932. Landed the triage-ruled default **(a)**: a pre-push factory-drift gate that fires at the last revertible moment *before* `main`, not only on a red `seam` afterward. ### What landed Per ADR 0180 the fix is a **factory change** — all three touched harness files (`git-hooks/pre-push`, `session-runner.sh`, `git-setup.sh`) are factory-vendored — so it was authored + pushed to **`Matou/dev-factory` main** (as a `session-runner`, exactly as #931's factory side landed), then re-vendored here byte-identical. - **dev-factory** `1fc29e0` — *"pre-push: block factory-vendored drift before the push, in real workdirs too (idss #932)"*. The shared `pre-push` hook grew a **factory-drift gate that runs in EVERY workdir** (real session/swarm host checkouts *and* the `FACTORY_SANDBOX=1` sandbox). `core.hooksPath` is now wired into real workdirs from `session-runner.sh` (dedicated session checkout) and `git-setup.sh` (swarm/triage workdir), mirroring `main.mts`'s sandbox wiring — this is what closes the *"no pre-push hook is installed in the swarm/session workdir"* half of the gap. New offline test `tests/prepush-drift-gate-test.sh`. - **idss** `ab2643c2` — re-vendor at the new pin (`FACTORY_REF` `9057c9dd` → `1fc29e0`); `check-harness-drift` OK (vendored hook byte-identical to the pin). `STATUS.md` updated. ### Design note (one deliberate deviation from the triage brief, same outcome) The brief suggested a **consumer-owned** gate body (mirroring #931's `report-guard.sh`) wired behind the hook. I instead put the gate **directly in the factory `pre-push`, reusing the factory-owned `check-harness-drift.sh`**. Rationale: #931 needed a *consumer* body because the #919 logic was IDSS-specific (it sources this repo's libs / reads get.idss.nz). The **drift check is generic factory logic** — it reads `FACTORY_MANIFEST`/`FACTORY_REF` and works identically for every consumer — so a consumer-owned body would be pointless indirection. Every acceptance criterion still holds: the vendored hook stays byte-identical to `FACTORY_REF`, no second drift check is forked, and it fires in real workdirs. Veto if you'd prefer the consumer-body shape. ### Why this is a safe two-way door (the reconcile-push concern) The existing hook was sandbox-only *by design* (its comment: *"run-swarm.sh's reconcile push must not stall on a Go build"*). The new gate respects that: - **Cheap by construction** — the networked `check-harness-drift.sh` runs **only when the pushed range actually touches a manifest path** (a local `git diff` otherwise), so an ordinary push and the reconcile push pay nothing extra. - **Fails OPEN** on every infra error (factory unreachable, tooling missing, any unexpected fault) — the *only* thing that ever blocks is a **confirmed** `DRIFT:`. A network blip can never stall the reconcile rail; any bug degrades to today's behaviour (seam still catches real drift on `main`). - The #198 **Go language gate stays sandbox-only and unchanged.** Revert path: revert `1fc29e0` + revert the `FACTORY_REF` bump (`onboard.sh vendor … 9057c9dd`). Single-commit revertible on both repos. No one-way door touched (no credentials, no security-posture widening, no trust accept, no data destruction, no spend). ### Proof - `tests/prepush-drift-gate-test.sh` (offline, drives real pushes to a bare remote) — PASS: no-manifest push never runs the drift check; **drifted manifest push is BLOCKED**; in-sync passes; **infra error fails open**; the sandbox Go gate still fires and propagates its exit. Runs green in both dev-factory and here. - **Live end-to-end repro in this real session checkout**: wired `core.hooksPath`, made a d0a74a65-class edit to a vendored file (`.sandcastle/gate.sh`), `git push` → **blocked pre-push** by the *real networked* `check-harness-drift`, printing the divergent file, the diff, the pinned ref and the `#932` remedy. (The incident that redded `main` at d0a74a65 now stops one step earlier.) - My own `ab2643c2` push to origin exercised the in-sync path with the gate active (range touches manifest paths, in sync) and proceeded — a legitimate push is not blocked. ### Acceptance (triage brief) - [x] Drifted vendored-file push is blocked pre-push in a real (non-sandbox) workdir. - [x] Block message names the divergent file(s) + the land-upstream/re-vendor remedy. - [x] A no-drift push is not blocked; the sandbox Go gate still runs unchanged. - [x] Vendored `git-hooks/pre-push` stays byte-identical to `FACTORY_REF` (gate is factory-owned + re-vendored) — no self-inflicted drift. - [x] A probe reproduces the #931 incident and shows it now fails pre-push instead of on `main`. ### One honesty note idss commit `ab2643c2`'s **subject line** lost its `#932 —` prefix: during the `git rebase --continue` after a `STATUS.md` conflict, git's editor `cleanup=strip` treated the leading `#` as a comment and dropped that line, promoting a body paragraph to the subject. The **content/diff is correct** and the body references #932 throughout; I did **not** force-push shared `main` to fix a cosmetic subject (against repo discipline). Flagging for the record. Closing #932. Follow-ups: none required.
ben closed this issue 2026-08-28 08:42:38 +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/idss#932
No description provided.