Repository navigation
fix(memory): retry transient store faults on canonical apply control read - #22025
Git-on-my-level wants to merge 6 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a16ad63eb5
ℹ️ 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".
…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
… 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.
a16ad63 to
5b23b42
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b23b424a3
ℹ️ 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".
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.
…ead 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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f7dd96293
ℹ️ 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".
…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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3bb1bed4e
ℹ️ 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".
… 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.
|
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) |
|
Monitor run — review-thread closure verification for All 9 outstanding Codex review threads were re-audited against the current diff and verified as genuinely addressed by the pushed fix commits, then resolved:
No new code changes were needed this run. Verified locally: targeted runner pass on |
|
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) |
3 similar comments
|
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) |
|
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) |
|
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) |
|
errfix finisher: this PR has been open >3 days without merging — escalating to a human. |
There was a problem hiding this comment.
1 issue found across 10 files
Confidence score: 4/5
- In
canonical_apply_control_retry_emulator_test.py, Scenario 3 wipes data after the retried read returns, so it doesn’t test deletion during the retry window. Inject the wipe from the transient-failure hook instead.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/scripts/canonical_apply_control_retry_emulator_test.py">
<violation number="1" location="backend/scripts/canonical_apply_control_retry_emulator_test.py:208">
P2: Scenario 3 does not actually exercise a deletion during the retry window: the wipe is injected by the post-read fence callback, after the retried read has returned. Inject the wipe from the transient-failure hook (or synchronize it with the backoff) and assert that the fault and retry both occurred before claiming this race is covered.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| def wiping_fence_reader(uid_arg: str, *, db_client: Any = None, **_kwargs: Any) -> Any: | ||
| calls = getattr(wiping_fence_reader, "calls", 0) | ||
| wiping_fence_reader.calls = calls + 1 # type: ignore[attr-defined] | ||
| if calls > 0: |
There was a problem hiding this comment.
P2: Scenario 3 does not actually exercise a deletion during the retry window: the wipe is injected by the post-read fence callback, after the retried read has returned. Inject the wipe from the transient-failure hook (or synchronize it with the backoff) and assert that the fault and retry both occurred before claiming this race is covered.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/scripts/canonical_apply_control_retry_emulator_test.py, line 208:
<comment>Scenario 3 does not actually exercise a deletion during the retry window: the wipe is injected by the post-read fence callback, after the retried read has returned. Inject the wipe from the transient-failure hook (or synchronize it with the backoff) and assert that the fault and retry both occurred before claiming this race is covered.</comment>
<file context>
@@ -0,0 +1,244 @@
+ def wiping_fence_reader(uid_arg: str, *, db_client: Any = None, **_kwargs: Any) -> Any:
+ calls = getattr(wiping_fence_reader, "calls", 0)
+ wiping_fence_reader.calls = calls + 1 # type: ignore[attr-defined]
+ if calls > 0:
+ # Simulate deletion completing between attempts: the wipe marker
+ # now blocks projection writes, and the control doc is gone.
</file context>
|
Folded into #24602 (the consolidation of this batch onto the age-gate survivor branch |
|
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:
Before your next PR, please skim:
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! |
fix(memory): retry transient store faults on the canonical apply control read
Product invariants affected
Error group
{"source": "gcp", "service": "backend", "group": "memory_system.py:64 | utils.memory.memory_system.CanonicalApplyStateUnavailable: canonical apply control state is unreadable", "count": 1, "id": "gcp:backend-memory-system-py-64-utils-memory-memory-system-canonicalapplystateunavailable-canonical-apply-control-", "fingerprint": "fp:c6246721d1f51e14"}
Root cause
ensure_canonical_apply_control_stateinbackend/utils/memory/memory_system.pywraps the Firestore read of the apply-control document in_read_snapshot, whoseexcept Exceptionconverts every failure — including a transientServiceUnavailable/DeadlineExceeded/InternalServerErrorblip that already exhausted the SDK's own retry — directly intoCanonicalApplyStateUnavailable("canonical apply control state is unreadable", raised atmemory_system.py:64). One transient store fault therefore failed the whole apply gate for the request. Sibling paths already distinguish transient from permanent faults and retry boundedly (MCP OAuth refresh rotation indatabase/mcp_oauth.py,database/conversation_scan.py, and thetransient_store_errorclassifier inutils/memory/read_resilience.py); this read had no such budget.Fix
_read_snapshotnow retries store faults classified transient by the existingtransient_store_errorhelper (typed google.api_core errors: ServiceUnavailable, DeadlineExceeded, TooManyRequests, InternalServerError, Aborted) with the same three-attempt / 0.1s-0.3s backoff budget the MCP OAuth rotation uses, before failing closed exactly as before. Fail-closed semantics are unchanged: permanent faults (e.g.PermissionDenied), malformed payloads, cross-UID states, and exhausted retries still raiseCanonicalApplyStateUnavailableimmediately — no fallback writes, no second ledger, no historical-write path.Verification
python3 -m py_compile backend/utils/memory/memory_system.py backend/tests/unit/test_atomicity_lifecycle_regressions.py— OKbackend/.venv/bin/python -m pytest tests/unit/test_atomicity_lifecycle_regressions.py -q—25 passed in 20.22s(includes 3 new regression tests: single transient blip retried and recovered; sustained outage bounded at exactly 3 attempts then fails closed; permanentPermissionDeniedfails closed on the first attempt)backend/.venv/bin/python -m pytest tests/unit/test_canonical_kg_promotion.py tests/unit/test_required_memory_async.py tests/unit/test_knowledge_ledger.py tests/unit/test_process_conversation_usage_context.py -q—86 passed, 9 warnings in 25.15sFailure-Class: none