Skip to content

fix(backend): complete empty JIT snapshot when admitted owner has no memory head - #12391

Merged
Git-on-my-level merged 1 commit into
mainfrom
sca-372-empty-jit-snapshot
Aug 29, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
sca-372-empty-jit-snapshot

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Admitted JIT trigger snapshot must be complete even with no memory head

Problem

Desktop Beta (0.12.241 / 12241) on the dev data plane: GET /v1/jit/rollout-decision returns 200 and the client treats the lane as on, but GET /v1/jit/trigger-snapshot returns a 748B incomplete envelope and the local jit_trigger_snapshot_receipts table stays at 0 rows.

Dev Firestore has no memory_state/head for these dogfood accounts (Beta Auth is prod, the data plane for this API is dev). read_authoritative_trigger_snapshot treated the missing head as generation_unavailable → complete=false, empty ids, default policy. The Swift client JITTriggerMirror.reconcile discards incomplete snapshots on purpose (requires complete == true and non-empty snapshotRevision), so an admitted user could fetch the snapshot but never persist a receipt — dev Beta can never exercise the JIT lane.

Change

When the rollout admits work (permits_work) and the memory_state/head document is proven absent (MISSING_STATE_HEAD — the query ran and the doc does not exist), read_authoritative_trigger_snapshot now returns a complete empty watchlist instead of the incomplete generation_unavailable stub:

  • complete=true, rows=[], failure_reason=null
  • owner_id = authenticated uid
  • account_generation=0, commit_sequence=0, head_commit_id=""
  • snapshot_revision = deterministic sha256 of empty-watchlist:{uid}:0 (64 hex, stable across serves)

Certification discipline is preserved:

  • Absence is fenced by a trailing head re-read (same discipline as the row-scan authority_changed fence): if a head appeared mid-read, the snapshot stays incomplete (generation_unavailable) and the client picks up the real snapshot on the next poll.
  • Unproven absence — read failure, malformed/unsupported/mismatched head — keeps the existing incomplete generation_unavailable receipt. No fake complete.
  • No trigger rows are invented; no row scan runs without a head.
  • Non-admitted owners keep the existing rollout_not_enabled incomplete stub (router gating unchanged).
  • The generation fence stays monotonic: when a real head later appears at a higher account_generation, Swift reconcile treats it as a new authority epoch and accepts it.

Verified against the Swift client contract (JITTriggerMirror.reconcile): headCommitID is decoded as a plain String and never validated for emptiness; acceptance requires complete, matching non-empty ownerID, non-empty snapshotRevision, accountGeneration >= 0, commitSequence >= 0, and a valid policy — all satisfied. Same (generation, sequence, revision) on repeated syncs is idempotent (no conflictingRevision).

Tests

  • New: admitted uid with missing head → complete empty snapshot, deterministic non-empty revision, no failure_reason, trailing re-read fence observed (head_reads == 2)
  • New: revision is stable across serves and owner-bound
  • New: head appearing between the two head reads → still incomplete generation_unavailable (no certification of a torn absence)
  • New: unreadable head (read raises) → still incomplete generation_unavailable
  • Existing suites green: test_jit_trigger_snapshot.py (16), test_jit_rollout.py (34, incl. rollout_not_enabled stub), test_jit_first_open_policy.py + test_jit_ledger_snapshot.py (52), test_jit_proactivity_store.py + test_jit_proactivity_eval.py (26)

Failure-Class: new

Adds FC-proven-empty-rendered-as-denial — the mirror of FC-denial-rendered-as-empty-success: a proven-empty authoritative state (the head query ran and the document is absent) was served as an indeterminate incomplete receipt that correctness-gated clients must discard, so a legitimately empty account could never persist its snapshot receipt. Guard artifact: the reader plus its behavioral tests.

Product invariants affected

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

Unblocks SCA-372 (dev Beta dogfood: allowlisted users can GET the snapshot but cannot persist a receipt).

Review in cubic

…memory head

An admitted owner whose memory_state/head is proven absent (never
initialized memory v3) now gets a complete, empty watchlist with a
deterministic revision instead of an incomplete
generation_unavailable receipt. Desktop Beta reconciles only complete
snapshots, so dogfood accounts on dev Firestore (no head, no
generation) could GET the snapshot but never persist a receipt.

Absence is still certified only after it is proven: a trailing
head re-read must still show the head missing, and unproven absence
(read failure, malformed head) keeps the incomplete receipt. The
generation fence stays monotonic: when a real head later appears at a
higher account_generation, reconcile treats it as a new authority
epoch. Non-admitted owners keep the rollout_not_enabled stub.

Verified against Swift JITTriggerMirror.reconcile: head_commit_id is
never validated (empty string is stored as-is); complete=true,
non-empty snapshot_revision, owner match, and generation/sequence >= 0
are the acceptance preconditions.

