Skip to content

test: pin the GET/delete and double-delete workload lifecycle races (#445) - #549

Merged
pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/445-workload-races
Oct 19, 2026
Merged

pdettori merged 1 commit into
rossoctl:mainfrom
pdettori:fix/445-workload-races

Conversation

@pdettori

Copy link
Copy Markdown
Member

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 /workloads implementation (check-then-act saveWorkload writes, a GET that wrote back). The rewrite replaced that with:

The pins

  • a GET in the delete window reports deleting, writes nothing, and cannot resurrect it — holds a DELETE at Context Service, asserts GET reports deleting, 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 with 404.
  • 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 answer 204, 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 RESERVE and rollback leaves a creating record holding the name and one quota unit; the remedy is the owner's DELETE (which handles creating). A record TTL would not fix this safely — expiry without the deleted transition leaks the quota unit permanently.

Closes #445; also resolves the "GET write-back race on /workloads" item of #363.

🤖 Generated with Claude Code

… 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 ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 match activateWorkload/createUpload's status === 'deleted' guards.
  • Double delete: the second DELETE reads deleting, skips the first CAS, deletes the Context and lands deleted. The first then gets 404 from CS (treated as deleted), loses the final CAS, re-reads a deleted record 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.

Comment thread docs/context-service.md
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — "with no other transitions" overstates it. The code also takes these edges:

  • creating → deleted and creating → deleting (rollbackCreate, workloads.ts, depending on whether the Context delete succeeded)
  • creating/awaiting_upload/ready → deleting (deleteWorkload transitions from whatever status the record has, and the comment above it calls out creating)
  • deleted → creating by re-create (RESERVE overwrites a deleted record 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pdettori
pdettori merged commit db68a75 into rossoctl:main Oct 19, 2026
15 checks passed
pdettori added a commit that referenced this pull request Oct 20, 2026
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make workload activation and deletion state transitions concurrency-safe

2 participants