Skip to content

fix: start Gateway while slow agent database checks finish - #150755

Merged
steipete merged 1 commit into
mainfrom
upd/sqlite-startup-integrity-budget
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/sqlite-startup-integrity-budget

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #150677 (GitHub lost the head refresh after a force-push; same branch, same change)

Closes #150574.
Related: #141918, #142179, #150444, #150564.

What Problem This Solves

Fixes Gateway startup aborting when an agent database inspection exceeds its wait budget without finding corruption.

Thanks to @desksk for the report and offline integrity timings that distinguished slow storage contention from database damage.

User Impact

The Gateway starts and serves healthy agents while an unfinished agent remains degraded with its reason and Doctor guidance. Its inspection continues in the background. The agent becomes available only after its credentials, sessions, and models are prepared. Genuine corruption leaves that agent degraded; shutdown cancels and joins retained work.

Shared-state database failures retain their existing behavior. There are no new configuration options, CLI flags, environment variables, dependencies, or SQLite schema changes.

Why This Change Was Made

At this PR's baseline, two fleet-preflight slots and a 635-second allowance for a 267.5 MiB database without sidecars are already on main but unreleased. The reporter's installed 2026.9.4 still has the older budget and concurrency. This PR fixes the remaining fatal timeout path; it preserves that scheduler, budget formula, and supervisor policy.

The existing inspection scheduler now separates its foreground wait from native worker cancellation. Startup transfers unfinished inspections to the Gateway lifetime and records agent admission refusals. Recovery uses the existing secrets, session, and model owners under current file, roster, configuration, and publication authority before clearing a refusal. Caller cancellation still cancels the native readers, and failed inspections remain foreground errors until their background handoff succeeds.

The Gateway startup owner composes this admission lifetime with the Linux spawn broker from #150564. Broker readiness precedes core startup. Admission remains registered in the existing Gateway lifetime-sidecar registry; the outer broker cleanup also joins that same admission if core cleanup fails before reaching its sidecars. Deferred preparation re-enters only the captured broker context, preserving its private database-preparation authority.

Evidence

  • Before the fix, a healthy 628 KiB fixture passed ordinary integrity checks but the existing 1 ms budget seam produced Gateway failed to start: SQLite schema inspection timed out after 0.001 seconds. The original database bytes were unchanged.
  • Differential regressions failed against the original owners for timeout recovery, corruption isolation, shutdown, targeted session preparation, and revoked write authority; the fast path passed.
  • Gateway boundary tests use real SQLite children and HTTP /healthz: healthy agents serve while a slow agent is refused, preparation completes before recovery, corruption stays agent-local, queued peers recover independently, and shutdown joins native work.
  • Review regressions failed before their fixes: caller abort left both native readers alive; an expired inspection failure was silently accepted before handoff; shared credential snapshots came from the ambient state instead of the selected state.
  • The original 120 focused tests passed in their existing order, followed by 20 broker startup, shutdown, fallback, and callback-context tests. Three new held-cleanup cases prove that broker extinction waits for admission drainage on failure before adoption, after adoption, and before sidecar shutdown.
  • Fresh boundary proof: healthz=200 while the slow agent is agent-database-inspection-pending; readmission clears only after credential/session/model preparation, and a command spawned during preparation has the broker as its parent. Removing the broker-context capture fails this parent-process assertion.
  • pnpm install --frozen-lockfile, pnpm check:changed, and pnpm build passed on the composed candidate. No lint substitute or baseline edit was needed.
  • Fresh Codex autoreview with --mode branch --base origin/main --max-priority P1 returned scoped-clean on the committed head.

Proof uses isolated state directories and free ports with deterministic native-child pauses and the existing budget seam. It does not claim a physical slow-volume benchmark or a shipped-driver respawn reproduction.

Ownership and line-count tradeoff

Production: +1,092 / −198 (net +894, 26 files). Tests: +1,113 / −18 (net +1,095, 9 changed files). Docs: net +37. Generated Swift protocol: +2 / −2 (net 0).

Production growth owns the previously missing transfer from CLI preflight to Gateway lifetime, agent-specific pending admission and cancellation, and guarded recovery through existing credential/session/model preparation. It also prevents an unavailable inherited auth store from taking healthy agents down. The existing scheduler remains the concurrency owner. The broker composition adds 10 net production lines, reuses the same idempotent admission stop operation, and removes the reused-scope early return that skipped failure cleanup; it adds no parallel work registry.

ClawSweeper Rank-up disposition

The exact-head review found no actionable correctness or security defect. Its additional published-driver × candidate retained-state validation, including the Windows supervisor path, is skipped for this landing under the maintainer instruction to apply or explicitly state-skip Rank-up moves. The existing real SQLite-child, HTTP, guarded-readmission, and broker-lifetime evidence supports the runtime repair; it does not establish published-updater or retained Windows-service compatibility. Migration-required agents remain degraded with Doctor guidance. This proof limitation remains open and is not represented as a passing platform test.

Exact-head CI was reverified on afe7cd506d9bac34615d686419b33e22a06eb063: run 35207940594, GREEN, GitHub rollup SUCCESS, zero pending checks. The recorded Codex review is scoped-clean; no source changes were made for this landing.

@clawsweeper

clawsweeper Bot commented Sep 17, 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.

@steipete
steipete marked this pull request as ready for review September 17, 2026 08:49
@steipete
steipete requested a review from a team as a code owner September 17, 2026 08:49
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 17, 2026
@steipete
steipete force-pushed the upd/sqlite-startup-integrity-budget branch from 5d86a07 to 3f2d72b Compare September 17, 2026 08:57
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 17, 2026, 6:42 AM ET / 10:42 UTC (Revision 3).

ClawSweeper review

What this changes

The PR lets healthy agents serve while slow database inspections continue, then restores deferred agents after credential, session, and model preparation.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful fix absent from fetched main. No actionable introduced defect was found, and the maintainer explicitly disposed of the previous upgrade-proof request.

Priority: P1
Reviewed head: afe7cd506d9bac34615d686419b33e22a06eb063

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent runtime repair with meaningful boundary evidence and no actionable findings; the upgrade-proof exception remains explicit.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured evidence exercises production admission with real SQLite children and HTTP, observing healthy service during refusal, guarded recovery, revoked-write rejection, and shutdown drainage. It supports this internal runtime repair; the expressly skipped updater and Windows-service scenarios are not claimed as passing.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured evidence exercises production admission with real SQLite children and HTTP, observing healthy service during refusal, guarded recovery, revoked-write rejection, and shutdown drainage. It supports this internal runtime repair; the expressly skipped updater and Windows-service scenarios are not claimed as passing.
Evidence reviewed 8 items Current main still lacks deferred admission: Fetched main awaits all scheduled inspections and propagates their failures; it has no foreground-to-background handoff. Earlier merged budget and reader-reuse improvements therefore do not supersede this repair.
Deferred admission retains live ownership checks: Recovery checks cancellation, the pending refusal, deletion state, and file identity, rejects incompatible or migration-required results, and delegates preparation before clearing admission.
Preparation and publication use existing owners: The Gateway verifies configured database paths, guards secrets publication against configuration and revision changes, restricts session preparation to the deferred agent, and requires a current model snapshot.
Findings None None.
Security None None.

How this fits together

Gateway startup checks each agent’s SQLite database before allowing session access. This change transfers unfinished checks into the Gateway lifetime while keeping affected agents unavailable until preparation succeeds.

flowchart TD
  A[Configured agent databases] --> B[Bounded startup inspections]
  B --> C[Healthy agents serve]
  B --> D[Deferred agent stays degraded]
  D --> E[Background inspection]
  E --> F[Guarded credential and session preparation]
  F --> G[Publish models and readmit agent]
  H[Gateway shutdown] --> E
  H --> F
Loading

Before merge

  • Resolve merge risk (P1) - Gateway liveness can succeed while an existing agent remains unavailable; deferred databases requiring migration remain degraded until Doctor repair. Published-updater and retained Windows-supervisor compatibility remain unproven under the recorded scoped exception.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +894, Tests +1095, Docs +37, Other 0. Total +2026 across 38 files.

View PR surface stats
Area Files Added Removed Net
Source 26 1092 198 +894
Tests 9 1113 18 +1095
Docs 2 40 3 +37
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 2 0
Total 38 2247 221 +2026

Review metrics

