Skip to content

Dream: retry short destructive-gate contention at apply instead of discarding the pass - #21966

Merged
Git-on-my-level merged 4 commits into
mainfrom
lane/dream-gate-retry
Oct 17, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
lane/dream-gate-retry

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

The 2026-10-17 02:00Z Dream pass on the allowlisted owner ran 40 turns ($0.69), verified its findings, and then failed at apply with DestructiveOperationInProgress, so nothing was applied (error_type=other). The account-wide gate (legal_hold_deletion_gates/{uid}) was held by an explicit_memory_deletion operation for a short window. Conversation reprocessing takes that gate every few minutes while sync backfill drains.

  • Dream now retries an apply or suggestion effect when it hits a short destructive gate (explicit_memory_deletion, retention_cleanup, audio_conversation_deletion).
    • Backoff is 5/15/30/60s and resets for each effect.
    • A pass-wide cap stops new waits once fewer than 20s of apply headroom remain before the pass deadline.
  • Dream never retries under account deletion or a legal hold. A new read-only helper, dream_gate_contention_retry_allowed in legal_holds.py, does two point reads; it is called only by Dream, and a failed read means no retry.
  • When retries run out, or the pass times out mid-retry, it ends with dream_gate_contention and releases the lease, instead of error_type=other.
  • Only on a gate retry, an apply_verified_edit journal written during this pass's lease counts as applied, so an ambiguous commit is not applied twice. First attempts and journals from earlier passes still go through full revalidation.

Product invariants

  • INV-MEM-4: no change to verification or apply authority. Legal-hold and deletion semantics are unchanged.

Verification

  • tests/unit/test_dream_harness_runtime.py, 21 tests via backend/test.sh:
    • contention then success applies the edit;
    • six independently contending effects all succeed;
    • persistent contention ends as dream_gate_contention;
    • the account-deletion gate fails fast;
    • an earlier-pass journal on a first attempt is still revalidated (invalid_evidence).
  • Pyright on the changed files reports 0 diagnostics.
  • Review: Grok gave FIX-FIRST (3 findings), all fixed in ff1ed15; the re-review gave SHIP.

Failure-Class: none

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-17T03:02:07.904078Z ff1ed15 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.

@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: ff1ed1526f

ℹ️ 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".

Comment on lines +564 to +565
if isinstance(exc, TimeoutError) and gate_retry_in_progress:
exc = ValueError('dream_gate_contention')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve executor timeout lease fencing during retries

If the overall pass deadline expires while a retried run_blocking effect is still executing, gate_retry_in_progress is still true, so this rewrites the cancellation from TimeoutError to ValueError('dream_gate_contention'). run_pass consequently calls dream_store.finish(..., release=True) and releases the capacity slot, whereas ordinary executor timeouts deliberately retain both because cancelling run_in_executor does not stop the worker. A slow two-phase memory effect can therefore continue after its lease has been cleared and a new pass has been admitted; only convert timeouts known to occur during the backoff sleep, or otherwise preserve the timeout/release semantics while an executor attempt is outstanding.

AGENTS.md reference: backend/AGENTS.md:L125-L125

Useful? React with 👍 / 👎.

raise ValueError('agent_user_memory_requires_review')
validate_edit(edit, records, authority=authority)
if authority == 'dream' and gate_retry:
key = edit_key(edit, records)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resume person merges after pre-journal bootstrap writes

When a merge_people edit targets legacy people whose knowledge_nodes are absent, merge_review_entities first creates those nodes in ensure_nodes and only afterward enters the gate-protected journal transaction. If that later transaction raises the retryable contention, no review_changes journal exists, so this retry path falls through; the second attempt then compares the original None node fences against the nodes created by the first attempt and returns invalid_evidence instead of completing the verified merge. The retry needs to make the bootstrap write atomic with the journal or explicitly recognize and resume nodes created by the failed attempt.

Useful? React with 👍 / 👎.

and change.get('undone', False) is False
):
return 'applied'
refs = {base_ref(ref) for ref in [edit.target, *edit.evidence, *([edit.other] if edit.other else [])]}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Resume post-commit transcript projection work

If a transcript correction commits and a retryable destructive gate starts before sync_transcript_chunks reaches its fenced Pinecone upsert, the chunk deletion has already run and the upsert raises DestructiveOperationInProgress. On retry, this early return sees the committed journal and reports applied without rerunning sync_transcript_chunks, leaving that conversation's transcript vectors deleted while the pass is recorded as successful. A committed-journal retry must resume the idempotent post-commit projection work rather than returning immediately.

AGENTS.md reference: backend/AGENTS.md:L125-L125

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit fba9685 into main Oct 17, 2026
57 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/dream-gate-retry branch October 17, 2026 03:27
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