Skip to content

sbx-mgr: a drain pass's confirm answers by the call's deadline - #2663

Draft
ac-pplx wants to merge 1 commit into
mainfrom
ac/drain-v2-confirm-finished-rows-deadline
Draft

ac-pplx wants to merge 1 commit into
mainfrom
ac/drain-v2-confirm-finished-rows-deadline

Conversation

@ac-pplx

@ac-pplx ac-pplx commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A v2 DrainNode pass plans, then confirms each row it found finished before
it starts any work (confirm_finished_rows): it takes the row's artifact read
lock, reads the node's rows again, and leaves the row pending if it changed.
That read is synchronous: SQLite scans, plus metadata.json for each started
or paused sandbox. It ran on the async task inside the call's
tokio::time::timeout, with no await between the pass's first read and its
response, so the timeout couldn't fire there. A slow disk or a stalled database
held the call, and the confirmed rows' locks, past call_timeout. Suspends and
uploads of those sandboxes waited behind it.

The confirm's locks, its second read and its comparisons now run together on
a blocking thread, which the pass awaits under the same timeout and in the
call's span. #2654 does the same for the full preview's confirm. A
cancellation token drops with the call:

  • A confirm whose call ended before it started takes no lock and reads
    nothing.
  • One under way stops at its next check, including inside its try-lock and
    comparison loops. Cancellation is cooperative, so its locks outlive the call
    by at most the one step in progress: the wait for the database connection
    plus the scans, one upload job's lookup, one row's files, or the in-memory
    work up to the next check.
  • start_actions comes after the confirm's await, so a pass whose call ended
    starts nothing.

When nothing is abandoned, the pass confirms the same rows, leaves the same
rows pending with the same reasons in the same order, and starts the same
actions.

A call that times out keeps whatever its pass did before the confirm: the
persisted seal, the evacuate flag, and a reset of the failures when the
generation changed. It starts no action, and the next call plans from scratch.
Trade-off for review: the call slot. The slot is released when the call
ends, as today and as #2654's preview slot is, so a next call can run while an
abandoned confirm finishes its step. The abandoned confirm writes nothing the
next call reads. If it still holds a row's lock, the next call's try-lock
leaves that row pending, as for any held artifact lock. When the abandoned step
is the wait for the database or its scans, the next call's first read, and a
cancel's or a new generation's seal write, wait for the same database on the
async task. So under a database stall that call, rather than the first, can
run past its deadline until the database frees; on main, the first call
blocked for the whole stall and a retry was refused at once. This PR releases the slot.
The alternative is to hold it until the abandoned confirm ends, which refuses
the retry instead, at the cost of coupling the slot to blocking work. Which of
the two to keep is a maintainer decision, still pending.

This follows #2654 and uses its read_plan_reads_while, the latched,
checkpointed read.

Validation

  • New test, a_stalled_drain_confirm_answers_by_its_deadline_and_starts_nothing.
    A test-only SQL trace hook stalls the confirm's read while it holds a
    finished row's lock.
    • With a 1 s call timeout, the call answers DeadlineExceeded while the
      lock is held, and nothing is running, failed or queued.
    • From the release until the lock frees, it counts upload-job lookups: the
      read it gave up makes none, though a row's pending backup would have it
      look one up.
    • Once the stall ends, the lock frees, and the next call confirms the row and
      starts its upload.
    • It takes about 1.03 s.
    • With the read not given the call's cancellation, the abandoned read makes
      two lookups and the test fails.
    • With the move reverted, the call answers Ok and starts the upload, and
      the test fails.
  • New unit test, a_drain_confirm_given_up_stops_at_its_check_and_drops_its_locks.
    With two finished rows, the confirm asks eight times: before each lock, four
    times in its read, and before each comparison. Answering false at each check
    in turn, it confirms nothing, asks no further, and leaves both rows' locks
    free. Removing a per-row check or the latch fails it.
  • The existing busy-lock and changed-row recheck tests show the same rows left
    pending, with the same reasons.
  • 51 existing test call sites gain .await, because run_drain_pass and
    finish_drain are now async.
  • On a remote Linux host, in CI's image, at this change on main 8aa7838edd:
    rustfmt, workspace Clippy with CI's flags, and sandbox-manager's unprivileged
    Nextest (2113 passed). This head sits on f66f4cd7d7, whose only additional
    commit changes no sandbox-manager file.
  • CI on this head, with the Kind smoke run through the kind-smoke label while
    this stays a draft: Pull CI,
    all 14 Kind shards passed, and the Direct substrate Kind lane
    passed. That run is evidence for this code, which releases the call slot. A
    change to hold the slot instead would get its own Kind run.