Metric Value Why it matters
Production versus test growth Production net +894 lines; tests net +1,095 lines The PR explains this growth as lifetime transfer, guarded recovery, and regression coverage while retaining the existing scheduler.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/config/sessions/startup-migration.ts, migration/backfill/repair: src/gateway/server-startup-session-migration.ts, migration/backfill/repair: src/state/agent-database-admission.ts, serialized state: src/agents/auth-profiles/inherited-store.ts, serialized state: src/gateway/server-startup-session-migration.ts, unknown-data-model-change: src/agents/auth-profiles/inherited-store.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #150574
Summary: This PR is the active implementation candidate for the reported fatal slow-database startup path.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Honor the scoped validation exception (recommended)
    Proceed under the recorded maintainer disposition while retaining the explicit updater and Windows-service compatibility limitation.

Technical review

Best possible solution:

Retain the single admission owner and guarded recovery path, with the accepted upgrade-proof limitation and agent-specific repair guidance visible.

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

Yes: current main propagates inspection failure through startup, and the supplied differential fixture demonstrates the timeout trigger. This read-only review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: separating the foreground wait from inspection cancellation preserves integrity checks and reuses existing preparation owners without adding configuration or a competing scheduler.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 15f258319a9a.

Labels

Label justifications:

  • P1: Healthy databases exceeding startup budgets currently prevent affected users' Gateways from serving.
  • merge-risk: 🚨 compatibility: Startup can now report liveness with degraded agents, and retained updater/service behavior has an explicitly accepted proof gap.
  • 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. Sufficient (live_output): The captured evidence exercises production admission with real SQLite children and HTTP, observing healthy service during refusal, guarded recovery, revoked-write rejection, and shutdown drainage. It supports this internal runtime repair; the expressly skipped updater and Windows-service scenarios are not claimed as passing.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured evidence exercises production admission with real SQLite children and HTTP, observing healthy service during refusal, guarded recovery, revoked-write rejection, and shutdown drainage. It supports this internal runtime repair; the expressly skipped updater and Windows-service scenarios are not claimed as passing.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Zhi Xu: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-09-17T09:05:10.237Z sha 3f2d72bbc84647c3d9d49e2a944f0c85969c3b1a :: blocked before merge. :: none
  • reviewed 2026-09-17T10:05:32.301Z sha afe7cd5 :: blocked before merge. :: none

Retain unfinished agent inspections under the Gateway lifetime instead of
turning a foreground timeout into a fatal startup error. Keep the agent
degraded until inspection and guarded credential, session, and model
preparation complete; cancel and join that work during shutdown.

Preserve caller cancellation, propagate failures until background handoff,
and keep inherited auth snapshots within their selected state directory.
Thanks to @desksk for the report and offline integrity timings.

Refs #150574, #141918, #142179, #150444.
@steipete
steipete force-pushed the upd/sqlite-startup-integrity-budget branch from 3f2d72b to afe7cd5 Compare September 17, 2026 09:57
@steipete
steipete merged commit ec9de37 into main Sep 17, 2026
214 checks passed
@steipete
steipete deleted the upd/sqlite-startup-integrity-budget branch September 17, 2026 10:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…150755)

Retain unfinished agent database inspections under the Gateway lifetime so a slow healthy database no longer turns its foreground wait timeout into a fatal startup error. Keep affected agents degraded until inspection and guarded credential, session, and model preparation complete; healthy agents can serve in the meantime. Corruption and pending migrations retain Doctor guidance.

Compose deferred admission with the existing Linux spawn-broker owner. Shutdown cancels and joins retained inspection and preparation before broker cleanup. Preserve caller cancellation, foreground failures before handoff, and inherited auth snapshots within their selected state directory.

Thanks to @desksk for the report and offline integrity timings.

Validation: recorded focused and real SQLite-child/HTTP boundary proof, scoped-clean Codex review, and green exact-head CI. Published-updater and retained Windows-service compatibility remain unverified; the PR records the scoped Rank-up skip.

Closes openclaw#150574.
Related: openclaw#141918, openclaw#142179, openclaw#150444, openclaw#150564.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 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.

Hard-coded 30s SQLite startup integrity/snapshot budget kills gateway on slow disks under concurrent multi-agent preflight (no timeout override)

1 participant