Repository navigation
🤖 fix: refuse child creation under a workspace being removed across backends - #4908
Conversation
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b6d58bcb49
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ed0343a94
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…cendants after the removal claim; drop empty-identity markers
…ly when preparation found it
9ed0343 to
9631419
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96314191c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Readiness record
Generated with |
…coder#4919) ## Summary The cross-process removal fence (coder#4776/coder#4908) now covers upgraded workspaces whose config row has no id yet. A removal persists the legacy row's id before it claims its `pendingRemoval` marker. A task creation whose parent resolved only through session metadata finds that row again by its stable identity (config project key + workspace path) inside its config commit. If the row is gone or marked, the commit refuses. Fixes coder#4914 ## Background Every step of the fence found the row by id: `claimPendingRemoval` wrote no marker when `findWorkspaceEntry` missed, `Config.removeWorkspace` did not deregister the row, and `assertParentAdmitsChild` could not see a marker or the row's absence (coder#4908 exempted id-less parents so that creation under them kept working). So another backend could create a child under such a workspace while it was being removed, or after it was removed. ## Implementation - **Removal** (`WorkspaceService.removeUnlocked`, after the mutation gate and before the marker claim): if the row is not found by id but `Config.findWorkspace` resolves it (a legacy row), it calls `Config.getWorkspaceMetadataById`, which persists the read-time id migration that workspace listing already persists. Then the claim, the release and the deregistration find the row by id as usual. If the row still has no id (the best-effort migration write failed), the removal refuses before any effect: it could not be fenced. This is the fail-closed choice. - **Task creation** (`createMany` plans and both `create` commits): when the parent row has no id in the preparation snapshot, the plan records `LegacyParentRow` from `Config.findWorkspace`. `assertParentAdmitsChild` falls back to the id-less row at that path and requires a row by id or by path, so a removed legacy parent refuses the child the same way a removed parent with an id does. A parent that resolves nowhere (e.g. the existing "no config row by id" test that fakes a parent id) keeps today's behavior. Scope stayed small (3 files); no new persisted fields: `LegacyParentRow` is an in-memory plan field. ## Validation New tests in `workspaceService.pendingRemoval.test.ts` (two backends, real service stacks, a real id-less row with its id in `sessions/<basename>/metadata.json`) fail on `origin/main` and pass with this change: ``` (fail) workspace removal across two backends on one root > a removal marks a legacy id-less row, so the other backend refuses a child under it (fail) workspace removal across two backends on one root > a batch creation under a legacy id-less parent refuses once the other backend removed it Expected to contain: "removed" Received: "created" ``` Each production hunk has its own red test: without the removal change the first test fails (no marker on the row), and without the task-creation change the second fails (the batch commits under the removed parent). A third test checks that a batch creation under a live legacy parent still commits. ## Risks Low. The new paths run only for rows without an id, which the read-time migration normally fixes at the first workspace listing. The removal of such a row now performs that migration write first, and refuses if the write fails. --- _Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_ <!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high costs= -->
Summary
This PR finishes the cross-process removal work tracked in #4782: the other backend can no longer create a child task under a workspace that is being removed (or was removed), a removal now checks for descendants after it claims its marker, and a removal marker with an empty identity field is dropped at load instead of blocking the workspace. Item 1 (a send into a live attempt) is already closed by the use leases and mutation gate that landed in #4861 and #4866; see below.
Fixes #4782
Background
#4776 added the durable
pendingRemovalmarker. The issue lists what it left open:pendingRemovalread and start a turn while backend A commits the marker and deletes the checkout.removeUnlockedchecked for descendants before its claim, and no task-creation config write looked at the parent's marker, so B could commitTaskService.createunder a parent that A was removing and leave an orphaned child row (and possibly an unmanaged checkout).PendingRemovalSchemaaccepted empty identity strings.parseProcessIdentity()turns""intonull, andjudgeHolder()on Linux then treats the holder as an unknown PID domain that never dies, so such a marker blocked admission and removal until someone edited config.json.Implementation
assertParentAdmitsChildruns inside every task-creation config write (commitReservationsforcreateMany, and both the queued and the direct write increate). It refuses while the parent row carriespendingRemoval.createalso refuses when the parent row it found by id during preparation is gone at write time (the direct path materializes a checkout in between, so a whole removal can fit in that gap).createManydoes the same with the parent row it found by id when it revalidated the reservation (its checkpoint callback runs before the commit, so a whole removal can fit there too). A parent that was not found by id (an upgraded, id-less row that resolves only through its session metadata) is not required.removeUnlockednow checks for descendants afterclaimPendingRemovalinstead of before the gate. Config writes are serialized, so either the child's write sees the marker and refuses, or the removal's post-claim read sees the child and refuses (itsfinallyreleases the marker, as for any other refusal after the claim). A refused direct create rolls its checkout back through the existing launch-failure path.PendingRemovalSchemaarez.string().min(1).nullable(), sonormalizePersistedWorkspacedrops such a marker as malformed.removeUnlockedtakes the structural mutation gate before it claims the marker and holds it until removal settles (🤖 feat: structural workspace mutations refuse while another backend uses the workspace #4866), and every turn holds aturnuse lease from preparation and confirms it before the provider starts (🤖 feat: turns and terminals hold cross-process workspace use leases #4861). By the Dekker ordering inworkspaceUseLeases.ts, either B's turn sees A's gate and fails as a settled preparation failure, or A's lease scan sees B's turn and the removal refuses before any effect. This also covers a turn B started before A's claim. Covered byagentSession.useLease.test.ts("B's send while A's mutation runs fails as a settled preparation failure", "a turn in B holds its lease from preparation until it settles") andworkspaceService.mutationGate.test.ts(other-backend leases refuse rename and remove before any effect).unarchiveuse lease from before its commit to the end, and a snapshot-restoring unarchive takes the mutation gate. Either one refuses while a removal holds the gate, and a removal refuses while the unarchive holds its lease.Out of scope
The removal marker and this fence find the row by id. An upgraded workspace whose config row is still id-less gets no marker (as before this PR), so creation under it is not fenced; tracked in #4914.
Validation
New tests in
workspaceService.pendingRemoval.test.ts(two backends on one root) fail onorigin/main(25faf8f1c4):Review round 1 added a test that a batch creation under a parent resolved only through metadata (legacy, no config row by id) still commits; it failed on the first PR head
b6d58bcb49(parent workspace legacy-parent was removed).Review round 2 added a test that a batch creation refuses when the other backend finished removing the parent during the reservation checkpoint; it failed on
9ed0343a94(Received: "created").Before the fix, B's
createunder the parent being removed succeeded, A's removal deleted a parent whose child had been committed just before its claim, and the empty-identity marker refused the reawaken. With the fix all pass, and so do everytaskService*/workspaceService*unit test file (1851 tests) and the 21 test files that mentionpendingRemoval,createManyor descendant checks (935 tests).Risks
Low to medium.
createandcreateManynow refuse when the parent row they found by id is missing at write time; before, such a child was written as an orphan. A removal of a workspace with descendants now takes the gate and briefly claims its marker before it refuses (the marker is released in the same call), so another backend's task admission can see a short refusal during that window.Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:high