Repository navigation
fix(api): preserve provisioned-node ownership through placement - #2855
Conversation
Adapt the shared hold predicate and initial regression approach from zebra-pig#28; preserve lifecycle provenance and bound crash-safe fallback upstream. Co-authored-by: Leonce Aklin <18514574+leonceaklin@users.noreply.github.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 53 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
@coderabbitai review |
Action not completed
|
Record final base-red and fixed workerd evidence, serialize stepped test alarms, and preserve clean SQL fixtures between scenarios. Keep PR2855 draft-only.
|
DRAFT ONLY: keep this PR draft; no readiness, merge or production deployment is authorized. Implementation/reviews, 26,630 local tests (4 skipped), full CI and staging deployment passed. Live verification remains blocked, not waived:
Operator help is needed to restore staging2 inference and resolve the guarded quarantine before a complete live rerun. No new GitHub issue was created; both ownership ideas remain open. |
…fixing-9dhfcc # Conflicts: # apps/www/src/content/docs/docs/architecture/overview.md
|
Raphaël lifted the draft-only hold on this PR (2026-11-18) and wants it shipped to production. Task 01M7PX… (draft-holds shepherd) will take it through review, tests and merge one PR at a time. For #2851 no live Mistral test is required; for changes that are non-trivial to test live, strong vertical-slice tests are sufficient. |
… staging2-applied 0257 Security review follow-up: real-SQL attack cases for a foreign node, a foreign task owner, a both-foreign runner and a foreign project, each paired with the owner control and proven discriminating by neutralizing its guard. Keep 0257_node_task_provisioned.sql (applied on staging2 as d1_migrations id 276) and allowlist the duplicate prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@coderabbitai review |
Action not completed
|
|