Co-authored-by: multica-agent <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 487b9fb into main Aug 29, 2026
42 checks passed
@Git-on-my-level
Git-on-my-level deleted the sca-372-empty-jit-snapshot branch August 29, 2026 16:51
Git-on-my-level added a commit that referenced this pull request Aug 31, 2026
## What changed and why

Bind JIT admission on every GCP `dev` evaluator (GKE listen, Cloud Run
listen, maintenance), then make first-open, ledger writes,
empty-watchlist suppress, drain, and public-docs hygiene correct before
flipping `jit-processing-v1` to 100% of Omi Beta / TestFlight.
Empty-extraction 500s already landed in #12410. Production `api.omi.me`
PostHog is unchanged.

## Product invariants affected

- INV-AGENT-*
- INV-DATA-1
- INV-MEM-1
- INV-MEM-4
- INV-TASK-2

## How it was verified

- `backend/.venv/bin/python -m pytest
backend/tests/unit/test_backend_runtime_env_validator.py
backend/tests/unit/test_conversation_jit_processing.py
backend/tests/unit/test_first_open_effect_resume.py` — 131 passed after
rebase onto `origin/main`.
- `python3 .github/scripts/check_agent_doc_references.py` and
`check_agents_md_lean.py` — OK.
- `python3 backend/deploy/compose_runtime_env.py` — generated
`runtime_env.yaml` matches overlays (dev TZ recon on, prod off).
- Did not deploy to GCP `dev` or flip PostHog in this PR. After merge:
probe a non-allowlist Beta UID, then operators flip `jit-processing-v1`
to 100% on the **dev** PostHog project only. Keep the two-UID allowlist
until soak.

## Tests

- Runtime-env compose requires PostHog +
`OMI_FIRESTORE_DATA_PLANE_PROJECT` on listen/maintenance.
- `force_process=True` still defers folders/apps when rollout admits;
`bypass_jit_first_open` is the explicit reprocess hatch.
- Empty folders initialize then assign; first-open never
`complete('folder_assignment')` on a skip.
- Ledger writes use the data-plane client; unknown preference slots stay
unslotted.
- macOS/Windows: complete empty watchlist suppresses; incomplete
snapshot consumes the visit; Insight stays gated.
- Cron skips `writer_mode=ledger` dreaming; sweep continues after one
unknown slot.

## Failure class (fixes)

Failure-Class: FC-rollout-flag-absent-from-a-cohost-of-its-code-path

Enabling `jit-processing-v1` while GKE/Cloud Run listen and maintenance
lacked `POSTHOG_PROJECT_API_KEY` (and GKE listen lacked the data-plane
overlay) would have produced two behaviours for the same UID: Cloud Run
chat/sync admitted, listen finalized as `configuration_missing`.

## Test plan

After merge, deploy this PR to GCP `dev`. Probe a **non-allowlist** Beta
UID:

1. `GET /v1/jit/rollout-decision` on desktop-backend and Cloud Run
`backend` → same `effective=enabled` once the flag is on for that UID
(PostHog override before 100% is fine).
2. Live-finalize via GKE listen: logs are not `configuration_missing`;
first-open attaches.
3. Kill-switch drill on **dev** PostHog, including allowlist, then off.
4. Chat `create_standing_trigger` appears on Mac **and** Windows
snapshots.
5. Empty ledger: no ambient nano/full; Windows does not run Insight.
6. Empty extraction conversation is 200.

Then flip `jit-processing-v1` to 100% on the **dev** PostHog project.
Watch writer_mode drain; do not claim extraction is off until `ledger`
is the majority. Keep the two-UID allowlist until soak.

Windows TestFlight floor is builds that include #12381 / #12391 /
#12397; older apps keep the legacy loop and cannot be remotely disabled.

## Line-count exceptions

Oversized files grew by the JIT admission/sweep patches; splitting them
is out of scope for this Beta-readiness PR.

Line-Count-Exception: backend/routers/conversations.py | 1955 -> 1956 |
pass bypass_jit_first_open through create/finalize without splitting the
router
Line-Count-Exception:
backend/utils/conversations/process_conversation.py | 2561 -> 2572 | add
bypass_jit_first_open so force_process stays a lazy-desktop hatch, not a
JIT bypass
Line-Count-Exception: backend/utils/memory/canonical_memory_adapter.py |
3491 -> 3496 | keep empty replace_conversation_source a no-op after
#12410 rebase
Line-Count-Exception: backend/utils/memory/daily_memory_sweep.py | 4994
-> 5008 | unknown-slot ValueError skips that candidate instead of
aborting the day
Line-Count-Exception: backend/utils/sync/pipeline.py | 2527 -> 2528 |
reprocess path sets bypass_jit_first_open


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/12452?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. -->
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