Skip to content

fix(backend): fail keyword privacy cleanup open when Typesense is unconfigured - #23063

Closed
Git-on-my-level wants to merge 2 commits into
mainfrom
fix/errfix-1021-gcp-canonical-memory-adapter-py-3382-run
Closed

Git-on-my-level wants to merge 2 commits into
mainfrom
fix/errfix-1021-gcp-canonical-memory-adapter-py-3382-run

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Error group

{"source": "gcp", "service": "backend", "group": "canonical_memory_adapter.py:3382 | RuntimeError: canonical keyword privacy cleanup unavailable", "count": 21, "id": "gcp:backend-canonical-memory-adapter-py-3382-runtimeerror-canonical-keyword-privacy-cleanup-unavailable", "fingerprint": "fp:69e6e793be40c3f3"}

Root cause

_run_immediate_privacy_cleanup (backend/utils/memory/canonical_memory_adapter.py:3382) raises
RuntimeError: canonical keyword privacy cleanup unavailable whenever delete_atom_keyword_doc
returns False. That helper constructs the shared Typesense client lazily from
TYPESENSE_HOST/TYPESENSE_API_KEY; on a deployment where those env vars are absent or empty
(this repo's deploy matrix produces such deployments — e.g. gcp_notifications_job.yml
explicitly strips TYPESENSE_HOST/TYPESENSE_HOST_PORT/TYPESENSE_API_KEY, and the backend
workflows bind vars.TYPESENSE_HOST, which renders empty when unset), client construction
raises, the generic except swallows it, and the delete returns False. Privacy cleanup then
fails closed forever on a projection that deployment never writes, so every explicit memory
delete / privacy purge on that deployment raises.

This is the keyword-projection recurrence of
FC-privacy-delete-fails-on-unprovisioned-derived-store: #15097 gave the vector-store sibling
(delete_canonical_memory_vectors, called one line above) the "unconfigured store = trivially
confirmed absence" classification, but the Typesense keyword delete never got it — the module
even defines typesense_configured() without using it on this path.

Fix

delete_atom_keyword_doc (backend/utils/memory/atom_keyword_index.py) now classifies
"Typesense not configured" as the trivially-confirmed desired absence: log and return True
before any client I/O, mirroring the #15097 vector-store fix. A configured client that raises
still fails closed (returns False → RuntimeError → durable outbox retries), and the empty
uid/memory_id input check still returns False.

All callers treat the return value as "the projection converged to absence", which is
trivially true when the projection is never provisioned:
_run_immediate_privacy_cleanup (this error group), sync_atom_keyword_index_for_item, and
short_term_promotion._delete_atom_projection_and_citations.

Verification

$ python3 -m py_compile backend/utils/memory/atom_keyword_index.py backend/tests/unit/test_ws_m_atom_keyword_index.py
PY_COMPILE_OK

$ python3 -m pytest tests/unit/test_ws_m_atom_keyword_index.py -q
47 passed in 2.51s
(includes new regression test test_delete_confirms_absence_when_typesense_unconfigured,
selected alone: 1 passed)

$ python3 -m pytest tests/unit/test_ws_j_delete_privacy.py -q
62 passed in 0.92s