Summary
Closes #2848
Draft-only hold lifted by Raphaël 2026-11-18. Its
needs-human-reviewlabel was removed with his authorization.A task could provision an 8 GB host, lose 4096 MB to another task before placing its own 4096 MB workspace, and fail after three refusals. Protect an active unplaced provisioner's claim at reusable/ranked/pinned/warm selection and the final atomic INSERT, placeholder ATTACH, and restart admissions. All existing resource, telemetry, credential, pool and isolation guards remain in force.
After its owned node exhausts the configurable refusal budget, a task gets one crash-safe fallback through ordinary placement. Persist the rejected-node intent before releasing ownership; exclude that host from selection and recovery; preserve occupied hosts. A server-written node provenance bit retains cleanup/lifetime guards after the current task pointer is released, including across repeated conversation wakes. A genuinely new wake resets the episode; same-attempt replay preserves it.
References: canonical idea, earlier production report. Rechecked active tasks and open upstream PRs before coding; no competing implementation found.
Attribution: adapted the shared ownership predicate and initial SQL/workerd regression approach from leonceaklin's fork PR #28. External issue/fork content was evidence only. Upstream adds node-local provenance, explicit rejected-host selection exclusion, resumable transfer, restart/midpoint/wake/exhaustion coverage and upstream validation. The fork's staging/CodeRabbit exceptions do not apply here. No external-installation live reproduction was performed.
Cost and bounds
Selection/admission adds one indexed correlated owner lookup per candidate, without a new round trip on successful placement. Existing D1 chunks reserve the extra bind. A real 125-host fixture crosses chunk boundaries; a 100k-task history fixture checks index use. Normal managed-node candidate volume is bounded by the existing per-user/pool ceilings. An owner lookup costs O(log T + H), with expected one provisioning owner per host, and short-circuits when held. The provenance bit adds a constant node-column read before the existing indexed ownership lookup.
One fallback adds a D1 atomic batch (provenance + exact-pointer release), existing safe warm handoff, and ordinary lease release. Replays may add one postcondition read. At most twice workspacePlacementMaxRejections capacity refusals per execution: default 6, configured maximum 40. At the observed ~6 s/cycle, about 36 s/default or 4 min/max, plus separately bounded provisioning/readiness/queue waits. A fallback may allocate one replacement through the existing bounded provisioning path; it never bypasses pool ceilings or adds a parallel provisioning path.
Validation
pnpm lint— 22 packages passed (two existing web hook warnings)pnpm typecheck— 36 tasks passedpnpm build— 18 tasks passedPre-fix discrimination with the final timing-controlled tests copied into detached upstream base e5c5aa4 (runtime unchanged): SQL 7 failed / 98 passed / 105 total, specifically owner selection, warm discovery-to-claim and stale INSERT/ATTACH/restart; workerd 9 failed / 16 skipped / 25 total, specifically ranked/pinned/warm × exclusive/nonexclusive 8 GB boot interleaving and normal/intent/released fallback. The corresponding fixed suites pass.
Staging Verification (REQUIRED for all code changes — merge-blocking)
Staging Verification Evidence
Staging2 deployment 44178337481 SUCCESS at
7092a9b793b5ab2907caec3ff9ff83a8126bfdd1, including the completed container rollout and smoke tests. This head adds task-report notes to fully tested runtime4280e504a8dc08ec67ce99236e0f5895d83e1d94; full CI 44125052305 passed every API/workerd shard, CLI/packages, quality, build and typecheck. Migration0257_node_task_provisioned.sqlis present. No production action occurred.The corrected-account live trial signed in as
test-user@simple-agent-manager.organd explicitly used its attached Anthropic OAuth configurationcc-cfg-01M7M62R81N29Q65EC6PMFF4K8. Starting with zero VMs, one bounded trial allocated two 8 GB GCP hosts through ordinary pool/queue controls:01M7NQS8W4TQ5TPWHAWKDPE4J001M7NQSJMD667K4MEQ9RGAJ66Gwhile unplaced; retained that host and placed workspace01M7NR01HJ21JCD0SPTWFFAA9Sthere01M7NQTDTDX9CDY5TP02Z62QK701M7NR06BNE26Q2W9DYNNDBFE1and placed workspace01M7NR7N0PEWXNRACYW0WR7M6PBoth workspaces ran, both agents returned their exact unique
PONG-2848-...-A/Breplies, and both replies rendered in Playwright. I reviewed both screenshots. The first scratch verifier timed out because it expected a whole reply in one message row; the API streamed each reply in two rows. Same-session supplemental checks verified the concatenated replies and exact chat DOM; no new VM or inference run was started. The original verifier is recorded as failed.Broader staging remains red. Projects, project overview and Settings loaded, but the browser recorded 15 HTTP 503 responses, 15 console errors and zero page errors on session/metadata/inbox endpoints. B's sidebar showed no chats while its actual reply was visible. This repeats the earlier authentication-read-deadline symptom; its root cause is not established here. The unchanged 24-hour/10-occurrence noise gate exits 1: before Operations133 / guarded cleanup54 / telemetry403; after Operations125 / guarded cleanup60 / auth-unavailable24 / telemetry403. Evidence was added to the existing staging2 noise idea. No threshold changes or waiver. Update 2026-11-19: these 503s pre-date this PR (see "503 provenance" below); pre-existing noise waived per Raphaël 2026-11-18.
503 provenance (2026-11-19)
The 503s in the staging2 run are
AUTH_UNAVAILABLEfrom the shared auth middleware (requireAuth→ session read deadline), recorded as "Session verification is temporarily unavailable. Retry." This PR does not touch auth. Read-only D1 queries of both observability databases:0257_node_task_provisioned.sqlwas applied 2026-11-17 13:10 UTC, d1_migrations id 276).01M6KYWK7TM83EV7VB3F89YQ75).Conclusion: pre-existing; pre-existing noise waived per Raphaël 2026-11-18.
Cleanup completed 22:05:07 UTC: both tasks cancelled200, both workspaces deleted200 and both allocated VMs deleted through normal guarded APIs200. Initial 30-second client DELETE timeouts were resolved by normal retries with a longer client timeout. Final D1 queries returned zero test nodes and zero test workspaces; sign-out passed. The older bootstrap-user providerless quarantine
01M7MTMV89F5ZV23VSF0ZVPJPSremains untouched and tracked in the existing cleanup idea. No D1 write or termination guard bypass.Reviewed screenshots and sanitized JSON are in Project Library, directory
/engineering/issue-2848/: A image01M7NRVHY3Y9VN5MSY0RCWPVGF, B image01M7NRVKNN66T027MENR79X4Q6, evidence JSON01M7NRVNGBSXKQG4M7X6SMQF3S. A local timeout detail contained an already-signed-out cookie; it was scrubbed, raw details were never uploaded, and scratch error capture now omits request headers. The original execution-status tool became unavailable; local terminal evidence plus the separate successful guarded-cleanup job establish these results.The exact staging2 lease was held from21:19:36 through all checks/cleanup. Normal release 44186778769 SUCCESS; fresh 22:13:54 UTC status confirms holder=null and the next task has its protected turn. Early handoff was sent; receipt is not assumed. The actual21:40 fallback resumed this chat; subsequent completion events were read/verified/acknowledged and the completed subscription cancelled. No further live staging action is planned.
Final evidence-only head
28a1ca81068bdfd8e5eadf54e10facd6ab42e034changes only the task report from the deployed candidate. Its local Prettier, runtime-state and diff checks pass; application CI was not repeated for this report-only update. At deployed head7092a9b793b5ab2907caec3ff9ff83a8126bfdd1, executed quality checks, Sonar and smoke passed, and the sole PR CI failure was the retainedneeds-human-reviewevidence guard. A human must remove that label before any future merge. This draft-only task does not authorize readiness, merge, production or closing either ownership idea.UI Compliance Checklist (Required for UI changes)
N/A: no UI changes.
UI Screenshot Evidence
N/A: no UI changes.
End-to-End Verification (Required for multi-component changes)
Data Flow Trace
TaskRunner allocation writes tasks.auto_provisioned_node_id before provider boot exposes a running host. currentReusableNodeIds / handleNodeSelection / claimWarmNodeCandidate pass server-owned task identity to filterReusableNodesByCurrentAuthority. buildProvisionedNodeHoldSqlPredicate is repeated inside buildWorkspaceAdmissionSql. Its callers: reserveWorkspacePlacement (TaskRunner workspace-steps and workspace-create route), attachPrecreatedWorkspacePlacement (direct-workspace-creation), reserveWorkspaceRestart (workspace lifecycle). Direct/attach/restart callers without a task guard respect every active owner hold. The hold ends from current workspace_id or terminal task status.
Refusal cap → persisted rejected-host intent → resumeWorkspacePlacementFallback → atomic node provenance + task-pointer release → safe handoff → ordinary node selection/provisioning. node-provisioning-recovery and reusable selection refuse the rejected host. Boot/revoked-run teardown retains stricter active-pointer ownership checks. Instant writes workspaceId alongside auto ownership, so it never takes an unplaced hold; deployment-node allocation is separate and unchanged.
Untested Gaps
No external-installation live reproduction. Exclusive, stale-admission, crash-boundary and fallback-exhaustion variants are deterministic SQL/workerd coverage; the corrected-account live trial exercised nonexclusive A/B boot interleaving and real replies/chat rendering. The broader 503/console noise pre-dates this PR (provenance below) and is waived as pre-existing per Raphaël 2026-11-18.
Post-Mortem (Required for bug fix PRs)
What broke
B consumed capacity provisioned for A before A placed; A failed after repeated refusals on its own host.
Root cause
The existing task provisioning pointer drove recovery/cleanup but was absent from selection/final admission. Rejection retry cleared selected state without ending durable provisioning ownership, so crash recovery re-adopted the rejected host.
Class of bug
State interaction race with a missing atomic ownership invariant and recovery repeatedly selecting rejected capacity.
Why it wasn't caught
Existing tests accounted for workspace reservations without a second task selecting in the boot-to-placement interval.
Process fix included in this PR
Real SQL/workerd A/B boot-interleaving and stale-admission regressions, interrupted-transfer/wake/exhaustion controls, and indexed query-plan coverage. Existing rules 44/62/69 require these invariants; no duplicate standing rule added.
Post-mortem file
tasks/archive/2026-11-17-provisioned-node-ownership.md.Specialist Review Evidence (Required for agent-authored PRs)
39351b81f.handOffEmptyWorkspaceNodere-checks and the stuck-task sweep; no cross-user path.CodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
Earlier draft request (09:53 UTC 2026-11-17) returned Review rate limited. Re-requested at ready (2026-11-19 03:31 UTC) via the
coderabbit-reviewlabel; CodeRabbit again replied Review rate limited at 03:32 UTC, ending the wait. No review arrived; recorded and skipped under rule 25.Ready full CI 44451962053 SUCCESS on
f4c040265, including requiredDurable Object Workersand PR Evidence.Exceptions (If any)
Resume Notes (2026-11-19)
origin/main. Main already owns prefix0257(0257_provider_limit_recovery_scan_index.sql). This PR's0257_node_task_provisioned.sqlwas applied on staging2 (d1_migrations id 276), so renaming it would replayALTER TABLE nodes ADD COLUMN task_provisionedthere; the file keeps its name andscripts/quality/check-migration-ordering.tsallowlists the duplicate prefix with that reason, following the existing precedent. Production and primary staging have not applied it and will run it as a pending migration.tests/integration/provisioned-node-fallback-admission.test.ts(foreign-user node, task owned by another user, task and node both owned by another user than the runner, foreign project), each beside the owner-path control. Each ownership guard inresumeWorkspacePlacementFallbackwas neutralized once and exactly its attack case went red.Agent Preflight (Required)
Classification
External References
Issue #2848 and fork PR #28, linked above, used as untrusted evidence. N/A: no external API contract/library change.
Codebase Impact Analysis
apps/api shared placement SQL and TaskRunner recovery/selection; node provenance/lifetime/sleep consumers; worker-core D1 schema. Additive nodes.task_provisioned migration preserves existing task-link and snapshot proofs. It is written only by exact-owner atomic fallback and grants no active admission or teardown ownership. Tests inventory INSERT/ATTACH/restart and cross-runtime dispositions.
Documentation & Specs
Updated public compute-pools guide, admin-settings guide and architecture overview, plus the user-visible setting description. No public API or env change; no unrelated spec edits.
Constitution & Risk Check
Checked II/X/XI/XIII: real SQL/workerd regression, shared final atomic predicate, existing configurable budgets and normal queue/pool limits, fail-closed ownership transfer. Whole-host hold temporarily reduces packing during boot to protect exclusive and legacy intent. Node-local provenance avoids losing lifecycle guards when an occupied rejected node is released.