Skip to content

feat(backend): restore the JIT kill switch as an authority over allowlist admission - #12388

Merged
Git-on-my-level merged 1 commit into
mainfrom
feat/jit-kill-switch-restore
Aug 29, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
feat/jit-kill-switch-restore

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

What changed and why

PR #12369 collapsed JIT admission in backend/utils/jit_rollout.py to one exposure flag (jit-processing-v1) plus a code-owned two-UID allowlist that bypasses PostHog entirely. In doing so it retired jit-processing-kill-switch-v1: _allowlisted_decision and _effective_decision hardcoded kill_switch=TriState.DISABLED, and the provider never read the kill flag at all. That left no way to stop JIT processing for the allowlisted UIDs if something went wrong with them specifically — the one thing an operational kill switch exists for.

Ratified product policy (decision 17) requires a real, separate operational kill switch that works even for the allowlist. This restores it.

PostHogJITFlagProvider already fetches every decided flag for a UID in one get_feature_variants call, so both jit-processing-v1 and jit-processing-kill-switch-v1 are now parsed out of that same response — no second network call, same bounded executor/timeout/caching discipline as before. The allowlist no longer skips the provider outright: it still bypasses the exposure flag, but the kill switch is now consulted for allowlisted UIDs too, since it's the only thing that can revoke their admission.

Review fixup: an earlier version of this PR read an absent kill-switch key as UNKNOWN. PostHog's decide response omits a boolean flag entirely when it evaluates false for the distinct ID, so a 0%-rollout kill switch — its normal, healthy steady state — is legitimately absent from a well-formed response, not a present false. Reading that as UNKNOWN would have permanently downgraded every steady-state decision to the short negative-cache TTL (~4x the normal control-plane call rate) and reported a false "unknown" kill switch on the wire even though nothing was wrong. Fixed: when the response itself is well-formed, an absent kill key now reads as DISABLED. UNKNOWN stays reserved for a kill key that is present with a non-bool value, and for the existing whole-response failure paths (timeout/error/malformed mapping).

Semantics

Caller Rollout Kill switch Effective Reason
allowlisted (ignored) ENABLED DISABLED KILL_SWITCH_ENABLED
allowlisted (ignored) UNKNOWN (present, malformed) / provider down ENABLED ROLLOUT_ENABLED
allowlisted (ignored) absent from a well-formed response → DISABLED ENABLED ROLLOUT_ENABLED
regular ENABLED ENABLED DISABLED KILL_SWITCH_ENABLED
regular ENABLED UNKNOWN / DISABLED (incl. absent → DISABLED) ENABLED ROLLOUT_ENABLED
regular DISABLED / UNKNOWN any non-ENABLED DISABLED / UNKNOWN unchanged (fail closed)

The kill switch can only ever remove authority, never grant it. An UNKNOWN or absent kill switch never blocks by itself, so:

  • the allowlist's existing PostHog-down resilience is unchanged (it still admits when the provider is unreachable, unconfigured, or the kill key is simply unset), and
  • non-allowlisted users still fall back to the exposure flag exactly as before.

Caching is unchanged in shape: a definitively known kill switch (ENABLED, or DISABLED — including "absent from a well-formed response") caches for the normal decision TTL; an UNKNOWN kill switch (present-but-malformed, or a whole-response failure — like an UNKNOWN rollout) uses the existing short negative-cache window. No new cache layers, and steady-state (kill key simply unset) keeps the full TTL rather than being silently downgraded.

The JITRolloutDecision.kill_switch field (already part of the wire shape the desktop DTO decodes) now reports the real observed state (ENABLED / DISABLED / UNKNOWN) instead of a hardcoded DISABLED — downstream consumers that already branch on it (routers/jit_ledger_snapshot.py's _disabled_snapshot, utils/retrieval/frame_request_authority.py) get correct behavior for free.

Module docstring and the "retired admission keys" comment are updated: the kill switch is live authority again; jit-processing-ledger-migration-v1 and daily-memory-sweep-v1 remain retired.

Tests

Extended backend/tests/unit/test_jit_rollout.py (46 tests, all passing):

  • allowlisted + kill ENABLED → permits_work=False, reason KILL_SWITCH_ENABLED
  • allowlisted + provider timeout/down (including a simulated dead control-loop for the sync path) → permits_work=True (resilience unchanged)
  • allowlisted + kill UNKNOWN → permits_work=True
  • regular + rollout ENABLED + kill ENABLED → False
  • regular + rollout ENABLED + kill UNKNOWN/DISABLED → True
  • regular + rollout DISABLED/UNKNOWN → False (unchanged, existing test)
  • resolve_jit_rollout_sync (the sweep/first-open path) inherits the same kill-switch authority as the async path
  • New (review fixup): kill key absent from a well-formed response → kill_switch=DISABLED, full cache TTL, both allowlisted and regular UIDs unaffected (test_kill_switch_absent_from_a_well_formed_response_means_disabled_and_full_cache_ttl)
  • New (review fixup): kill key present with a non-bool value → UNKNOWN, short cache TTL, still never blocks either UID class (test_kill_switch_present_but_malformed_stays_unknown_with_short_cache_ttl_and_never_blocks)
  • Updated the two pre-existing tests whose assertions baked in "the kill flag never authorizes work" (test_posthog_provider_parses_only_the_exposure_flag → ..._parses_the_exposure_and_kill_switch_flags, test_retired_flags_do_not_change_admission → split into test_ledger_migration_and_daily_sweep_flags_do_not_change_admission + test_kill_switch_flag_revokes_admission_even_when_rollout_is_enabled) to assert the new contract instead: the kill switch can only ever remove authority, never grant it.

Verification run (from the worktree, backend/)

$ export ENCRYPTION_SECRET=... OPENAI_API_KEY=test-openai-key-not-real
$ .venv/bin/python -m pytest tests/unit/test_jit_rollout.py -q
46 passed, 17 warnings in ~3.7s

Also ran the directly-related consumer/mocking test files to check for regressions:

$ .venv/bin/python -m pytest tests/unit/test_jit_rollout.py tests/unit/test_jit_ledger_snapshot.py \
    tests/unit/test_jit_first_open_policy.py tests/unit/test_frame_request_promotion_safety.py \
    tests/unit/test_daily_memory_sweep_job.py tests/unit/test_jit_qa_orchestrated_dogfood.py \
    tests/unit/test_agent_tools_isolation.py -q
137 passed

(An earlier run of this same set hit one pre-existing, order-dependent flake in test_memories_archive_and_read_contracts.py, reproduced identically on unmodified origin/main — unrelated to this change; it did not recur on this re-run.)

Type check (focused, both touched files plus direct downstream readers of decision.kill_switch):

$ uv tool run --python 3.11 --from pyright pyright -p pyrightconfig.json --pythonpath .venv/bin/python \
    utils/jit_rollout.py utils/retrieval/frame_request_authority.py routers/jit_rollout.py routers/jit_ledger_snapshot.py
0 errors, 5 warnings, 0 informations

(All 5 warnings are pre-existing reportUnknownVariableType notes unrelated to this diff — confirmed identical against unmodified origin/main.)

Format check:

$ uv tool run --python 3.11 black --line-length 120 --skip-string-normalization --check --diff utils/jit_rollout.py tests/unit/test_jit_rollout.py
All done! ✨ 🍰 ✨
2 files would be left unchanged.

The repo's pre-push gate also ran its own bounded backend-unit-test selection (auto-detected test_jit_rollout.py from the diff, 46 passed) and the optional formatters check on every push — both passed, including after the amended fixup commit (head f7f3ebad13).

I did not attempt a full-repo test.sh --all run: the changed-file selector flags utils/jit_rollout.py as broad enough to warrant a full ~995-file run, but collecting that many files in one non-file-isolated pytest session segfaults on this machine — a pre-existing, documented hazard in test.sh itself (native-library re-registration under xdist), unrelated to this change. The proper file-isolated full run is CI's job; the focused + directly-related test set above is what's practical to run locally in this environment.

Diffstat

backend/tests/unit/test_jit_rollout.py | 228 +++++++++++++++++++++++++++++++--
backend/utils/jit_rollout.py           | 149 ++++++++++++++-------
2 files changed, 323 insertions(+), 54 deletions(-)

Review in cubic

PR #12369 collapsed JIT admission to the exposure flag plus a code-owned
allowlist, retiring jit-processing-kill-switch-v1 and hardcoding
kill_switch=DISABLED so it could never block anyone -- including the
allowlist. Product decision 17 requires a real operational kill switch
that works even for the allowlist.

PostHogJITFlagProvider now parses both jit-processing-v1 and
jit-processing-kill-switch-v1 out of the single get_feature_variants
response it already fetches (no second network call). The allowlist no
longer skips the provider outright: it still bypasses the exposure flag,
but a definitively ENABLED kill switch now revokes admission for
everyone, including allowlisted UIDs. An UNKNOWN or absent kill switch
never blocks by itself, so the allowlist's PostHog-down resilience and
the non-allowlist fail-closed exposure-flag behavior are unchanged. The
kill switch can only ever remove authority, never grant it.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Git-on-my-level
Git-on-my-level force-pushed the feat/jit-kill-switch-restore branch from db5ebf0 to f7f3eba Compare August 29, 2026 15:45
@Git-on-my-level
Git-on-my-level marked this pull request as ready for review August 29, 2026 16:04
@Git-on-my-level
Git-on-my-level merged commit 1a76a28 into main Aug 29, 2026
42 checks passed
@Git-on-my-level
Git-on-my-level deleted the feat/jit-kill-switch-restore branch August 29, 2026 16:05
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