Skip to content

Dream: retry Firestore contention on turn ledger, admission and discovery; log failure stages - #23051

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/dream-new-owner-failures
Oct 21, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/dream-new-owner-failures

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

At 2026-10-21 13:01Z, prod's first Dream sweep with 5% of paid owners failed about 18 passes in seconds on one backend-sync instance:

  • most had turns=0, error_type=other and applied=0;
  • one failed with ValueError.

The ramp was rolled back to DREAM_AGENT_PAID_PERCENT=0 (#23041).

Root cause (Codex Sol, high confidence in the defect, moderate in prod attribution).

  • database/dream_turns.reserve/settle ran Firestore transactions without the existing helper that retries transaction-read Aborted.
  • The SDK retries only commit aborts. Read-time Aborted escapes, and exhausted commit retries surface as ValueError from Aborted.
  • Concurrent new owners contend on the shared minute-headroom shards. Aborted falls outside the metrics allowlist, so it's labelled other.
  • All of this happens before the turn counter advances, which matches the zero-turn pattern.

Fix.

  • Retries: the bounded Aborted-retry helper (fresh transaction and re-read per attempt; only Aborted-cause chains replay) now wraps:
    • reserve and settle;
    • dream_store.acquire's claim;
    • dream_scheduler.discover's initialize. A discover abort previously killed the whole sweep with no report.
  • Diagnostics: a failed pass now logs the exception class, stage and source location (file:func:lineno), with no uid, message, document path or exc_info. drain records worker failures.
  • Metrics: FirestoreContentionExhausted is added to the metric ERROR_TYPES.
  • Pins: discover's Firestore query-shape digest is re-pinned in both registry locations.

Review

GLM-5.3 (zcode) returned SHIP-WITH-NITS. It confirmed:

  • the SDK behaviour behind the diagnosis;
  • that retries can't double-reserve or double-settle (aborted transactions write nothing; tests assert single receipts, exact spend and shard sums);
  • that the diagnostics carry no uid or user content and metric labels stay bounded.

Findings and what happened to them:

  • Medium (fixed in the second commit): acquire and discover transactions were unwrapped.
  • Low (fixed): FirestoreContentionExhausted rendered as other.
  • Low, accepted:
    • the drain results list now includes each retry attempt;
    • the emulator test fails rather than skips without an emulator, which matches repo convention (it's marked integration and excluded from test.sh).

Verification

Codex Sol ran backend/test.sh with BACKEND_UNIT_TEST_FILE_LIST, under nice/taskpolicy with 2 workers. Final head: 557 passed, 1 deselected across 7 targeted files, including 495 Firestore query-shape tests and 18 scheduler tests. Every new regression case failed before the patch.

A local Firestore-emulator run with 20 concurrent owners passed, preserving receipts, spend and minute totals.

These are unit and emulator results only.

Re-ramp plan

After deploy, re-ramp DREAM_AGENT_PAID_PERCENT to 5 with DREAM_AGENT_CONCURRENCY capped (8), as one config change. Watch:

  • zero-turn failures, and the new stage and class logs;
  • contention recovery and exhaustion logs;
  • capacity waits and completion rate.

The clean metric is unchanged: <2 failed passes per hour.

Product invariants affected

none

Failure class

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits October 21, 2026 20:52
Retry atomic read-time aborts and SDK commit-exhaustion wrappers with the existing bounded transaction helper. Keep ambiguous failures unreplayed. Log payload-free exception class, stage and source location, including drain retries after capacity waits.

Co-Authored-By: Codex Sol <[email protected]>
Apply the existing bounded transaction-contention helper to owner acquisition and each discovery page. Preserve admission, reclamation and queued due-row semantics; classify exhausted contention explicitly in pass metrics. Refresh both discovery query-coverage digests and cover read-abort recovery plus exhaustion.

Validation: 557 passed, 1 deselected across seven targeted backend test files. Seven new regression cases fail on c88bae0 and pass with this change.

Co-Authored-By: Codex Sol <[email protected]>
@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-21T14:22:32.068230Z d2388f3 PR opened
ℹ️ 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.

@Git-on-my-level
Git-on-my-level merged commit ffabf89 into main Oct 21, 2026
63 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/dream-new-owner-failures branch October 21, 2026 14:34
Git-on-my-level added a commit that referenced this pull request Oct 21, 2026
… contention fix (#23065)

* config(dream): re-ramp paid owners to 5% with concurrency 8 after the contention fix

The first 5% sweep failed on Firestore Aborted contention (fixed in #23051).
Re-ramp at 5% and cap Dream workers at 8 on all four Cloud Run services.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* config(dream): classify DREAM_AGENT_CONCURRENCY as a deploy config binding

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Oct 22, 2026
…obe_failed (#23283)

available_model() mapped every exception from reservation_state.refresh()
and dream_headroom() to reason=probe_failed with no exception visibility.
The probe callable cannot actually raise into that frame: _probe converts
its own failures to 'inconclusive' and refresh runs the probe as a
background task, so the old label misattributed shared-state read and
transaction errors (prod 2026-10-22: a probe_failed wait 0.45 s after
mark_saturated()'s record write to the same state, no gateway probe ran).

Exceptions on the shared-state path now wait with reason=state_error and
emit one payload-free WARNING per decision carrying the exception class
and failing stage (client/refresh/headroom); waiting semantics are
unchanged. No bounded retry added: #23051's contention retries cover
Firestore transactions, while this state is Redis with its own WATCH/
MULTI retry and read budgets.

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