The regression test deletes TYPESENSE_HOST/TYPESENSE_API_KEY and stubs the client handle
to raise if constructed, asserting the delete confirms absence — per the failure class's
canonical prevention (stub the handle to its unconfigured state, don't remove it).

Product invariants affected

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

Neither invariant is violated: the keyword projection stays a non-authoritative projection,
and this change only converges it to absence on deployments that never write it; no restricted
content is sent to any provider.

Failure-Class: FC-privacy-delete-fails-on-unprovisioned-derived-store

View guided diff Turn on auto-fix

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T20:29:46.540171Z d88a443 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4114fe6731

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Git-on-my-level added a commit that referenced this pull request Oct 21, 2026
…ypesense

Review repair for #23063: delete_atom_keyword_doc confirmed absence whenever
typesense_configured() was False, i.e. also when exactly one of
TYPESENSE_HOST/TYPESENSE_API_KEY was bound. A partial binding does not prove
the projection absent — backend-listen binds only TYPESENSE_HOST while
backend-sync and memory-maintenance-job hold both against the same cluster —
so a rollout losing one variable would acknowledge the privacy deletion with
plaintext keyword documents still stored. Confirm absence only when neither
binding is present (Cloud Run backend, desktop), let partial bindings fail
closed through the client call, and instrument the fail-open with
record_fallback(reason=unconfigured, outcome=recovered) per the fallback
telemetry contract.
…onfigured

delete_atom_keyword_doc returned False whenever the shared Typesense env was
absent or empty (lazy client construction raises, the generic except swallows
it), so _run_immediate_privacy_cleanup raised 'canonical keyword privacy
cleanup unavailable' and every explicit memory delete failed closed on
deployments that never write the keyword projection — the keyword recurrence
of FC-privacy-delete-fails-on-unprovisioned-derived-store (#15097 classified
the vector-store sibling but not this one). Classify the unconfigured state as
the trivially-confirmed desired absence before any client I/O; a configured
client that raises still fails closed, and empty uid/memory_id still returns
False.

Failure-Class: FC-privacy-delete-fails-on-unprovisioned-derived-store
…ypesense

Review repair for #23063: delete_atom_keyword_doc confirmed absence whenever
typesense_configured() was False, i.e. also when exactly one of
TYPESENSE_HOST/TYPESENSE_API_KEY was bound. A partial binding does not prove
the projection absent — backend-listen binds only TYPESENSE_HOST while
backend-sync and memory-maintenance-job hold both against the same cluster —
so a rollout losing one variable would acknowledge the privacy deletion with
plaintext keyword documents still stored. Confirm absence only when neither
binding is present (Cloud Run backend, desktop), let partial bindings fail
closed through the client call, and instrument the fail-open with
record_fallback(reason=unconfigured, outcome=recovered) per the fallback
telemetry contract.
@Git-on-my-level
Git-on-my-level force-pushed the fix/errfix-1021-gcp-canonical-memory-adapter-py-3382-run branch from bf1005d to d88a443 Compare October 21, 2026 20:25
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Review repair pushed for both Codex threads on delete_atom_keyword_doc (commit d88a443):

  • Instrument the fail-open branch — the unconfigured fast path now calls record_fallback(component="other", from_mode="atom_keyword_delete", to_mode="confirmed_absence", reason="unconfigured", outcome="recovered") so privacy-delete fail-opens are visible to the shared fallback metric, not just the warning log. Thread resolved.
  • Fail closed when missing config does not prove absence — the trivially-confirmed path is now scoped to neither TYPESENSE_HOST nor TYPESENSE_API_KEY being bound (the durably-unprovisioned deployments: Cloud Run backend, desktop). A partial binding (exactly one var — e.g. backend-listen holds only TYPESENSE_HOST while backend-sync / memory-maintenance-job hold both against the same cluster) no longer confirms absence; it falls through to the client call and fails closed. Added parametrized regression tests for each partial-binding case. Thread resolved.

Verification: tests/unit/test_ws_m_atom_keyword_index.py (49 passed, incl. 2 new partial-binding cases + fallback-metric assertion) and tests/unit/test_ws_j_delete_privacy.py (62 passed) via the repo runner; full pre-push gate passed with the PR body; CI on d88a443 is green (33 pass / 25 skip / 0 fail). Rebases the PR onto current origin/main (056c302).

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Autonomous repair exhausted (review failed 3x (timeout)); 0 fixup rounds, attempt 3/3. PR left OPEN for human triage.\n\nLast findings excerpt:\nreview failed 3x (timeout)

1 similar comment
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Autonomous repair exhausted (review failed 3x (timeout)); 0 fixup rounds, attempt 3/3. PR left OPEN for human triage.\n\nLast findings excerpt:\nreview failed 3x (timeout)

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Folded into #24602 (the consolidation of this batch onto the age-gate survivor branch lane/freshtitles-agegate, head e2e0767). Survivor #24580 merged separately at 11:59Z without the batch folds, so #24602 carries this PR's changes on top of current main for review. Every behavior change from this PR is preserved in the fold; conflicts were reconciled against main's newer contracts (details in #24602's description). Closing as folded — follow #24602.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Hey @Git-on-my-level 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Git-on-my-level added a commit that referenced this pull request Nov 4, 2026
… the age-gate survivor branch (#24602)

* fix(memory): retry transient store faults on canonical apply control read

A transient Firestore fault on the apply-control read was converted
straight into CanonicalApplyStateUnavailable (memory_system.py:64),
failing the whole apply gate for one blip. _read_snapshot now gives
store faults classified transient by transient_store_error the same
three-attempt backoff budget as the MCP OAuth refresh rotation before
failing closed; permanent faults and exhausted retries keep the
existing fail-closed behavior.

Failure-Class: none

* fix(memory): bound each retry attempt and recheck the deletion fence; add emulator proof

Review feedback on the canonical apply-control transient retry:

- Each attempt now disables the SDK's own (default 300s deadline) retry and
  passes an explicit per-attempt timeout (CANONICAL_APPLY_READ_TIMEOUT_SECONDS,
  default 5s), mirroring the MCP OAuth refresh-rotation boundary that owns its
  three-attempt budget. An exhausted SDK Retry policy would raise RetryError,
  which the transient classifier does not treat as retryable, so the typed
  error must surface at this boundary directly.
- The deletion fence is re-read before the first-write provisioning path: a
  wipe that completes while the retry loop waits can no longer re-enroll a
  wiped account as a fresh generation-1 control document.
- New Firestore-emulator proof (canonical_apply_control_retry_emulator_test.py)
  wired into run-emulator-proofs.sh: fault injection at the client API layer
  proves transient recovery, exhausted fail-closed (3 bounded attempts), the
  deletion race, and that every retried read passes retry=None plus a bounded
  timeout. Hermetic fakes updated to accept the new get() kwargs.

* fix(tests): shared Firestore fakes accept the retry/timeout read kwargs

The apply-control boundary now passes retry=None and a bounded timeout on
every document read; the shared canonical_memory_fakes._DocRef and the
WS-B _Document fake rejected those kwargs, and the resulting TypeError was
swallowed by the production except-Exception fail-closed path, failing 34
tests across five unit shards. Mirror the real SDK get() signature.

* fix(tests): remaining per-file Firestore fakes accept retry/timeout read kwargs

Same fix as the shared fakes for the two per-file fakes CI rounds reach:
canonical_consolidation_apply._FakeDocumentRef and the ws_j_delete_privacy
_DocRef. The apply-control read boundary passes retry=None plus a bounded
timeout on every document read; rejecting those kwargs fails closed through
the swallowed TypeError path.

* fix(memory): recheck fence before existing-state return; bound fence reads; one budget per control read

Review round 2 on the apply-control retry boundary:

- The post-retry deletion-fence recheck now also guards the existing-state
  branch (it previously ran only on the first-write path), so a deletion that
  starts during transient backoff cannot admit work or touch the maintenance
  registry under a running/completed wipe.
- The fence helper threads through optional retry/timeout read kwargs via an
  UNSET sentinel (other callers keep the SDK-default read), and the
  apply-control boundary passes its bounded per-attempt policy to every fence
  read, so the added safety check cannot pin a worker for the default 300 s.
- The exists-branch validates the recovered snapshot directly instead of
  re-reading the control document with a second fresh three-attempt budget;
  the create-race path likewise reads once and validates from that snapshot.
- Emulator proof: module-scope import per the backend import rule; fence stub
  accepts the new read kwargs.

* fix(memory): give fence reads the same transient budget; module-scope test imports

Review round 3:

- With the SDK retry disabled for the bounded fence read, a single transient
  blip on account_deletions/{uid} would fail the whole apply gate — the very
  failure mode this PR fixes. Both fence reads now run through the same
  three-attempt transient budget as the control read (one shared helper).
- Hoist the three retry tests' imports to module scope per the backend
  import rule.

* fix(backend): fail keyword privacy cleanup open when Typesense is unconfigured

delete_atom_keyword_doc returned False whenever the shared Typesense env was
absent or empty (lazy client construction raises, the generic except swallows
it), so _run_immediate_privacy_cleanup raised 'canonical keyword privacy
cleanup unavailable' and every explicit memory delete failed closed on
deployments that never write the keyword projection — the keyword recurrence
of FC-privacy-delete-fails-on-unprovisioned-derived-store (#15097 classified
the vector-store sibling but not this one). Classify the unconfigured state as
the trivially-confirmed desired absence before any client I/O; a configured
client that raises still fails closed, and empty uid/memory_id still returns
False.

Failure-Class: FC-privacy-delete-fails-on-unprovisioned-derived-store

* fix(backend): scope keyword privacy fail-open to fully-unconfigured Typesense

Review repair for #23063: delete_atom_keyword_doc confirmed absence whenever
typesense_configured() was False, i.e. also when exactly one of
TYPESENSE_HOST/TYPESENSE_API_KEY was bound. A partial binding does not prove
the projection absent — backend-listen binds only TYPESENSE_HOST while
backend-sync and memory-maintenance-job hold both against the same cluster —
so a rollout losing one variable would acknowledge the privacy deletion with
plaintext keyword documents still stored. Confirm absence only when neither
binding is present (Cloud Run backend, desktop), let partial bindings fail
closed through the client call, and instrument the fail-open with
record_fallback(reason=unconfigured, outcome=recovered) per the fallback
telemetry contract.

* feat(memory): stale-planner archive restore operator tool (2026-10-22)

Dry-run-first operator tool re-applying incident-archived memory_items as
short_term-visible decisions through the canonical apply ledger
(apply_long_term_patch_firestore) with the remediation=stale-planner-2026-10-22
audit marker, reversible via --revert. Per-user COLLECTION-scope scan with
read budget, keyset cursor, legal-hold/deletion-gate/deleted-user exclusions,
and payload-free count-only output. Registers the two memory_items query
drivers and regenerates the composite-index manifest. Prod writes remain
gated on the plan's explicit GO.

Co-Authored-By: GLM-5.3 <[email protected]>

* fix(conversations): require relevance decisions on terminal rows

Close decision gaps in dead-letter, orphan, BYOK, imports, external text, sync promotion, merge rollback, and legacy restore paths. Preserve calendar, photo, wake-word, rule-keep, and tombstone protections; keep mandatory decisions through terminal size guards.

Failure-Class: FC-contentless-recovery-surfaced-visible

* refactor(conversations): extract terminal storage and relevance labels

Keep the large conversation modules below their existing line budgets by moving snapshot status storage, deferred retry storage, pure terminal payload serialization, and bounded metric vocabulary to their owning modules. Migrate callers and behavioral/static coverage together.

Failure-Class: FC-contentless-recovery-surfaced-visible

* fix(conversations): stamp local fixture capture decisions

Cover the direct batch fixture writer with an explicit fixture-seed policy and bounded telemetry vocabulary. Preserve the local/offline account fence and extract the payload builder to keep its owner below the existing line budget.

Failure-Class: FC-contentless-recovery-surfaced-visible

* fix(conversations): refresh terminal visibility after commit

Invalidate people-stats and refresh search after terminal discards or document-ceiling failures commit. Isolate observer failures and publish no effects on aborted transactions. Document terminal relevance and size behavior in the lifecycle owner guide.

Failure-Class: FC-contentless-recovery-surfaced-visible

* fix(conversations): preserve positive evidence during terminal repair

* fix(conversations): retain recovery provenance when repairing keeps

* fix(conversations): preserve terminal verdicts and bound calendar probes

* fix(conversations): satisfy type checker on terminal decision sites

Narrow prior decision before subscripting, return str-keyed entries from
the preserve path, and expose a public accessor for the post-write search
index convergence instead of touching the private name.

* test: allowlist structural first-test CPU in terminal-decision suites

* test: allowlist the 70-minute narration fixture's first-test CPU

* fix(conversations): compose terminal decisions with wave-2 lifecycle

* style: pin the pinned formatter on test_recovery_rule_skip

* test(sync): align frozen parity with mandatory intake decisions

* fix(memory): invalidate projections on every committed retry

* Reconcile fold interactions with current main contracts

- finalization jobs: thread calendar_probe through the shared dead-letter helper
- sync intake: stamp explicit keep provenance only on newly created rows;
  replays retain their assessed verdict and promotions keep clearing the
  receipt (main's replay/promotion contracts)
- decision triggers: accept main's capture_group trigger
- parity fixture: re-pin frozen sources to the merged live files with a
  documented expectation update
- folded PR tests: point at the recovery module that now owns orphan
  completion, match current helper arities, RULES_VERSION, and the
  real-clock fence liveness window

* Restore origin/main's enrichment recovery emulator script

The refresh merge kept the survivor lineage's real-monotonic clock lines
without the import time that went with them, so the proof died on
NameError: time at line 111. The fold stack does not intentionally
change this script; take origin/main's blob wholesale. No retry or lease
behavior changes.

* Fix CI-red fold interactions against current main contracts

- lifecycle state table: the blocked_byok stock dwell alert is agent tier
  (omi-finalization-byok-dwell-info) since #24595 moved the page to fresh
  cohort dwell; re-point the inventory row and declare the folded writer
  moves (recover_deferred_processing_failure_txn and the dead-letter title
  helpers now live in conversation_terminal_title)
- crash-window orphans: an absent transcript is not evidence the user said
  nothing, so the orphan terminal recovery paths stage the path's policy
  keep as a prior verdict; dead_letter and BYOK abandonment keep their
  calendar-protected rule assessment of content-free audio
- run-emulator-proofs: drop the daily-sweep entry (main retired that proof)
- strict firestore fixture: model the canonical apply control read's
  retry kwarg, and default its per-attempt timeout to the modeled 3s bound
- folded tests: match the folded terminal receipt (replay exhaustion) and
  keep the size-rollover fixtures stamp-agnostic

* Classify the crash-window keep flag in the firestore query driver

* chore: retrigger PR workflows after a missed synchronize event

* Match the folded dead-letter keep receipt in the exhausted-requeue test

* Keep transcription-failed episode members in the home member projection

The size-ceiling terminal's failed-status visibility exclusion is a
conversation-list contract; the episode member surface renders a failed
member with its 'Couldn't transcribe' wire status so the user keeps the
bounded recovery exit. Exempt that surface from the exclusion instead of
weakening the shared predicate.

* Declare the diarization eval lifecycle writers in the site inventory

#24583 landed utils/stt/diarization_eval.py with seven lifecycle write
sites but no inventory entry; declare the reviewed sites so the writer
guard matches the real payload writes.

---------

Co-authored-by: David Zheng <[email protected]>
Co-authored-by: GLM-5.3 <[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