Skip to content

fix(session-admission): reconcile a workflow Temporal has no record of - #224

Merged
artempartos merged 1 commit into
developfrom
fix/reconciler-unknown-workflow
Sep 9, 2026
Merged

artempartos merged 1 commit into
developfrom
fix/reconciler-unknown-workflow

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

What was wrong

Production project 27 had a cap of 20 and was running 4 sessions. Nine were queued, the oldest for 38 minutes. Sixteen reservations were occupied with no Pod behind them:

SNAP  {enabled: true, paused: false, queued: 9, occupied: 20, pools_with_queue: 1,
       oldest_queue_wait_seconds: 2307, uncertain_operations: 16}
OCCUPIED {"project:27" => 20}
$ kubectl -n aixle-prod-project-27 get pods   # 4 pods, all Running

Twelve of them carried the same last_error, rewritten once a minute:

Reconciliation: Temporalio::Error::RPCError: workflow not found for ID: agent-session-10290

SessionAdmissionReconciler.run describes the container workflow to decide whether a reservation is still live. Any exception was swallowed into last_error, so Temporal's NOT_FOUND — a definitive answer that no such execution exists — was treated exactly like an unreachable server: the admission was skipped, cleanup never ran, release! was never called. adm=19 had been holding a slot since 2026-09-05.

The fix

execution_open? distinguishes the one negative answer that is not a transport failure:

  • NOT_FOUND — the server looked and has no such execution (launch never reached Temporal, or retention expired). Nothing can ever report a result for it, so it reconciles as closed and proceeds to cleanup + release.
  • every other RPCError — still propagates, still recorded, reservation retained. Cleaning up behind a workflow we merely cannot reach would race its own cleanup (AD-5).

Tests

Two new tests in session_admission_recovery_test.rb, both mirroring the production shape (cancelled session, acknowledged launch state, an uncertain exec operation, runtime provably absent):

  • a workflow Temporal has no record of releases its reservation — fails without the fix (an execution that does not exist can never report a result)
  • a workflow that is merely unreachable keeps its reservation (UNAVAILABLE leaves it held, error recorded)

make check_all green: rails-test, rubocop, brakeman, system-test, eslint, typescript, fsd, fe-test, vite-build.

Note on production

Prod is still on pre-#216 code, where release! refuses on any unresolved operation rather than only a materializing one — which is why an uncertain exec pins a slot there. Both this fix and #216 need to reach prod for those 16 slots to come back; with them deployed the next reconciler pass releases all 16 on its own, no manual DB surgery.

🤖 Generated with Claude Code

Temporal answers NOT_FOUND when it has no such execution — the launch
never reached the server, or retention expired. The reconciler read that
as "unknown", skipped the admission, and wrote the same error to
last_error every minute, so the reservation was never cleaned up and its
slot never came back.

Production evidence: twelve reservations in one project held slots for
four days with "RPCError: workflow not found for ID"; a cap of twenty
was running four sessions. No Pod existed for any of them.

NOT_FOUND is the one negative answer that is not a transport failure, so
it now reconciles as closed. Every other RPC error still propagates —
cleaning up behind a workflow we merely cannot reach would race its own
cleanup (AD-5).

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
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