Repository navigation
test: pin the GET/delete and double-delete workload lifecycle races (#445) - #549
Conversation
… closed with The workload lifecycle rewrite already answers rossoctl#445: every record write is the TRANSITION Lua compare-and-set on (generation, status), GET is read-only, activation and upload grants refuse a deleted record, and a delete Context Service failed midway stays `deleting` for a retry. Pin the two races the rewrite's tests did not yet cover: a GET inside the delete window reports `deleting`, leaves the stored record byte-identical (the rossoctl#363 write-back race), and cannot resurrect the deleted workload; and two concurrent DELETEs converge on one `deleted` record, one Context deletion and one quota release. Both pins were checked to fail against a mutated handler. Also enumerate the allowed state transitions in docs/context-service.md. Closes rossoctl#445 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Tests and docs only (2 files, +59/−0). I traced both new tests through deleteWorkload at 30b1671:
- GET/delete window: holding the CS delete leaves the record in
deleting. The raw-key comparison is a real check on #363's write-back, and the 404s afterwards matchactivateWorkload/createUpload'sstatus === 'deleted'guards. - Double delete: the second DELETE reads
deleting, skips the first CAS, deletes the Context and landsdeleted. The first then gets 404 from CS (treated as deleted), loses the final CAS, re-reads adeletedrecord with the same generation and returns 204. That's the convergence path, and removing the re-read would make the first answer 409.
Two non-blocking suggestions. The new docs paragraph says the state machine has "no other transitions", but the code also has create-rollback, delete-from-any-status and re-reserve edges. And quotaOf(alice) === 0 can't detect a double release, because DECR is clamped at 0. CI is green, the commit is signed off, and there's no .claude//.vscode/ change.
| Context Service fails, the workload stays `deleting` and a repeated `DELETE` retries. | ||
|
|
||
| A workload record moves through a fixed state machine — `creating` → `awaiting_upload` → `ready` → | ||
| `deleting` → `deleted`, with no other transitions — and every record write is a compare-and-set on |
There was a problem hiding this comment.
suggestion — "with no other transitions" overstates it. The code also takes these edges:
creating → deletedandcreating → deleting(rollbackCreate, workloads.ts, depending on whether the Context delete succeeded)creating/awaiting_upload/ready → deleting(deleteWorkloadtransitions from whatever status the record has, and the comment above it calls outcreating)deleted → creatingby re-create (RESERVEoverwrites adeletedrecord before its TTL)
A reader who checks the code against this sentence will find it wrong. Suggest listing the edges, e.g. "creating → awaiting_upload → ready; any non-deleted status → deleting → deleted (a failed create goes straight to deleted, or to deleting if its Context could not be removed); a deleted name may be reserved again".
| status: 'deleted', | ||
| }); | ||
| expect(cs.contexts.size).toBe(0); | ||
| expect(await quotaOf(alice)).toBe(0); |
There was a problem hiding this comment.
suggestion — this assertion can't catch a double quota release. TRANSITION only DECRs while the counter is > 0, so with one workload a second release clamps at 0 and the test still passes. The test name promises "one quota release". To pin that, create a second workload for alice first (quota 2) and expect 1 here. Separately, the PR body says "one Context deletion", but both deletes reach Context Service: the second deletes the Context and the first gets the fake's 404 once released. If that's the intended behaviour, expect(cs.calls.filter((c) => c.method === 'DELETE')).toHaveLength(2) would pin it too.
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
What
fix #445. The workload lifecycle rewrite (#482 and follow-ups) already answers it; this PR pins the two races its tests did not yet cover, documents the state machine, and closes the issue.Why
#445 was filed against the pre-phase-1
/workloadsimplementation (check-then-actsaveWorkloadwrites, a GET that wrote back). The rewrite replaced that with:TRANSITIONLua script compares and sets on(generation, status);RESERVEmakes the name-and-quota reservation one atomic op (POST /workloads: concurrent create of one new name can hand the owner to the later writer #356).creating → awaiting_upload → ready → deleting → deleted, no other transitions; now enumerated indocs/context-service.md.404.deletingis retryable,deleteContexttreats 404 as deleted, and a delete that lost the final CAS to its own concurrent twin reports success.The pins
a GET in the delete window reports deleting, writes nothing, and cannot resurrect it— holds a DELETE at Context Service, asserts GET reportsdeleting, that the raw Redis record is byte-identical across the GET (the MI1 S1 follow-up: #350 round-3 review items (SH_MODEL_HEADERS, Vertex ADC, GET write-back race, pins, doc fixes) #363 scenario), and that the completed delete answers activation and upload grants with404.two deletes racing converge on one deleted record and one quota release— a second DELETE arriving while the first is held at Context Service finishes the same delete; both answer204, one Context deletion, quota released once.Both were mutation-checked: each test fails against a handler with the convergence re-read removed, and against a GET that writes back. No sleeps — the existing
cs.hold()determinism machinery drives both.Out of scope, recorded for honesty: a create whose process dies between
RESERVEand rollback leaves acreatingrecord holding the name and one quota unit; the remedy is the owner'sDELETE(which handlescreating). A record TTL would not fix this safely — expiry without thedeletedtransition leaks the quota unit permanently.Closes #445; also resolves the "GET write-back race on
/workloads" item of #363.🤖 Generated with Claude Code