Skip to content

fix: retry temporary database capacity failures during agent startup - #173994

Merged
obviyus merged 10 commits into
openclaw:mainfrom
McgAtom:fix/startup-sqlite-capacity-retries
Oct 30, 2026
Merged

obviyus merged 10 commits into
openclaw:mainfrom
McgAtom:fix/startup-sqlite-capacity-retries

Conversation

@McgAtom

@McgAtom McgAtom commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #162497

What Problem This Solves

Agents can remain degraded after a temporary SQLite broker-capacity refusal during Gateway startup, even after capacity is released. This PR lets their database preparation recover during that same startup.

User Impact

An affected agent can complete startup and continue its existing conversation without another Gateway restart. Persistent pressure and genuine database failures still fail visibly. No configuration, schema or storage-format change is required.

Why This Change Was Made

The existing startup preparation owner retries canonical overloaded opens within its bounded, abortable policy. Opening lock and capacity refusals share one four-attempt budget, with deletion/file-identity checks before retry and opening permits released before backoff. An opening retry does not repeat migration or publication. Migration locks retain their existing separate phase retry and opened borrower.

The contributor's commits are retained and refreshed on current main, preserving upstream early-read admission and restart-input recovery. This is only the recovery fix: it does not include the permanent resource-budget feature proposed in #182165 or change any broker limit.

Evidence

Independent current-main and exact-head built-Gateway proof.

  • Complete independent main 65acdfd629e3555f3c876e3fe887d548633e1863 and candidate 94e2440d241d80d750ece96c989c136fa40725c3 builds in secretless Linux arm64 Docker, Node 24.22.1.
  • Two main startups encounter actual broker capacity at 64 real occupied SQLite stores and remain unable to serve the target agent after release.
  • Two candidate startups observe the real opening refusal, release real capacity, recover without changing Gateway PID, and successfully continue the saved conversation through actual ACP manager/acpx and a maintained controlled stdio peer.
  • A separate pressure-free candidate startup control passes. Configuration/workspace hashes and session identity are preserved; independent SQLite reads confirm old and new transcript roles.
  • 50 existing consumer tests passed across three files, plus scoped formatting. Final delta: production +37/-29, docs +6/-0, tests +0/-0; no test-budget allocation. Existing main tests remain unchanged.

This is real broker pressure through a public-SDK plugin, not a fabricated exception, replaced startup callback or filesystem-full condition. The baseline is a full main build, not an owner-file substitution. No live-provider, live-channel or new upgrade claim is made. Candidate 2's functional proof passed but its cleanup driver falsely counted two defunct processes; independent follow-up confirmed no live proof children, and the corrected census completed the normal control successfully. Full details and the limitation are in the linked evidence.

Simplification keeps one preparation owner and reuses its existing retry policy without new state, exported helper or alternate recovery path.

Merge Danger

Two-way door: reverting restores the former opening-refusal behavior; there is no migration or persisted contract to undo. Blast radius is deferred agent database startup preparation under lock/capacity pressure. An incorrect retry classification could delay a genuine failure or repeat unsafe work; retries remain bounded, abortable and restricted to opening capacity refusals, with existing lifecycle/identity checks and separate migration/publication ownership.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@McgAtom
McgAtom marked this pull request as ready for review October 16, 2026 08:04
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Retry temporary SQLite opening-capacity refusals within the existing bounded agent-startup retry policy.

Example: An agent encounters opening-capacity refusal while 64 real SQLite stores occupy the broker, then capacity becomes available.

  • Before: The agent remains unavailable after capacity is released until the Gateway restarts.
  • After: The agent retries opening and can continue its saved conversation without restarting the Gateway.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct recovery change with strong production-entry-point proof; a committed automated opening-overload regression would improve long-term protection.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The exact-head Linux Docker proof exercises real broker pressure through a public-SDK plugin and the built Gateway: two baseline runs remain unavailable after release, two candidate runs recover in the same Gateway process and continue the saved conversation, and a normal control passes; the disclosed cleanup-census error does not invalidate the functional observations.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A temporary database-opening refusal can leave a healthy agent unavailable even after capacity returns.
Reason: The PR fixes its stated startup-recovery defect without adding configuration or changing broker limits; its Related reference appropriately leaves the broader capacity request open.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses a confirmed startup-recovery failure still present on current main, with convincing exact-head Gateway evidence and no identified correctness defect.

Priority: P1
Reviewed head: 94e2440d241d80d750ece96c989c136fa40725c3

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway startup admission coordinates deferred database opening, migration, and publication; broker refusals enter this owner, which either admits the agent or records a readiness failure.

flowchart TD
  A[Gateway startup] --> B[Startup admission owner]
  B --> C[SQLite database opening]
  C --> D[Bounded opening retry]
  D --> C
  C --> E[Migration]
  E --> F[Agent publication]
  F --> G[Conversation available]
Loading

Technical review

Best possible solution:

Keep recovery in the existing startup owner, retaining bounded opening retries and separate migration and publication phases.

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

The supplied independent built-Gateway baseline reproduces terminal opening-capacity degradation twice; the affected startup source is unchanged on fetched main, and this review ran no target code.

Is this the best way to solve the issue?

The scoped fix uses the existing preparation owner, releases opening permits before backoff, rechecks deletion and file identity, and avoids replaying completed migration or publication.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4d2a9f8bb4c4.

Provenance checked

  • Opening and migration retry policy changes intended behavior with a stated reason (84806d0: Recover transient SQLite locks using separate bounded phase retries while preserving cleanup, deletion, and file-identity safeguards.)
  • Deletion-journal retry settings keeps the original intent (520860b: Prevent fleet startup journal checks from exhausting shared read admission and retry temporary contention.)
  • Prepared database lifetime keeps the original intent (efd7523: Retain the ordinary database borrower through preparation so idle eviction does not force reopening during publication.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +8, Docs +6. Total +14 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 37 29 +8
Tests 0 0 0 0
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 43 29 +14

Review metrics

Metric Value Why it matters
Production versus test delta Production +37/-29; tests +0/-0 The small net growth extends the existing retry owner and shares its settings without adding state, another recovery path, or test scaffolding.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: Reported large-fleet startups leave otherwise healthy agents unavailable until restart, preventing their conversations from continuing.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

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

  • Extend the existing startup regression fixture to cover canonical opening overload recovery and exhaustion without duplicating its setup.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (8 earlier review cycles)
  • reviewed 2026-10-16T08:20:40.060Z sha 205f57e :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T14:13:02.038Z sha 205f57e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-23T13:53:51.742Z sha a577e85 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-23T15:42:20.134Z sha 42a7bd7 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T12:53:29.198Z sha 0bc17f5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T14:37:32.659Z sha 0bc17f5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-29T04:52:42.290Z sha a61ce9d :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-29T09:08:58.800Z sha a61ce9d :: needs maintainer review before merge. :: none

Reviewed October 30, 2026, 6:05 PM ET / 22:05 UTC (Revision 9).

@McgAtom

McgAtom commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@609NFT

609NFT commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Ran this head (205f57e) on our 810-agent production copy against its parent (387ebd6): 4 vCPU / 16 GB, Node 24.21, doctor --fix to v27, then two 15-minute boots.

The retry works. In the boot where deferred preparation ran at fleet scale, 1,038 opens were rejected with SQLite worker open input capacity reached and no agent stayed degraded on it (on 58fb588 every degraded agent did).

The next gate now fails the same way: 136 agents stayed degraded until restart with Agent schema admission changed before publication; retry the operation, each after ~270 s in open-wait and a completed open and migration. The error asks for a retry, but startup treats it as terminal; retrying publication (or re-running that agent's preparation) on it looks like the remaining piece. 586 more were still queued when our 15-minute window closed.

Happy to rerun on a revision.

@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 29, 2026

McgAtom commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S and removed size: M labels Oct 30, 2026
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Independent current-main startup recovery proof for exact head 94e2440d241d80d750ece96c989c136fa40725c3.

Refreshed the contributor's original commits on main 65acdfd629e3555f3c876e3fe887d548633e1863 because the startup owner changed upstream. Built complete independent source archives of main and the final candidate in secretless Linux arm64 Docker, Node 24.22.1 (gatewayWatch, bundled acpx). The baseline is not an owner-file substitution. Each run uses its own explicit profile, home/state/config paths, port, SQLite files and controlled maintained ACP peer.

Actual capacity condition

This PR handles SQLite broker store/open-input capacity, not disk-full errors. A task-owned plugin uses the public SQLite SDK to open real databases and hold real broker operations. 64 stores occupy the actual unchanged broker limit; the next open produces the production overloaded refusal. No error is fabricated, no startup callback is replaced, and no capacity constant or budget is modified. Releasing those real operations frees capacity.

The setup first completes a real seed agent turn, stops that Gateway, and removes one index from the owned offline target database, following the existing unsealed-fleet startup regression. This requires actual writable startup repair instead of letting early read admission warm the target owner before pressure. The pressure is released only after observing the target's production opening outcome, not on a timer. A safety deadline would fail the proof.

Observed runs

Run Startup opening under pressure After actual capacity release Saved conversation
Main 1 Target terminally degraded: SQLite worker open input capacity reached Real target agent RPC still rejected as unavailable Original user, assistant retained
Main 2 Same terminal opening refusal Same unavailable target after release Original user, assistant retained
Candidate 1 agent database startup capacity reached; retrying preparation ... phase=open attempt=1 Production recovery completed; real agent RPC status: ok, same Gateway PID user, assistant, user, assistant, same session ID
Candidate 2 Same bounded opening retry observed Real agent RPC status: ok, same Gateway PID Same preserved identity and four message roles
Normal candidate control No pressure enabled Readiness and both real agent calls succeeded Same four roles and identity

Configuration and workspace sentinel hashes remain unchanged in all five runs. Independent read-only SQLite reads verify transcript roles after shutdown. Candidate readiness succeeds after release. No system clock changes, external model-provider credentials, live channel, physical disk-capacity or new upgrade claim.

Representative captured production output:

main1: PROOF_CAPACITY_SATURATED canonical=overloaded held=64
main1: agent database remains degraded agentId=target ... reason="SQLite worker open input capacity reached"
main1: PROOF_CAPACITY_RELEASED stores=64 reason=observed-production-opening-outcome
main1: agent RPC UNAVAILABLE: SQLite worker open input capacity reached

candidate1: PROOF_CAPACITY_SATURATED canonical=overloaded held=64
candidate1: agent database startup capacity reached; retrying preparation agentId=target phase=open attempt=1
candidate1: PROOF_CAPACITY_RELEASED stores=64 reason=observed-production-opening-outcome
candidate1: agent database recovered after background inspection and preparation
candidate1: agent RPC status=ok; prior and new messages retained

Checks and scope

  • 50 existing tests passed across three files: startup journal admission, agent database admission and Gateway startup. Scoped formatting passed.
  • Final introduced delta: production +37/-29, docs +6/-0, tests +0/-0. Contributor-added test growth was removed to meet the assigned zero-growth ceiling; existing main coverage is restored unchanged. No test-budget allocation.
  • Simplification retains the existing preparation owner and one bounded four-attempt policy. Opening overloads share the opening lock budget; migration/publication are not replayed by opening retries. No permanent resource-budget feature from fix(sqlite): size the worker store budget from the configured agent roster #182165, config option, schema, public API or security-policy change is included.
  • Candidate 2 completed every functional assertion and wrote its PASS receipt, but its final cleanup census exited nonzero because it counted two PID-1-adopted defunct processes as live. A subsequent independent docker top showed only the container's sleep infinity, with no live proof children. The task-owned census now reads process state and excludes zombies; no product/retry assertion was changed. The normal control then exited successfully. The original failure/retention receipt is preserved rather than represented as a clean driver exit.

The older macOS upgrade evidence in the prior description remains historical; the results above are the new current-main/exact-head Linux startup proof.

@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@obviyus
obviyus merged commit 9db820e into openclaw:main Oct 30, 2026
149 of 152 checks passed
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Landed in 9db820e. Thanks @McgAtom. The Gateway now recovers when SQLite capacity frees up during startup.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…penclaw#173994)

fix(gateway): recover when SQLite capacity frees up during startup

If SQLite broker capacity was exhausted while the Gateway started, startup gave up and the Gateway stayed unavailable even after capacity was freed, until it was restarted by hand. Startup now retries within the existing startup flow, so the same Gateway process recovers once capacity is available. There is no new budget or configuration.

Evidence: built Gateways with real SQLite broker capacity exhausted and then released. Main stayed unavailable after the release (twice). With this change it recovered in the same process and continued the saved conversation (twice). A normal startup control passed. Config and workspace hashes and session identity were preserved. Details: openclaw#173994 (comment).

Thanks @McgAtom.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

3 participants