Skip to content

Batch 673: sandbox refusal alerts once across reloads; worker pipes closed (BACKLOG #6830, #6831) - #3257

Open
wshallwshall wants to merge 13 commits into
mainfrom
b673/6830-graphshape-compare
Open

wshallwshall wants to merge 13 commits into
mainfrom
b673/6830-graphshape-compare

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Batch 673 (pipeline). This is its own PR because it changes the sandbox refusal alert and the sandbox's re-pend path, and adds a dated note to ADR 0187. It merges clean with current main (git merge-tree exit 0).

OWNER QUESTION -- this PR holds until the owner rules. With this change, a graph-mismatch refusal that a reload, rollback or graph change has overtaken is raised as SandboxSessionClosed. It is re-pended or retried on a fresh session, with no alert, instead of being dead-lettered. The message's rerun compares against the current graph. If the mismatch still stands, the rerun alerts and dead-letters as before. A reviewer reads this as departing from the owner ruling of 2026-10-16 (vault #2724: "alert, keep dead-letter"). The Manager reads that ruling as still met on the rerun. The Manager has put the question to the owner; record the answer here.

BACKLOG #6830 -- one alert per refusal across reloads

  • Source branch b673/6830-graphshape-compare, head 3043fe660c388c3f4c6dfff833f7a90631835f50.
  • Verdict: REAL, fixed. Half 1 (is against ==) is real and fixed, and == is kept in the session's refusal cache.
  • Change in wiring_runner.py:
    • The change touches _off_loop_sandboxed (the alert gate and the retry/re-pend path) and adds a new _sandboxed_dispatch.
    • A refusal counts as overtaken when its session was discarded, or when it was compared against a graph unequal to the one served.
    • An overtaken refusal is raised as SandboxSessionClosed.
    • A session still serving when only the graph changed is closed and dropped.
    • If session.close() raises in that branch, a WARNING is logged and SandboxSessionClosed is still raised.
  • Pinned by tests:
    • one alert across an equal-registry swap;
    • a reload to an equal graph that straddles the refusal, for first and for cached refusals;
    • a same-registry reload, with a real worker, and the same reload under stop;
    • a graph change, then a return to an equal graph;
    • no mismatched worker is ever kept;
    • a close failure in the overtaken branch.
  • Docs: CONFIGURATION.md (step 4 and the alerting text), the alerts.py docstring, the GRAPH_MISMATCH comment, a dated ADR 0187 note under Amendment B, and changelog.d/6830.fixed.md.
  • Proposed banner: CLOSED (fixed). Half 1 (is vs ==) REAL and fixed; a refusal overtaken by a reload, a rollback or a graph change re-pends as a closed session, and its rerun alerts if the cause stands; one alert per refusal, each case pinned. Half 2 (the transient-mismatch latch) not adjudicated.

BACKLOG #6831 -- the sandbox closes its worker's pipes

  • Verdict: REAL. A test measured 3 ResourceWarnings per closed worker.
  • Fix:
    • The reap closes stdin. A lookup helper the dispatch gave up on closes stdin itself, and a lock-guarded handoff decides which side closes.
    • Each drain thread closes its own stream.
    • A timed-out wait, or an OSError from the wait, logs a WARNING with the inbound and pid only.
    • Close failures log at DEBUG.
    • New file tests/test_sandbox_pipe_close.py, and changelog.d/6831.fixed.md.
  • Proposed banner: CLOSED (fixed). REAL; the reap and the drains close the worker's pipes, an abandoned lookup helper closes stdin, and a timed-out wait is logged.

Checks (Builder):

  • ruff, both mypy package legs and mypy on the touched tests: clean.
  • 13 doc, ADR and sandbox test files: 1613 passed, 89 skipped.
  • Full suite not run. Read the Linux and Windows test legs; the pipe-close tests are platform-sensitive.

QA: xhigh. Rounds: 2 + 2 unrepaired. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (round-ec855c51, round-22802361, round-b8dd91aa, round-c121d5af). Manager-directed repairs followed each unrepaired round. The head, 3043fe66, is text only, and no review round ran on it.

Open findings, to file under R2:

  1. An overtaken refusal is logged at ERROR with a traceback, and then the lane backs off 1 s.
  2. The inline close in the graph-overtaken branch can stall that inbound's worker, or be orphaned if stop cancels it.
  3. A lookup helper that never ends keeps stdin and its Popen alive for the engine's lifetime.
  4. Altitude: dropping sessions on every registry swap would remove the graph-overtaken branch.
  5. The ResourceWarning test has no positive control on its name=<fd> filter, and _reap is not called on a held or released worker in the tests.
  6. The overtaken check takes the graph-shape lock on the loop for every refusal.
  7. #6830 half 2, the transient-mismatch latch, is not adjudicated.

The cache keyed on `is`, so a graph callable returning an equal but
new GraphShape per call spawned a worker and raised a first refusal
per spawn. Compared with `==`; a hit only refuses. The mid-write
latch half is not a bug: workers run the session's snapshot and
never read the directory; a test pins it.

BACKLOG #6830

Proposed banner: CLOSED. Half 1 real (unmemoized graph callable
missed the cache), fixed with a value compare and a failing test.
Half 2 not a bug: snapshot, not disk, feeds every respawn; pinned.
A cache hit now carries the graph the worker was compared with. The
runner lock comment names the alert gate as the reason for one shape
per registry. The changelog fragment is a bullet scoped to direct
SandboxSession callers. The duplicate mid-write test is dropped:
tests/test_config_snapshot.py already pins that a respawn runs the
snapshot, not the disk.

BACKLOG #6830

Proposed banner: CLOSED. Half 1 real (unmemoized graph callable
missed the cache), fixed with a value compare and a failing test.
Half 2 not a bug: the snapshot, not the disk, feeds every respawn.
BACKLOG #6830

Proposed banner: CLOSED. Half 1 real: a SandboxSession graph callable
returning an equal but new GraphShape missed the refusal cache, so
each spawn started a worker; fixed with a value compare and a failing
test (the runner memoizes, so serve was not affected). Half 2 not a
bug for any session given a snapshot, which every runner session for
a loaded registry is: respawns run the snapshot, never the disk. A
snapshot=None session reads the disk once and keeps it by #2596
design; that is the snapshot cache, not the refusal latch.
The session cache matches an equal graph, so its later hits are never
first. The gate compared by identity, so a first refusal raised
against an equal graph the runner was not serving the same object of
(a swap to an equal registry) dropped the alert for the session's
life. A runner-level test covers the cache and the gate together.

BACKLOG #6830

Proposed banner: CLOSED. Half 1 real: an equal but new GraphShape
missed the refusal cache; the cache and the runner's alert gate now
both compare by value, with tests. Half 2 not a bug for sessions given
a snapshot: respawns run the snapshot, never the disk.
A reload to an equal graph discards the session; with the by-value
gate, a refusal still in flight then alerted beside the fresh
session's own. The gate now also requires that the refusing session
is the one the runner holds for the inbound. Docs, docstrings, the
changelog and the replaced-graph test say what the code does.

BACKLOG #6830

Proposed banner: CLOSED. Half 1 real: an equal but new GraphShape
missed the refusal cache; the cache and the runner's alert gate now
compare by value, and the gate alerts only for the live session.
Half 2 not a bug for sessions given a snapshot.
The alert gate in _off_loop_sandboxed traded one defect for another:
compared by value alone it raised a duplicate alert when a refusal
straddled a reload to an equal graph, and with the live-session check
added it lost the alert when a same-registry reload (reload(None), a
rollback) discarded the session under stop or with no next message.

A refusal from a session a reload or a rollback discarded, or against
a graph unequal to the one served, is now raised as
SandboxSessionClosed by the new _sandboxed_dispatch. It is retried on a
fresh session while the same registry is served and the runner is not
stopping, and re-pended otherwise, so it neither alerts nor
dead-letters; the message's own rerun compares again and that refusal
raises the one alert. Functions touched in wiring_runner.py:
_off_loop_sandboxed (alert gate and re-pend path) and the new
_sandboxed_dispatch. Docs and changelog now state this exactly.

BACKLOG #6830
Measured: closing a session left the worker's stdin, stdout and stderr
to the collector, which raised three ResourceWarnings, and a reap whose
wait timed out passed silently. The reap now closes stdin unless a
lookup helper the dispatch gave up on still holds it, in which case
that helper closes it when it ends; each drain thread closes the stream
it reads; a TimeoutExpired or OSError from the wait logs a WARNING with
the inbound and pid only.

BACKLOG #6831

Proposed vault banners:
#6830: CLOSED (fixed) -- the refusal cache and the alert gate compare
the graph by value; a refusal a reload overtook re-pends as a closed
session; one alert per refusal across an equal-registry swap, a reload
to an equal graph and a same-registry reload, each pinned by a test.
#6831: CLOSED (fixed) -- real, measured as three ResourceWarnings; the
reap and the drains close the pipes, and a timed-out wait is logged.
The rule for an overtaken refusal is stated in _sandboxed_dispatch
alone; the alert sink docstring and the GRAPH_MISMATCH comment point at
it instead of restating a narrower copy (it also names a stop, and the
same-session rerun when only the graph changed). The new _overtaken
helper skips the comparison by value when the compared graph is the
served object, the common case for every cached refusal. The retry log
line names an overtaken refusal as well as a recycled worker.

BACKLOG #6830
Who closes the request pipe is now decided under a lock shared by the
dispatch thread and its lookup helper: a helper that had already ended
when the dispatch gave up leaves the pipe to the reap, so no pipe is
left open and no worker kept in _stdin_held. A failed close logs at
DEBUG by exception type. The reap-timeout WARNING says the process
tree was reaped rather than killed, since a reap also runs for a
worker that exited on its own. A test pins both closers.

BACKLOG #6831
A refusal overtaken only by a graph change, with the session still
serving, left the overtaken refusal in that session's cache; once an
equal graph was served again the rerun was refused from the cache, not
first, and no alert was ever raised. _sandboxed_dispatch now discards
and closes that session, so the rerun always compares on a fresh one.
The _overtaken helper is folded back in. The operator doc no longer
says a refusal at stop is never failed: only a discarded session's is.

BACKLOG #6830
The stderr relay closes its stream in a nested finally, so a fault in
its final flush cannot leave the pipe to the collector. The reap's
comment on who writes the request pipe now names the helper the
dispatch thread waits on. The ResourceWarning test counts only this
worker's three pipes, and the module reuses test_sandbox's session
builder.

BACKLOG #6831

Proposed vault banners:
#6830: CLOSED (fixed) -- half 1 (is vs ==) REAL and fixed: the refusal
cache and the alert gate compare the graph by value; a refusal a
reload, rollback or graph change overtook re-pends as a closed session
(a still-serving session is discarded), so there is one alert per
refusal across an equal-registry swap, a reload to an equal graph and a
same-registry reload, each pinned by a test. Half 2 (transient latch)
not adjudicated here.
#6831: CLOSED (fixed) -- REAL, measured as three ResourceWarnings per
worker; the reap and the drains close the pipes, an abandoned lookup
helper closes the request pipe itself, and a timed-out wait is logged.
In _sandboxed_dispatch's graph-overtaken branch, a session.close() that
raises is logged with the inbound only and the refusal is still raised
as SandboxSessionClosed, so the message is re-pended, not dead-lettered
as a Router or Handler fault. The SandboxSessionClosed text names the
overtaken cause generically rather than a reload. CONFIGURATION.md now
says a reload refused before its swap keeps the session and its cached
refusal, with no new comparison or alert.

BACKLOG #6830
CONFIGURATION.md's [sandbox] kill-line paragraph and ADR 0187, as a
dated note under Amendment B, now say that a refusal overtaken by a
reload, even one re-applying the same registry, gets no alert or runner
line and that the message's rerun alerts. Step 4 no longer claims the
message always runs again: a row whose inbound the reload removed never
runs, and repeated re-pends on a pooled lane count toward
infra_fault_stop_after. Text only.

BACKLOG #6830
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 24, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA: level xhigh. Rounds: 2 + 2 unrepaired. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (last round round-c121d5af). The head, 3043fe6, is text only and was not reviewed. Lander: this PR HOLDS for an owner ruling. The body's first section asks whether re-pending an overtaken refusal fits the 2026-10-16 'alert, keep dead-letter' ruling, and the batch 673 Manager has put that question to the owner.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

OWNER RULING, 2026-11-24, in the batch 673 Manager's chat. The question was whether re-pending an overtaken refusal, whose rerun still alerts and dead-letters a real mismatch, fits the 2026-10-16 ruling 'alert, keep dead-letter'. The owner answered: 'Fits; merge'. The hold is lifted, and the Lander may merge on its usual checks.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander hold on head 3043fe6.

Held: a red check caused by this PR. Shard 3 fails on ubuntu-latest and windows-2022 in test_vacuous_absence_assert_lint.py::test_no_file_gains_an_unguarded_absence_assertion. The report names tests/test_sandbox_pipe_close.py line 78, assert unclosed == [], which has no guard. Put a count guard the lint accepts ahead of it. The best guard is a positive control: show that the name=<fd> filter does match a ResourceWarning from a pipe deliberately left open. That also closes open finding 5.

Also needed: say whether the relayed ruling covers findings 1 and 2. The owner ruling "Fits; merge" (relayed at 16:59Z) answers whether re-pending fits. QA findings 1 and 2 are separate behaviour changes: (1) an overtaken refusal logs ERROR with a traceback, then backs off 1 s; (2) the inline close can stall the inbound's worker. Finding 2 is a liveness risk, not a fail-closed refusal. Either state that the ruling covered both, quoting the owner's question and answer, or fix them, for example by moving the close off the worker. A fix commit needs its own review round.

@github-actions github-actions Bot added the ci-red A required check went red. Attribute it before retrying. label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-red A required check went red. Attribute it before retrying. qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant