Skip to content

fix(delivery): renew stable producer leases - #118663

Merged
vincentkoc merged 2 commits into
mainfrom
fix/delivery-stable-producer-lease
Aug 3, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/delivery-stable-producer-lease

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Related: #118044

What Problem This Solves

Resolves a delivery race where a reusable stable outbound intent could outlive its producer claim while channel preparation or the provider send was still running. Recovery could then acquire the same intent and begin a second provider send before the first producer had a definitive result.

Why This Change Was Made

  • Upgrade a reused stable send to one exact renewable SQLite owner before channel preparation.
  • Renew that same claim through preparation and provider execution; abort before further provider or queue mutation when ownership is definitively lost.
  • Keep producer_claimed, send_attempt_started, and explicit unknown_after_send rows fenced while the stable lease is live.
  • Use the existing Gateway-owned five-second retry loop as the only recovery scheduler. Startup migration still runs once, periodic drains use fresh runtime config, and expired leases are picked up by the next tick.
  • Fence recovery synchronously during Gateway close and await actual in-flight settlement before plugin/channel teardown.
  • Warn after five seconds if recovery is still pending; the process-level shutdown watchdog remains the forced-exit owner.

This integrates with the single recovery owner landed in #118694. It deliberately removes the stacked branch's duplicate exact-expiry timer and nextRecoveryAt contract.

No SQLite schema version, DDL, or migration is added. requiresProducerClaim remains metadata in the existing queue entry JSON.

User Impact

Long-running outbound sends no longer become eligible for concurrent recovery while their original producer still owns the attempt. This reduces duplicate real-world sends and keeps restart recovery conservative when the platform outcome is unknown.

Recovery may begin up to five seconds after an expired lease. That bounded delay is intentional: one lifecycle-owned scheduler is safer than competing interval and exact-expiry timers.

Shutdown now keeps plugin/channel runtime alive until any admitted recovery settles. Providers do not expose a universal acknowledged-cancellation contract, so a local timeout cannot safely prove that delivery work has stopped.

Evidence

  • Exact-head focused proof: 189/189 tests passed across eight files.
  • Gateway lifecycle/import-boundary proof: 32/32 passed.
  • Lease, SQLite, storage, recovery, and delivery integration proof: 157/157 passed.
  • Covered behavior includes active-lease skip, post-expiry recovery, renewal through long preparation, exact-owner replacement, lease loss before and after dispatch, unknown_after_send retention, fresh-config retries, non-overlap, suspended admission, idempotent stop, startup-recovery join, and warning-only shutdown wait.
  • git diff --check passed.
  • Targeted oxfmt passed.
  • Exact-head autoreview passed with no accepted/actionable findings (patch is correct, confidence 0.91).
  • Production delta: +348/-35. Test delta: +965/-9. Total: 22 files.

No CHANGELOG.md edit: release generation owns changelog entries for normal PRs.

@vincentkoc vincentkoc self-assigned this Aug 3, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 3, 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 3:10 PM ET / 19:10 UTC.

ClawSweeper review

What this changes

The PR renews the exact SQLite producer lease for reusable durable outbound sends during preparation and provider execution, and makes Gateway shutdown wait for active recovery before runtime teardown.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The prior shutdown-lifecycle blocker is resolved: the Gateway fences outbound recovery synchronously and now awaits the admitted recovery before tearing down plugin/channel runtime. The branch still addresses a real current-main duplicate-send race, so it remains necessary; this maintainer-authored, delivery-critical change needs normal maintainer acceptance of its deliberate shutdown-versus-delivery-safety tradeoff.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The branch has a coherent owner-boundary repair, resolves the prior P1 lifecycle finding, and supplies targeted coverage for the central race and shutdown behavior.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the body and follow-up nevertheless provide exact-head focused runtime proof claims.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the body and follow-up nevertheless provide exact-head focused runtime proof claims.
Evidence reviewed 5 items Current-main gap: Current main keeps a 30-second reusable-owner lease through promotion but has no renewal path, so a long preparation or provider call can outlive the durable claim and become recoverable concurrently.
Exact-owner renewal: The PR renews only an unexpired row whose producer or platform-attempt identifier exactly matches the active claim, preserving the existing SQLite ownership boundary rather than adding a parallel scheduler.
Resolved prior finding: Gateway close now starts the recovery stop synchronously and awaits the same promise before close-prelude teardown, replacing the earlier five-second resolution behavior that could permit runtime teardown while recovery remained live.
Findings None None.
Security None None.

How this fits together

OpenClaw stores durable outbound intents in SQLite and the Gateway periodically recovers pending rows after failures or restarts. The producer lease determines whether a live sender or recovery owns an intent, and Gateway lifecycle code controls whether that recovery can still use channel and plugin runtime during shutdown.

flowchart LR
  A[Durable outbound intent] --> B[Exact producer lease]
  B --> C[Channel preparation]
  C --> D[Provider send]
  B --> E[Gateway recovery loop]
  D --> F[Durable outcome]
  E --> F
  E --> G[Gateway shutdown fence]
Loading

Decision needed

Question Recommendation
Should Gateway shutdown retain plugin and channel runtime until an admitted outbound recovery settles, rather than allowing a local timeout to continue teardown? Accept the conservative shutdown fence: Keep the new warning-only five-second threshold and wait for the recovery promise before teardown, preserving delivery ownership safety.

Why: The code correctly implements the documented conservative contract, but choosing between possible extended shutdown and the risk of duplicate or misclassified provider sends is an operator-facing lifecycle policy choice.

Before merge

  • Resolve merge risk (P1) - If a provider call never settles during shutdown, Gateway now retains channel/plugin runtime until the process-level watchdog exits; this intentionally favors avoiding duplicate or misclassified delivery over a local forced teardown.
  • Complete next step (P2) - No discrete automated repair remains; a maintainer must accept the intentional shutdown availability tradeoff before this delivery-critical change lands.
Agent review details

Security

None.

PR surface

Source +321, Tests +948. Total +1269 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 14 356 35 +321
Tests 8 957 9 +948
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 1313 44 +1269

Review metrics

Metric Value Why it matters
Production and test delta production +348/-35; tests +965/-9 The substantial production growth is tied to a concrete ownership boundary—renewable exact leases and lifecycle settlement—and is paired with broader focused regression coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/delivery-queue-sqlite.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Merge with the conservative recovery fence (recommended)
    Accept the bounded recovery-start delay and warning-only shutdown threshold so an active provider operation cannot be raced by recovery or teardown.
  2. Pause for a provider cancellation contract
    Keep the PR open until maintainers choose and can validate an acknowledged-cancellation boundary that safely permits earlier teardown.

Technical review

Best possible solution:

Keep one renewable exact owner for stable delivery and one Gateway-owned recovery scheduler, then merge only if maintainers accept waiting for admitted recovery rather than tearing down its runtime mid-flight.

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

Yes. Current main has a finite producer lease with no renewal path, while recovery treats an expired stable owner as eligible; the PR's focused tests exercise lease expiry during preparation and after provider dispatch.

Is this the best way to solve the issue?

Yes. Reusing the merged Gateway recovery scheduler while renewing only the exact SQLite owner is a more coherent fix than adding another expiry timer or relying on cancellation that providers cannot acknowledge universally.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • 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: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the body and follow-up nevertheless provide exact-head focused runtime proof claims.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The repaired race can cause concurrent recovery and a duplicate real-world outbound send.
  • merge-risk: 🚨 message-delivery: The patch changes ownership fencing around durable provider sends and recovery eligibility.
  • merge-risk: 🚨 availability: Gateway close deliberately waits for in-flight recovery before plugin and channel runtime teardown.
  • 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: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the body and follow-up nevertheless provide exact-head focused runtime proof claims.

Evidence

What I checked:

  • Current-main gap: Current main keeps a 30-second reusable-owner lease through promotion but has no renewal path, so a long preparation or provider call can outlive the durable claim and become recoverable concurrently. (src/infra/delivery-queue-sqlite-claim.ts:133, cd42cb770332)
  • Exact-owner renewal: The PR renews only an unexpired row whose producer or platform-attempt identifier exactly matches the active claim, preserving the existing SQLite ownership boundary rather than adding a parallel scheduler. (src/infra/delivery-queue-sqlite-claim.ts:135, a654eacea78e)
  • Resolved prior finding: Gateway close now starts the recovery stop synchronously and awaits the same promise before close-prelude teardown, replacing the earlier five-second resolution behavior that could permit runtime teardown while recovery remained live. (src/gateway/server-lifecycle.ts:300, a654eacea78e)
  • Lifecycle behavior coverage: Focused tests cover waiting for startup recovery, warning after five seconds without releasing shutdown, lease loss before provider I/O, and preserving the queued row after lease loss following dispatch. (src/gateway/server-runtime-services.test.ts:390, a654eacea78e)
  • Merged scheduler provenance: The branch and current main both contain the merged Gateway retry-loop owner, so this PR layers lease fencing onto the canonical recovery scheduler instead of restoring a second timer. (src/gateway/server-runtime-services.ts:185, 25f174c8a044)

Likely related people:

  • vincentkoc: Authored the current lease and shutdown repair, and git blame attributes the existing Gateway recovery loop to their recent work. (role: recent area contributor; confidence: high; commits: f9baa3e89421, 2ac8111f6a18, a654eacea78e; files: src/gateway/server-runtime-services.ts, src/gateway/server-lifecycle.ts, src/infra/outbound/deliver-queue.ts)
  • steipete: Merged the canonical Gateway durable-retry owner that this PR intentionally reuses rather than duplicating. (role: merged recovery-scheduler contributor; confidence: high; commits: 25f174c8a044; files: src/gateway/server-runtime-services.ts)

Rank-up moves

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

  • Obtain maintainer acceptance of the documented shutdown-wait contract and let the remaining exact-head required checks complete.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-03T12:49:17.777Z sha 5f8b9c6 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T18:23:42.164Z sha 5f8b9c6 :: found issues before merge. :: [P1] Do not continue teardown while recovery is still live

@vincentkoc
vincentkoc force-pushed the fix/plugin-route-registration-strict branch 2 times, most recently from db71f9f to 830ae07 Compare August 3, 2026 18:04
Base automatically changed from fix/plugin-route-registration-strict to main August 3, 2026 18:15
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 3, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 3, 2026
@vincentkoc
vincentkoc force-pushed the fix/delivery-stable-producer-lease branch from 5f8b9c6 to 2ac8111 Compare August 3, 2026 18:51
@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label Aug 3, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 3, 2026 18:55
@vincentkoc

Copy link
Copy Markdown
Member Author

Resolved the ClawSweeper P1 on shutdown ownership.

Decision: Gateway close must await actual outbound-recovery settlement before plugin/channel teardown. The five-second timer is now warning-only; it no longer reports quiescence or permits teardown while recovery remains live. The outer process shutdown watchdog remains the forced-exit boundary.

Why not treat AbortController as the safety proof: provider dispatch and plugin adapters do not have a universal acknowledged-cancellation contract. A signal can improve cooperative shutdown latency later, but it cannot prove that an already-started provider call has stopped or was not accepted.

Exact-head proof:

  • 189/189 focused tests passed.
  • Startup recovery and periodic retry both retain their admitted root until settlement.
  • Double-stop is idempotent, no retry rearms, and the five-second warning fires once without resolving shutdown.
  • Gateway import-boundary proof confirms the close prelude awaits this stop before runtime teardown.
  • Autoreview found no actionable issues.

Head: a654eacea78e5cf6ee608d3f5932e10fca94c2cb

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 3, 2026
@vincentkoc
vincentkoc merged commit 371c03c into main Aug 3, 2026
132 of 138 checks passed
@vincentkoc
vincentkoc deleted the fix/delivery-stable-producer-lease branch August 3, 2026 19:15
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 3, 2026
…-state-mutation

* origin/main: (22 commits)
  fix(delivery): renew stable producer leases (#118663)
  test(mcp): isolate catalog size checks from wall-clock load (#118871)
  test(ui): add credentials primary QA proof (#118790)
  fix(slack): prevent stalled presence polling from hanging shutdown (#117478)
  test(security): cover gateway shared auth modes (#118834)
  fix(macos): show gateway auth failures in app status (#118841)
  test(tui): route PTY gateway scenarios through explicit models (#118802)
  test(qa): add session transcript primary coverage (#118820)
  fix(browser): protect private observation media and Canvas trust boundaries (#118775)
  fix(build): restore SDK packages and signed macOS app builds (#118833)
  test(qa): cover plugin authoring contracts (#118821)
  fix(parallels): keep provider keys out of POSIX job logs (#118840)
  improve: reduce redundant Code Mode test work (#118815)
  fix(models): report primary OpenRouter limits in scans (#110855)
  test: speed up setup inference fixtures (#118811)
  fix(auto-reply): enforce canonical reset authorization (#118580)
  docs(gateway): fix invalid heartbeat visibility examples (#118827)
  fix(plugins): unify HTTP route conflict handling (#118203)
  test(agents): use prepared auth fixtures (#118816)
  fix(lmstudio): resolve JIT embedding variants
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
* fix(delivery): renew stable producer leases

* fix(delivery): keep recovery inside shutdown fence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

1 participant