Severity and risk

Severity: low to moderate. A stalled confirm kept the drain call, and the
artifact locks of the rows it confirmed, until its read finished, past the
call's timeout.

Risk: the pass gains one await point. A call cancelled there leaves the state
above, which the next call plans again. The confirm runs on Tokio's blocking
pool. Rollback is a revert.

Rollout

No wire, schema or persisted-state change; sandbox-manager only.

Not covered

  • Known: this PR's new stall test builds its service on the test's only
    runtime thread, so it has the same latent race sbx-mgr: the full preview's stall test no longer races the watchdog #2695 fixes for the full
    preview's stall test (3 failures in 60 runs on a saturated runner). The same
    separate-runtime change is committed and lands with the next push here,
    before this is marked ready.
    The pass's own first read, before planning, and the cheap preview's read still
    run on the async task. Neither takes artifact locks, but a stall there can also
    run past the deadline, including the retry case above. Moving the first read
    onto the same pattern would fix that for the read, though not for the seal
    writes.

AI assistance: Claude Code drafted the change, the test and this description.

Local review: round 2 (Codex + Claude), READY after fixes; the one fix was to this description.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Passed 6

Check name Status Explanation
Description Follows The Pr Template Passed The PR description (PR #2663, author ac-pplx) meets all four required items. Checked against the description text, no code inspection was needed. 1. "## Summary": Present with content. It states t…
Bug Fixes Name A Regression Test Passed The check applies. PR #2663 (head 325fe87, base f66f4cd) fixes a defect in application code under crates/: the drain pass's confirm step ran synchronously on the async task inside the call's timeo…
Weakened Safeguards Are Justified Passed No weakened safeguard without a reason. PR #2663 (author ac-pplx, head 325fe87, base 8aa7838) changes three test files in the PR commit and, across the full patch, moves substrate code from `contr…
Agent Tooling Runs No New Commands Passed The check does not apply to this change. The PR's own commit, 325fe87 ("sbx-mgr: a drain pass's confirm answers by the call's deadline"), changes only three Rust files under crates/l40_api/sbx/mgr/s…
External Code Sources Need A Person Passed The check fails only if the diff adds or changes an external code source: a git/rev/branch/tag/registry key or an external path on a Cargo dependency, a container image reference, a downloaded binary'…
Public-Safe Content Passed The public-safe content check passes for PR #2663 (perplexityai/SPACE, head ac/drain-v2-confirm-finished-rows-deadline, base main). Diff: The PR commit 325fe8715 changes three sandbox-manager dr…
Full details: Description Follows The Pr Template

Explanation

The PR description (PR #2663, author ac-pplx) meets all four required items. Checked against the description text, no code inspection was needed. 1. "## Summary": Present with content. It states that the confirm step moves onto a blocking thread under the call's timeout and cancellation token, and what changes when a call is abandoned. 2. "## Validation": Present with content. It names the new tests, the commands run (rustfmt, workspace Clippy, sandbox-manager Nextest with 2113 passed), and the CI results ("CI on this head" with the Pull CI and Direct substrate Kind lane runs). 3. "## Severity and risk": Present with content. It gives "Severity: low to moderate" and a "Risk:" paragraph describing the added await point and rollback. 4. "AI assistance:": Present as its own line. It reads "AI assistance: Claude Code drafted the change, the test and this description," which names the tool and the parts it drafted. Judged on presence only, as the check requires. No item is missing or empty.

Full details: Bug Fixes Name A Regression Test

Explanation

The check applies. PR #2663 (head 325fe87, base f66f4cd) fixes a defect in application code under crates/: the drain pass's confirm step ran synchronously on the async task inside the call's timeout, so a stalled database or disk could hold the call and the artifact locks past the deadline. The PR-only changes are in crates/l40_api/sbx/mgr/server/src/service/drain_node/{rpc.rs,tests.rs,producer_tests.rs}. The confirm now runs on a blocking thread under the same timeout, with a cancellation token. The Validation section names a regression test, a_stalled_drain_confirm_answers_by_its_deadline_and_starts_nothing. I confirmed it exists at crates/l40_api/sbx/mgr/server/src/service/drain_node/tests.rs:5350. The Validation section states that with the move reverted, the call answers Ok and starts the upload, so the test fails. It also states that the test passes with the fix. I did not run the test. The claim comes from the PR description. The Validation section also names a second unit test, a_drain_confirm_given_up_stops_at_its_check_and_drops_its_locks, which exists at tests.rs:5484.

Full details: Weakened Safeguards Are Justified

Explanation

No weakened safeguard without a reason. PR #2663 (author ac-pplx, head 325fe87, base 8aa7838) changes three test files in the PR commit and, across the full patch, moves substrate code from controllers/substrate/mod.rs into substrate/core (commit f66f4cd). Checked items: - Test assertions (drain_node/tests.rs, producer_tests.rs): Every removed assertion has an equivalent added line. The only difference is .await, which the async finish_drain/run_drain_pass now require. No test function was removed. Two new tests were added. No #[ignore], #[should_panic] or #[allow] was added there. - Assertion change (controllers/template/tests.rs:185, 694): error.message became error.to_string(). ControllerError uses #[error("{message}")], so the text is the same. - Moved attributes: #[deny(clippy::missing_trait_methods)] (substrate.rs:594), #[allow(async_fn_in_trait)] (substrate/core/src/lib.rs:1314) and #[serde(deny_unknown_fields)] (substrate/core/src/models.rs:33) all still exist in their new files. The allow is the same attribute on the same trait, moved, not newly added. - Lint tables: substrate/core/Cargo.toml keeps [lints] workspace = true. The api Cargo.toml change only adds a dependency. - ARCHITECTURE.toml allow list (line 49-53): Adds controllers/substrate.rs, the file that substrate/mod.rs became. The existing substrate/** entry stays. The new entry covers the same code and no more. - ARCHITECTURE.toml layer lists: Adds pplx-space-substrate to several store_users and coordinator lists. No entry was removed. The pplx-space-api entries stay (28 in both base and head). The new crate holds code moved out of pplx-space-api, so this follows the move. It is an allowlist addition in form, so a reviewer should confirm that the moved code needs each store. - CI and path lists: kind-direct-ci.yml and ci/kind-placement-paths.txt only add entries. No continue-on-error, || true, set +e, skip or xfail was added. No .config/nextest.toml, deny.toml, clippy.toml or guideline file changed. Nothing in the diff weakens a test, assertion, lint, CI check or repository guard without a reason or a move that keeps coverage.

Full details: Agent Tooling Runs No New Commands

Explanation

The check does not apply to this change. The PR's own commit, 325fe87 ("sbx-mgr: a drain pass's confirm answers by the call's deadline"), changes only three Rust files under crates/l40_api/sbx/mgr/server/src/service/drain_node/ (rpc.rs, tests.rs, producer_tests.rs). It touches no plugin manifest (plugin.json, plugin.yaml), no SKILL.md, no command or skill file, and no hook, MCP, or LSP configuration. The branch also contains f66f4cd (#2609), which the PR description says is the base of this head. That commit modifies crates/l40_api/api/src/controllers/substrate/AGENTS.md among many other files. Searching the added lines of the changed .md, .json, .yaml, and .yml files in both commits found no inline shell substitution (!...), no added frontmatter keys such as hooks or allowed-tools, and no mcpServers or lspServers entries. The .agents/plugins/pplx-space skill files appear in the local origin/main...HEAD diff. The local origin/main is stale, so that diff includes many commits outside this PR. They are not in the PR's commits, and the check is scoped to the PR's diff. No failure condition in the check is met.

Full details: External Code Sources Need A Person

Explanation

The check fails only if the diff adds or changes an external code source: a git/rev/branch/tag/registry key or an external path on a Cargo dependency, a container image reference, a downloaded binary's URL/version/checksum, or a Helm chart dependency from outside the repo. I found none of these. Base and diff scope: the local origin/main ref (22e9465) is stale. The PR description names main as 8aa7838, so I used 8aa7838 as the base. The PR's head is 325fe87. The range 8aa7838..HEAD has two commits: - 325fe87, the PR's own change. It touches only three Rust files under crates/l40_api/sbx/mgr/server/src/service/drain_node/ (rpc.rs, tests.rs, producer_tests.rs). It has no manifest, image, or download changes. - f66f4cd, "api: move the substrate core into pplx-space-substrate (#2609)". It is in the PR range and touches Cargo manifests. Cargo manifests: - The added dependency lines in crates/l40_api/api/Cargo.toml and crates/l40_api/substrate/core/Cargo.toml all use { workspace = true }, with only feature additions. These are workspace or internal crates, so they pass. - The root Cargo.toml did not change. - Cargo.lock gained no added or removed source = or checksum lines. Its changes are only new dependency-name entries for workspace crates and crates.io packages already in the lock. Images, downloads and charts: - No Dockerfile changed. No Chart.yaml or Chart.lock changed. - Added lines in the infra, CI, scripts and docs paths in the range contain no image, FROM, curl, wget, URL, checksum, digest, repository, or version keys. The Helm value and helper changes are comment or template-path edits in the kind charts. No finding in the explanation was matched against an explicit failure condition, so there is nothing to list by file and line.

Full details: Public-Safe Content

Explanation

The public-safe content check passes for PR #2663 (perplexityai/SPACE, head ac/drain-v2-confirm-finished-rows-deadline, base main). Diff: The PR commit 325fe8715 changes three sandbox-manager drain files: drain_node/producer_tests.rs, drain_node/rpc.rs, and drain_node/tests.rs. A scan of its 525 added lines found no private keys, tokens, or API secrets; no AWS ARNs or 12-digit account IDs; no internal hostnames, private IPs, or internal URLs; no personal workstation paths; and no incident, production-data, or vulnerability wording. The UUIDs and 00000000-... values are fixed test values. Out-of-scope hits: The branch also contains ip-10-0-0-51.ec2.internal and ip-10-0-0-52.ec2.internal in k8s_store_postgres_tests.rs. These come from earlier stacked commits, not this PR's commit. The base revision already has the same strings. They are not in the PR's own diff, so they do not fail this check. Description: The only links are public GitHub Actions run URLs in the same public repository, and they are not private trackers or chats. The description names no hostnames, clusters, or environments. It describes a timeout and locking issue, not an incident or an unfixed security vulnerability. Its AI attribution line ("Claude Code drafted…") has no link and holds no sensitive value. Title: "sbx-mgr: a drain pass's confirm answers by the call's deadline" contains nothing sensitive. Note: The PR's stated base commit 8aa7838 and the wider stack are present locally. The local origin/main has advanced past the PR base, so the 449-file merge-base diff is stack noise. The analysis above uses the PR commit alone.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! A SPACE maintainer will take a look.

CONTRIBUTING.md explains how we review outside contributions.

@github-actions github-actions Bot added the triage:pending Waiting for a maintainer to triage label Dec 2, 2026
@ac-pplx
ac-pplx force-pushed the ac/drain-v2-confirm-finished-rows-deadline branch from b8b775b to f8c3d01 Compare December 2, 2026 07:07
@ac-pplx ac-pplx added the kind-smoke Run the Kind/Firecracker smoke on this PR, whatever it changes, from its next push label Dec 2, 2026
A DrainNode pass confirms its finished rows under their artifact locks
on a blocking thread, in the caller's span, and the call awaits it under
its timeout: a stall in the confirm's read no longer holds the call past
`call_timeout`. A pass whose call ends there starts no action and keeps
its failures as they were, so the next call re-plans from the rows.

Cancellation is cooperative. The confirm asks before each row's lock,
inside its read (`read_plan_reads_while`) and before each row's
comparison; once its caller has gone it drops every lock at once and
confirms nothing, and a later answer doesn't resume it. Its locks
therefore outlive the call by at most the one step in progress: the
wait for the database connection and the scans, one upload job's
lookup, one row's files, or the in-memory work up to the next check.
The comparison finds each row's second read by id in constant time. The
locks still drop before the plan's work starts. When nothing is
abandoned the pass confirms the same rows, rechecks them with the same
reasons in the same order, and starts the same actions; the pass's
other reads still call `read_plan_reads`.

A full preview's confirm also asks before each row's lock, and its doc
states the same bound, plus the comparisons and seal reads that follow
its read's last check.

The stall test stalls the confirm's read inside the database while it
holds a finished row's lock: the call answers `DeadlineExceeded`, starts
and queues nothing, the read given up looks up no upload job, the lock
frees once the stall ends, and the next call confirms the row and starts
its upload. A unit test gives up the confirm at each of its checks in
turn and finds it stopped there with every lock free.

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

kind-smoke Run the Kind/Firecracker smoke on this PR, whatever it changes, from its next push triage:pending Waiting for a maintainer to triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant