Skip to content

SCA-367: feat(backend): one JIT flag + two-UID allowlist - #12369

Merged
Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-cursor-grok-4-6/2cd6a590
Aug 28, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-cursor-grok-4-6/2cd6a590

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Collapse backend JIT admission onto one PostHog exposure flag and a code-owned two-UID allowlist.

  • Single flag key: jit-processing-v1
  • Allowlist (always admitted, including when PostHog is down):
    • vi7SA9ckQCe4ccobWNxlbdcNdC23
    • 9OqYLlKJv4hmeYpIhwJcHBR975i2
  • Everyone else is off when the flag is false, absent, or unknown; flag true admits all users
  • These flags are no longer admission authority: jit-processing-kill-switch-v1, jit-processing-ledger-migration-v1, daily-memory-sweep-v1
  • Ledger migration, daily-sweep cohort, trigger/prompt/mirror snapshots, and first-open wiring all use permits_work from resolve_jit_rollout

SCA-367. Regular merge (never squash). Do not merge from this PR until review.

Product invariants affected

  • INV-MEM-4
  • INV-MEM-1

This PR only changes who is admitted to existing JIT helpers. It does not add a memory tier, change Short-term intake, or add a promotion fast-track.

Failure-Class: none

Test plan

  • backend/.venv/bin/python -m pytest backend/tests/unit/test_jit_rollout.py backend/tests/unit/test_jit_first_open_policy.py backend/tests/unit/test_jit_ledger_snapshot.py backend/tests/unit/test_canonical_short_term_maintenance_cron.py backend/tests/unit/test_frame_request_promotion_safety.py -q — 116 passed
  • backend/.venv/bin/python -m pytest backend/tests/unit/test_daily_memory_sweep_job.py -q — 8 passed; deployed sweep job uses permits_work
  • Allowlist UID is enabled when the flag is false / missing / timed out
  • Non-allowlist UID is disabled when the flag is false or absent
  • Non-allowlist UID is enabled when the flag is true
  • Non-allowlist UID is not enabled on provider timeout / malformed
  • Kill-switch / ledger-migration / daily-sweep flags no longer change admission
  • Did not mutate live PostHog, Firestore, or deploys

Review in cubic

Git-on-my-level and others added 2 commits August 29, 2026 04:37
Collapse processing, ledger, and sweep admission onto jit-processing-v1, keep David's two Firebase UIDs enabled even when PostHog is down, and treat a missing or false flag as off instead of unknown.

Co-authored-by: Cursor <[email protected]>
Co-authored-by: multica-agent <[email protected]>
Keep the sweep library free of jit_rollout so the hanging sweep suite is not selected, while the deployed job still uses permits_work.

Co-authored-by: Cursor <[email protected]>
Co-authored-by: multica-agent <[email protected]>
@mintlify

mintlify Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Aug 28, 2026, 10:56 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@Git-on-my-level
Git-on-my-level merged commit bc1ccef into main Aug 28, 2026
43 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m1-studio-cursor-grok-4-6/2cd6a590 branch August 28, 2026 23:14
Git-on-my-level added a commit that referenced this pull request Aug 29, 2026
…12381)

## What changed and why

The macOS desktop client never downloaded the JIT trigger snapshot for
admitted owners: `GET /v1/jit/trigger-snapshot` was gated on the client
**re-deriving admission** from the raw `rollout` + `kill_switch` pair
instead of consuming the server's own `effective` verdict from the same
`/v1/jit/rollout-decision` response. Live evidence (2026-08-29): Omi
Beta 12237 issued rollout-decision 200s against dev desktop-backend
`ecec0c281011` (contains the #12369 allowlist) with **zero**
trigger-snapshot reads in the same window, and the local DB for the
allowlisted owner had zero `jit_trigger_snapshot_receipts` rows.

- `JITProactivityFlags.permitsNewLane` now admits on `effective ==
.enabled` and fails closed on `.disabled`; the known-good rollout +
kill-switch pair remains the older-server fallback. A missing
`kill_switch` is wire compatibility, not an unknown-off veto; a present
`unknown` still fails closed.
- `fetchJITTriggerSnapshot` no longer lets the downstream
`KnowledgeLedgerMirrorCoordinator.sync` failure block the snapshot:
**mirror sync must not prevent the local trigger receipt**. A failing
mirror now fails itself closed (bounded, content-free error-class log)
and the complete snapshot still returns, so `JITTriggerMirror.reconcile`
(still `complete == true`-gated) writes the receipt. A complete empty
watchlist decodes via the snake_case keys and persists its receipt.
- Server allowlist untouched; no standing triggers created; no
PostHog/Firestore mutation. Owner comparison still binds to `owner_id`;
foreign-owner and undecodable bodies still fail closed.

## Product invariants affected

none

## How it was verified

- `xcrun swift test --package-path Desktop --filter
"JITProactivityPolicyTests|JITProactivityRuntimeTests|ProactiveLaneClientTests|JITTriggerMirrorTests|JITProactivityDeliveryTests"`
— 86 tests, 0 failures. This includes new wire-level URLProtocol tests
that drive the real `jitProactivityFlags` / `fetchJITTriggerSnapshot`
against the router's actual response shapes, and a runtime test proving
an effective-enabled authority reads the snapshot and persists the
empty-watchlist receipt.
- `./scripts/swift-format-wrapper.sh lint` clean on all changed files;
`./scripts/swiftlint-wrapper.sh lint` — 0 violations across 1444 files;
`python3 scripts/check_desktop_test_quality.py` — at baseline.
- Not verified locally: a live Beta rebuild against the dev backend (no
signed artifact rebuild in this task); the wire tests exercise the same
contract the dev desktop-backend emits.

## Tests

- `ProactiveLaneClientTests`: effective=enabled admits with unknown raw
flags; missing `kill_switch` + effective enabled admits; all-unknown and
present-unknown fail closed; complete empty snake_case watchlist decodes
and returns despite a throwing mirror sync (attempted exactly once);
disabled stub returns its content-free receipt without touching the
mirror; foreign-owner and garbage bodies fail closed.
- `JITProactivityPolicyTests`: effective-enabled admits over
non-admitting raw pairs; effective-disabled blocks an
otherwise-admitting pair; present-unknown kill switch without effective
still fails closed; absent kill switch with enabled rollout admits via
the fallback.
- `JITProactivityRuntimeTests`: effective-enabled authority with unknown
raw flags reads the trigger snapshot and persists the receipt into
`jit_trigger_snapshot_receipts`.

## Failure class (fixes)

Failure-Class: new

## Failure-class transition narrative

New class `FC-client-rederives-authority-verdict`
(`.github/failure-classes/FC-client-rederives-authority-verdict.json`,
added here with `evidence_prs: []` — this PR is the evidence). Violated
contract: a client consuming an authority's decision response must act
on the authority's verdict field, never re-derive a stricter verdict
from the raw inputs beside it — the divergence is silent (200s on the
decision read, no decode error, no failing test). Canonical guard: the
admission predicate points at `effective` (fail-closed on `.disabled`),
the raw pair is only an older-server fallback that distinguishes absent
from present-unknown `kill_switch`, and the truth table is covered by
wire-level tests plus a runtime receipt-persistence test. The Windows
client already parses and uses `effective` and was not affected.

## Scoped cleanups (optional)

none


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/12381?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
Git-on-my-level added a commit that referenced this pull request Aug 29, 2026
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 added a commit that referenced this pull request Aug 29, 2026
…list admission (#12388)

## 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(-)
```


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/12388?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

This branch was successfully deployed

1 active deployment
staging - docs — 5524d87f Deployed Aug 28, 2026 by mintlify[bot]
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