Skip to content

Stop an unresolved operation from blocking its own cleanup - #215

Merged
artempartos merged 1 commit into
developfrom
fix/cleanup-blocked-by-unresolved-operation
Sep 5, 2026
Merged

artempartos merged 1 commit into
developfrom
fix/cleanup-blocked-by-unresolved-operation

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

What production showed

A cancelled session's Pod was still 1/1 Running 109 minutes after its workflow closed, with the reservation still held:

SESS 10290       cancelled, finished 22:06:29
WORKFLOW         status=CANCELED, closed 20:41:51
POD              terminal-bfd6e8c1...  1/1 Running, AGE 109m
OCCUPIED_BY_POOL {"project:27" => 20}     <- pool at its cap

The reservation was held correctly — there was a real container consuming real cluster resources, and AD-6 says capacity is not returned while the workload is confirmed present. The bug is that nothing was deleting it.

The deadlock

Two different prohibitions had been collapsed into one. AD-5 says an operation nobody can prove landed must not release the slot: a late create must never find its seat given away. Cleanup enforced that by refusing to do anything at all:

if admission.session_runtime_operations.where(state: %w[in_flight uncertain]).exists?
  raise SessionAdmissionService::UncertainOperation, "..."   # before any deletion
end

So:

exec stuck in_flight
  -> cleanup raises before reaching the runtime
  -> Pod never deleted
  -> absence never provable, operation never resolves
  -> slot held forever, container runs forever

The guard protecting the capacity accounting prevented the cleanup that would have made the accounting true.

The fix

Deleting the runtime is separate from releasing the reservation. The stop marker is already set by the time cleanup runs, so no new attempt can start; the delete goes ahead, and only the release waits for an operator.

If a late create does land, it reappears under the same stable identity, session_absent? stays false and the retry loop keeps holding the slot — self-correcting, which refusing to delete never was.

Reconciliation stops skipping the wedged ones. It excluded admissions with unresolved operations from its scan, which is exactly how this one stayed invisible for hours. They are examined like any other now.

A closed workflow's in_flight operation is relabelled uncertain. in_flight means "a create is running right now", which is only true while something is running it. Once the workflow is closed nothing can ever report that result — and in_flight reads as ordinary provisioning load in the health line, so a fully pinned slot showed uncertain_operations: 0 for 108 minutes. uncertain is the number an operator is alerted on.

Type of change

  • Bug fix
  • Breaking change

How was this tested?

docker compose exec -T web make check_all — green in full.

Four tests, each pinned to a claim rather than to the implementation: an unresolved operation now deletes but does not release; it still never releases even once the runtime is gone; a closed workflow strands its in-flight operation into uncertain and that reaches the health snapshot; a wedged admission is examined rather than skipped, and its runtime is deleted.

The existing test that asserted the old "refuses everything" behaviour was rewritten rather than deleted — the invariant it guarded (never release) still holds and is still checked.

Checklist

  • I read CONTRIBUTING.md.
  • All commits are signed off for the DCO.
  • make check_all passes locally.
  • Added/updated tests.
  • Updated documentation.
  • Commits use descriptive messages.

…s own cleanup

Found in production: a cancelled session's Pod was still Running 109 minutes
after its workflow closed, and the reservation was still held.

The two prohibitions were tangled. AD-5 says an operation nobody can prove
landed must not release the slot — a late create must never find its seat given
away. Cleanup enforced that by refusing to do anything at all, which deadlocked:
the workload kept the slot honestly occupied, and the operation could never
resolve because the deletion that would have made absence provable was the thing
being refused.

Deleting the runtime is now separate from releasing the reservation. The stop
marker is already set by then, so no new attempt can start; the delete goes
ahead, and only the release waits for an operator. If a late create does land,
it reappears under the same stable identity, absence stays false and the loop
holds the slot — self-correcting, which refusing to delete never was.

Reconciliation also used to skip these admissions entirely, which is how one
stayed invisible for hours. It examines them like any other now, and relabels a
closed workflow's `in_flight` operation as `uncertain`: nothing can report that
result any more, and `in_flight` reads as ordinary provisioning load in the
health line, so a pinned slot never reached the number an operator watches.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit 80e6aa9 into develop Sep 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant