Skip to content

Harden the admission gate after the production cutover - #207

Merged
artempartos merged 2 commits into
developfrom
fix/admission-schema-window
Sep 5, 2026
Merged

artempartos merged 2 commits into
developfrom
fix/admission-schema-window

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

Summary

Three things the production cutover surfaced. All were found by running the change against a real cluster, not by reading it.

1. New code can serve before its schema arrives

Production runs aixle-app-web:main with imagePullPolicy: Always. The tag is mutable, so new code starts serving when the image is pushed, not when the deploy job runs — and DB Migrate runs just before Deploy. On 2026-09-05 that gap was 24 minutes:

Build Web      18:49:22   <- image pushed
Backend Checks 19:04 -> 19:13:50
DB Migrate     19:13:52
Deploy         19:14:15
errors         19:10:02 -> 19:13:35   <- inside the gap

A worker pod rescheduled in that window (spot, autoscaling — they move constantly) ran new code against the old schema. Five sessions died with PG::UndefinedTable: relation "session_admission_policies" does not exist, because the admission gate sits on the container-create path.

A missing policy table is not an ambiguous answer — the queue cannot be on if its policy does not exist — so the gate now says no and the legacy path serves. Narrowed to that one question; every other database error still raises.

This also protects the follow-up that drops namespace_resource_quotas, where the same window runs in reverse.

2. The legacy-quota removal could never have run

remove_managed_session_quota refused all 62 objects with "Namespace is not a managed session scope" no matter how correctly they were labelled:

KEYS [Symbol] -> [:"aixle.com/runtime-origin", ...]
STRING_LOOKUP nil
SYMBOL_LOOKUP "aixle-prod"

Kubeclient returns labels as a RecursiveOpenStruct, so #to_h gives symbol keys and every guard clause read them with string keys. The dry run is what caught it, which is what the dry run is for.

There was no test at all for that method. There are three now, built on a real Kubeclient::Resource — a plain Hash stand-in reads fine with string keys and hides exactly this. Verified that they fail without the fix, with the same message production gave.

3. Sessions that never started were never reaped

The stale sweeper asked about running, ready and finishing — never not_started. A launch lost between the database commit and Temporal therefore sat untouched forever. Production had 47 of them, the oldest since March, 45 from a single day, none carrying an error to explain itself:

WF_ID_NIL 47   STARTED_AT_NIL 47   WITH_ERROR 0

That is the failure the queue's durable launch intent exists to prevent, but the legacy path still needs a floor. The scope needed its own branch too — these sessions have no started_at, so the shared branch would have matched nothing. Queued sessions stay exempt: waiting for a slot is not staleness.

Type of change

  • Bug fix
  • Breaking change

How was this tested?

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

Six tests added. The quota-guard ones were checked against the un-fixed code and reproduce the production error exactly.

Checklist

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

artempartos and others added 2 commits September 5, 2026 22:50
…agree

Production runs a mutable image tag with pullPolicy Always, so new code starts
serving when the image is pushed, not when the deploy job runs — and migrations
run just before that job. A pod rescheduled in the gap executes new code against
the old schema. On 2026-09-05 that gap was 24 minutes and cost five sessions:
the admission gate sits on the container-create path, so a table it could not
read failed the launch outright.

A missing policy table is not an ambiguous answer — the queue cannot be on if
its policy does not exist — so the gate says no and the legacy path serves.
Narrowed to that one question; every other database error still raises.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
… never started

Two things the cutover found in production.

The legacy-quota removal could never have run. Kubeclient returns labels as a
RecursiveOpenStruct, so #to_h gives symbol keys, and every guard clause read
them with string keys — silently nil, so "Namespace is not a managed session
scope" fired for all 62 objects regardless of how correctly they were labelled.
The dry run is what caught it, which is what the dry run is for. There was no
test at all for that method; there are three now, built on a real
Kubeclient::Resource, because a plain Hash stand-in reads fine with string keys
and hides exactly this.

The stale sweeper never asked about `not_started`. It swept running, ready and
finishing, so a launch lost between the database commit and Temporal sat
untouched — production had 47 of them, the oldest since March, none carrying an
error to explain itself. The scope needed its own branch too: these sessions
have no started_at, so the default branch would have matched nothing. Queued
sessions stay exempt — waiting for a slot is not staleness.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos merged commit b2be5cc 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