Skip to content

fix(recovery): wait for owner release before reply admission - #120935

Merged
vincentkoc merged 1 commit into
mainfrom
fix/recovery-owner-release-fence-120833
Aug 9, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/recovery-owner-release-fence-120833

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #120833

What Problem This Solves

Fixes an issue where a reply arriving immediately after restart recovery could begin before the previous reply operation had durably released its recovery ownership. In that ordering, the successor could snapshot recovery state that the old owner's delayed release then changed.

Why This Change Was Made

The reply-run registry is the lifecycle owner for operation clear and successor admission. It now installs and starts a successor-admission fence synchronously when the old operation clears, before the lane wakes a successor. The recovery-store release remains the durable CAS owner and resolves that fence only after its bounded owner-release retry completes.

Visible successors wait abortably through the release retry. Queued follow-ups remain bounded, heartbeat callers remain non-blocking, rotated session IDs propagate across registered aliases, and command-turn adoption preserves the source-keyed recovery identity.

Root Cause

runAfterReplyOperationClear previously began durable recovery-owner release only after clearReplyRunState notified lane waiters. That allowed a successor to pass admission and read durable recovery state before the old owner's release callback ran.

Architectural Owner And Canonical Fix

  • reply-run-registry.ts owns operation clear ordering and successor admission.
  • reply-turn-admission.ts registers recovery-owner release as the operation's successor fence.
  • main-session-recovery-store.ts owns the durable release retry and completion signal.

The canonical path remains the existing reply operation and durable recovery CAS flow. No duplicate execution path or downstream compensation layer was added.

Removed Or Avoided Paths

  • No Matrix-specific production changes.
  • No weakening or removal of recovery cycle, revision, owner, or lease CAS fields.
  • No public result-shape changes, AsyncLocalStorage, QA ownership moves, or broad CLI changes.
  • No WeakMap identity inference. The two operation-keyed maps hold explicit lifecycle metadata only, reject inactive owners, and are deleted synchronously on clear before handoff starts.

User Impact

Replies that race restart recovery no longer observe a partially released recovery owner. Normal visible replies remain cancellable, while queued and heartbeat traffic keeps its existing bounded behavior.

Evidence

Independent exact-head review approved:

4d6ed0cf84e1b88c43cdc8b128173d46a877847f

Focused local proof:

  • reply-run-registry.test.ts: 73 passed
  • reply-turn-admission.test.ts: 48 passed
  • main-session-recovery-store.test.ts: 23 passed
  • restart-recovery-claim.test.ts: 8 passed
  • session-accessor.test.ts: 94 passed
  • QA scenario catalog: 57 passed; one checkout-only failure because this sparse linked worktree omits a tracked Swift fixture
  • Targeted formatting and git diff --check: passed
  • Autoreview: clean, no accepted P0 findings
  • Merge-tree against origin/main d7133e7df6f5418810609be4827f61e2c51e7120: clean (abb54df2d66bfa806bfe88442f4b70df7bf5d4c7) with no overlap in the seven owner files

Changed-check proof passed conflict, ratchet, formatting, SDK contract, API, boundary, and package-patch gates. The remaining local typecheck gap is environment-only: this linked worktree lacks package-local [email protected], so resolution falls back to root 4.2.3. Hosted exact-head CI and repository-native prepare gates remain required before merge.

Production delta: +282/-39
Test delta: +442/-1

Punchcard-Session: amber-workshop-workshop-36

Punchcard-Session: amber-workshop-workshop-36
@vincentkoc vincentkoc self-assigned this Aug 9, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 9, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 9, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 2:45 AM ET / 06:45 UTC.

ClawSweeper review

What this changes

The PR makes successor replies wait for durable restart-recovery ownership release before they can enter reply admission.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open. Current main still wakes successor reply work before durable recovery-owner release begins; this PR moves that ordering fence to the registry owner boundary and has no definite correctness finding, but it remains a draft maintainer PR needing exact-head validation and a maintainer decision on the persistent-store outage tradeoff.

Priority: P1
Reviewed head: 4d6ed0cf84e1b88c43cdc8b128173d46a877847f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a coherent owner-boundary repair with focused regression coverage, pending rebase and exact-head recovery-boundary validation.
Proof confidence 🌊 off-meta tidepool Not applicable: The contributor is a repository member, so the external-contributor proof gate does not apply; exact-head recovery-boundary proof is still the material merge-confidence gap.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The contributor is a repository member, so the external-contributor proof gate does not apply; exact-head recovery-boundary proof is still the material merge-confidence gap.
Evidence reviewed 5 items Current-main race: Current main clears reply-run state and wakes waiters before its post-clear callback starts recovery-owner release, leaving a successor-admission window.
Owner-boundary repair: The PR starts operation-keyed successor barriers before clearing lane state and waking waiters; admission also rechecks the fence before operation creation.
Deferred-release contract: A failed immediate durable release keeps the fence pending until the lifecycle scheduler succeeds, rather than admitting a successor after an unsuccessful release.
Findings None None.
Security None None.

How this fits together

Restart recovery coordinates an interrupted agent reply with the next inbound turn. The reply-run registry controls in-memory lane admission, while the recovery store owns the durable lease release that prevents a successor from observing stale recovery state.

flowchart LR
  A[Reply operation completes] --> B[Reply-run registry]
  B --> C[Successor admission fence]
  C --> D[Durable owner release]
  D --> E[Recovery store]
  E --> F[Next reply admission]
  F --> G[Reply delivery]
Loading

Decision needed

Question Recommendation
Should visible successor replies remain abortably blocked until a persistently failing recovery store eventually releases the old owner, in order to preserve durable ownership ordering? Keep durable-first ordering: Retain the fence and require exact-head Matrix or mock-gateway fault proof that shows recovery handoff and the visible abort path.

Why: The implementation intentionally favors durable recovery correctness over immediate visible-reply availability during a store outage; source inspection establishes the behavior but cannot choose the product tradeoff.

Before merge

  • Resolve merge risk (P0) - During a persistent recovery-store write outage, visible successors wait abortably until durable release succeeds; queued traffic remains bounded and heartbeats skip. This is a deliberate integrity-over-availability tradeoff that needs maintainer acceptance and exact-head operational proof.
  • Resolve merge risk (P1) - The branch is draft and behind main, and its required exact-head checks are currently skipped.
  • Complete next step (P2) - Because this is a draft, maintainer-labeled PR with an intentional availability tradeoff, a maintainer should decide the contract after exact-head proof rather than dispatch an automated repair.
Agent review details

Security

None.

PR surface

Source +243, Tests +441. Total +684 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 282 39 +243
Tests 4 442 1 +441
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 724 40 +684

Review metrics

Metric Value Why it matters
Production vs test delta production +282/-39; tests +442/-1 The production growth is tied to a new explicit lifecycle-owner fence and is accompanied by focused ordering, retry, alias, and admission coverage.

Merge-risk options

Maintainer options:

  1. Rebase and demonstrate the handoff (recommended)
    Refresh onto main and attach exact-head fault-injection proof through the recovery boundary before marking the draft ready.
  2. Accept durable-first availability behavior
    Merge with an explicit maintainer decision that persistent recovery-store failure may keep a visible successor waiting until it aborts or storage recovers.
  3. Pause for a recovery-availability contract
    Do not merge until the intended behavior for persistent store failures is specified if indefinite visible waiting is not acceptable.

Technical review

Best possible solution:

Keep the registry-owned fence, rebase it, and prove the restart-recovery ordering through the Matrix/mock-gateway boundary before a maintainer marks the PR ready.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main wakes the reply lane before beginning durable owner release, and the linked Matrix QA report provides the observable failed ordering; no fresh run was executed in this read-only review.

Is this the best way to solve the issue?

Yes. Starting the fence in the reply-run registry before wake-up fixes the owner ordering directly while leaving durable CAS and retry ownership in the recovery store; narrowing downstream claim comparisons would be a less canonical mitigation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a3d2ac7dc887.

Labels

Label changes:

  • add P1: The linked current-main race can suppress a post-restart reply after an inbound message.
  • add merge-risk: 🚨 session-state: The PR changes the ordering between persisted recovery-owner release and successor admission.
  • add merge-risk: 🚨 availability: A persistent recovery-store failure can keep visible successor admission waiting until abort or eventual release.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The contributor is a repository member, so the external-contributor proof gate does not apply; exact-head recovery-boundary proof is still the material merge-confidence gap.

Label justifications:

  • P1: The linked current-main race can suppress a post-restart reply after an inbound message.
  • merge-risk: 🚨 session-state: The PR changes the ordering between persisted recovery-owner release and successor admission.
  • merge-risk: 🚨 availability: A persistent recovery-store failure can keep visible successor admission waiting until abort or eventual release.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The contributor is a repository member, so the external-contributor proof gate does not apply; exact-head recovery-boundary proof is still the material merge-confidence gap.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the implicated post-clear ordering to this recent recovery-lifecycle commit. (role: recent recovery-lifecycle contributor; confidence: high; commits: c2e7c819f570; files: src/auto-reply/reply/reply-turn-admission.ts, src/auto-reply/reply/reply-run-registry.ts)
  • Ayaan Zaidi: History associates this contributor with the operation-adoption path that shares the reply-run lifecycle invariant. (role: earlier reply-operation contributor; confidence: medium; commits: 47ce757c; files: src/auto-reply/reply/reply-run-registry.ts, src/auto-reply/reply/reply-turn-admission.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and obtain required exact-head CI.
  • Attach a redacted Matrix or mock-gateway fault-injection trace showing durable release completes before the next reply is admitted.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer decision and ClawSweeper Rank-up moves:

  • Refresh onto current main / exact-head CI: no drift-only rebase. Live origin/main is f67da420f6068a4cf28ccc4f57200663d8acc3f2; it has no overlap with the seven recovery-owner files, and reviewed head 4d6ed0cf84e1b88c43cdc8b128173d46a877847f merge-trees cleanly as 79474c13b9c0244d92256c71c661d9b045d82ae2. Required exact-head CI will run on the unchanged reviewed SHA through the repository-native prepare flow.
  • Matrix or mock-gateway fault trace: not added. ClawSweeper classifies this as an optional Rank-up move, and the authorized scope excludes Matrix-specific production changes. Exact-head focused tests already cover delayed durable release, visible abortability, bounded queued and heartbeat behavior, alias rotation, command adoption, and recovery claims.
  • Availability tradeoff: accepted. Durable recovery ownership wins over visible-reply availability during a persistent recovery-store outage; a visible successor may remain blocked until it aborts or storage recovers. Queued traffic remains bounded and heartbeats skip.

No ClawSweeper code or security finding remains. Proceeding only through the required scripts/pr exact-head prepare and merge gates.

@vincentkoc
vincentkoc marked this pull request as ready for review August 9, 2026 07:04
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc
vincentkoc merged commit bccf659 into main Aug 9, 2026
200 checks passed
@vincentkoc
vincentkoc deleted the fix/recovery-owner-release-fence-120833 branch August 9, 2026 07:17
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky: matrix-post-restart-room-continue — durable-turn admission rejects the post-restart reply on recovery-progress fields

1 participant