Skip to content

fix(gateway): recover startup under load - #132186

Merged
galiniliev merged 35 commits into
mainfrom
galin/LocaFixesForOCReviewer
Sep 1, 2026
Merged

galiniliev merged 35 commits into
mainfrom
galin/LocaFixesForOCReviewer

Conversation

@galiniliev

@galiniliev galiniliev commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large or partially recovered OpenClaw installations could start slowly without a complete explanation of where time was spent. Repeated workspace skill indexing and duplicate Control UI reconnect bootstrap requests added avoidable work, while a NULL app_version could force unnecessary metadata writes on each reopen.

Windows Gateway operation also lacked durable Task Scheduler supervision for restart, exact process-tree shutdown, and duplicate-start prevention. Backup ACL failures did not always report the actionable path, principal, and rights context. An interactive continuation could emit a visible waiting status yet lose its final outcome if delivery failed before the handoff completed.

Why This Change Was Made

The change adds a reproducible, non-sensitive startup-load fixture and benchmark; makes startup phases attributable through readiness; reuses the skill index for a workspace snapshot; and defers non-readiness-critical work until health is available. It repairs current-schema metadata persistence and the reopen fast path.

It also introduces a Task Scheduler-owned Windows supervisor using the existing Job Object support, separate health/readiness reporting, sanitized ACL diagnostics, failure-total continuation settlement, and a connection-epoch coordinator that bounds and deduplicates non-page Control UI bootstrap requests. No configuration option, SQLite schema version, or paid dependency is introduced.

User Impact

Operators with incident-scale local state receive health availability sooner and a fully attributable path to readiness. Reconnecting Control UI tabs avoid redundant loading. Windows Gateway restarts and shutdowns are owned as a single process tree, backup permission failures identify the data needed to repair access, and every accepted interactive continuation either hands off after its waiting status is delivered or releases terminal delivery on every earlier abort or error.

Evidence

  • Current exact PR head: 3f81742ea3d44c9cc223925e305a983d62ea42ac.
  • Exact-head CI passed: https://github.com/openclaw/openclaw/actions/runs/33464637078. The required openclaw/ci-gate is successful and GitHub reports no failed or pending checks.
  • Focused repair validation passed: 97 provider and transcript-import tests (including the 100k-event, 256 MiB import case); 86 continuation/Control UI bootstrap tests; and 94 daemon lifecycle/readiness tests.
  • The current max-lines ratchet passed with no new suppression or baseline entry. git diff --check also passed.
  • The linked-worktree full local gate remains unavailable because its configured package feed cannot resolve the repository-pinned @pnpm/[email protected]. Exact-head hosted CI is the authoritative full validation.
  • Redacted Windows Scheduled Task evidence confirms InteractiveToken scheduling, Scheduler process ownership, cleanup, and isolated /healthz and /readyz HTTP 200 responses. It is deliberately limited: it was captured on the earlier de210e8 head, and the successful isolated run omitted --task-supervisor after the canonical task-supervisor path exited with Windows result 134. It is not represented as a passing task-supervisor integration test.

@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@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 scripts Repository scripts agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 28, 2026
@galiniliev
galiniliev force-pushed the galin/LocaFixesForOCReviewer branch from 2fc86a9 to a5588fa Compare August 28, 2026 23:03
@galiniliev
galiniliev marked this pull request as ready for review August 28, 2026 23:03
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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. labels Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 29, 2026, 2:17 AM ET / 06:17 UTC.

ClawSweeper review

What this changes

The branch combines Gateway startup and Windows recovery work with agent continuation delivery, SQLite metadata repair, and Control UI reconnect bootstrap changes.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/state/openclaw-agent-db-schema.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Regression provenance

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

Merge readiness

⛔ Blocked by patch quality or review findings - 8 items remain

Keep this protected maintainer PR open: its new continuation handoff can strand a child completion on abort or pre-queue failure, and completed Control UI bootstrap tasks are never eligible to run again.

Priority: P1
Reviewed head: 7c063bf4848fd8775165e292f7068bcd6ce32d94

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has substantial useful reliability work but two concrete delivery/refresh blockers prevent merge readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a protected maintainer PR, so the external-contributor proof gate does not apply; however, its body identifies interactive Windows Scheduled Task proof as still pending, which remains a maintainer-visible availability risk.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a protected maintainer PR, so the external-contributor proof gate does not apply; however, its body identifies interactive Windows Scheduled Task proof as still pending, which remains a maintainer-visible availability risk.
Evidence reviewed 6 items Continuation claim can remain parked: The new settlement is associated with the status payload, but an abort at the following check or a send failure before dispatcher-task registration bypasses every release path; the outer abort handler completes the reply operation without settling the child claim.
Lifecycle blocks the parked child wake: A completed child cannot schedule its requester wake while requesterTurnRunId remains present, which is exactly the state left by the failed continuation settlement.
Existing continuation tests miss the failure window: The new tests cover dispatcher delivery failure after registration, but not an abort before status dispatch or a pre-queue send rejection.
Findings 2 actionable findings [P1] Release continuations on every pre-queue finalization failure
[P2] Evict fulfilled bootstrap tasks before repeat refreshes
Security None None.

How this fits together

Gateway startup binds health/readiness before initializing runtime services. Agent continuation results and Control UI connection events then use delivery and bootstrap coordinators to reach users and the browser.

flowchart LR
A[Gateway startup] --> B[Health and readiness]
B --> C[Runtime services]
C --> D[Continuation delivery]
B --> E[Control UI connection]
E --> F[Bootstrap coordinator]
D --> G[User-visible completion]
Loading

Before merge

  • Release continuations on every pre-queue finalization failure (P1) - The new settlement is only released on ordinary delivery branches. An abort at line 115 or a rejected sendFinalPayload at line 155 exits before registration at line 190, leaving requesterTurnRunId set; the lifecycle waker then refuses the completed child. Release once with settle(false) on every such exit and add abort-before-status and send-rejection coverage.
  • Evict fulfilled bootstrap tasks before repeat refreshes (P2) - Only rejected work deletes its key. After a successful run, later same-key calls return the already-fulfilled promise instead of refreshing; the approval access-transition path can therefore never refresh again for that connection. Delete the current-generation key after fulfillment too and cover success-then-repeat behavior.
  • Resolve merge risk (P1) - The stated native interactive Windows Scheduled Task proof is still absent, so restart and process-tree ownership remain unverified on the platform this code changes.
  • Resolve merge risk (P1) - The branch has material net growth across several runtime owners; the available checkout cannot reconstruct a complete production-versus-test split from the pinned base.
  • Complete next step (P2) - This protected maintainer PR needs its two concrete blockers resolved and its platform evidence reviewed; it is not an automated repair-lane candidate.
  • Improve patch quality - Release continuation ownership on abort and pre-queue send failure, with focused regressions.
  • Improve patch quality - Evict fulfilled connection-bootstrap work and add a successful repeat-refresh test.
  • Improve patch quality - Provide the stated interactive Windows supervisor proof.

Findings

  • [P1] Release continuations on every pre-queue finalization failure — src/auto-reply/reply/dispatch-from-config.finalize.ts:91-115
  • [P2] Evict fulfilled bootstrap tasks before repeat refreshes — ui/src/app/connection-bootstrap.ts:50-56
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta overall +4,001/-1,167; complete production/test split unavailable from the pinned base The supplied PR statistics show substantial growth across core runtime owners, while required base blobs are unavailable locally for a reliable classification.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-agent-db-schema.ts, serialized state: src/daemon/schtasks.task-supervisor.native-test-support.ts, serialized state: src/state/openclaw-agent-db-schema.ts, serialized state: ui/src/lib/sessions/index.ts, unknown-data-model-change: src/state/openclaw-agent-db-schema.ts, unknown-truncated-pull-files, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair terminal settlement (recommended)
    Release continuation ownership on every abort or pre-queue finalization error and cover both failure paths before merge.
  2. Complete Windows supervisor validation
    Attach redacted interactive-session evidence for Scheduled Task restart, shutdown, and process-tree ownership before accepting the platform-specific risk.

Technical review

Best possible solution:

Use a one-shot continuation-settlement owner that releases child delivery on every pre-queue abort/error, evict bootstrap keys after both fulfillment and rejection, and then validate the native Windows supervisor path.

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

Yes—source-reproducible. An abort at finalization entry or a rejected status send occurs after child ownership is held but before any false settlement is registered, while the lifecycle waker rejects that held state.

Is this the best way to solve the issue?

No. The branch needs failure-total continuation release and successful-task eviction; these are narrower owner-boundary repairs than adding retries or downstream fallbacks.

Full review comments:

  • [P1] Release continuations on every pre-queue finalization failure — src/auto-reply/reply/dispatch-from-config.finalize.ts:91-115
    The new settlement is only released on ordinary delivery branches. An abort at line 115 or a rejected sendFinalPayload at line 155 exits before registration at line 190, leaving requesterTurnRunId set; the lifecycle waker then refuses the completed child. Release once with settle(false) on every such exit and add abort-before-status and send-rejection coverage.
    Confidence: 0.96
  • [P2] Evict fulfilled bootstrap tasks before repeat refreshes — ui/src/app/connection-bootstrap.ts:50-56
    Only rejected work deletes its key. After a successful run, later same-key calls return the already-fulfilled promise instead of refreshing; the approval access-transition path can therefore never refresh again for that connection. Delete the current-generation key after fulfillment too and cover success-then-repeat behavior.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The introduced continuation path can leave an interactive child completion permanently parked after a dispatch abort or send failure.
  • merge-risk: 🚨 message-delivery: The PR changes terminal continuation ownership and currently has a concrete path that suppresses the eventual completion.
  • merge-risk: 🚨 availability: It changes startup readiness and Windows service supervision without the stated native interactive proof.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a protected maintainer PR, so the external-contributor proof gate does not apply; however, its body identifies interactive Windows Scheduled Task proof as still pending, which remains a maintainer-visible availability risk.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: History shows recent repairs to failed queued replies and gateway-owned turn lifecycle on the affected owner boundary. (role: recent delivery and lifecycle contributor; confidence: high; commits: efde610a9f64, 6515f6a2555d; files: src/auto-reply/reply/dispatch-from-config.finalize.ts, src/agents/subagents/registry/subagent-registry-lifecycle-wake.ts)
  • Ayaan Zaidi: History on the finalization path includes restart-replay and continuation-delivery fixes. (role: recent delivery-path contributor; confidence: medium; commits: 210aca6de387; files: src/auto-reply/reply/dispatch-from-config.finalize.ts)
  • Vyctor H. Brzezowski: Recent history on the overlays approval-refresh surface includes Control UI refresh work. (role: adjacent Control UI contributor; confidence: medium; commits: 83978aec63a9; files: ui/src/app/overlays.ts, ui/src/app/connection-bootstrap.ts)

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 (8 earlier review cycles)
  • reviewed 2026-08-28T23:12:41.887Z sha a5588fa :: needs maintainer review before merge. :: none
  • reviewed 2026-08-29T02:04:38.099Z sha a5588fa :: found issues before merge. :: [P2] Clear completed bootstrap tasks
  • reviewed 2026-08-29T03:35:16.542Z sha fedefa7 :: found issues before merge. :: [P1] Release implicit continuations when reply preparation fails | [P2] Clear fulfilled bootstrap tasks
  • reviewed 2026-08-29T04:32:07.878Z sha 6e8ab9d :: found issues before merge. :: [P1] Probe TLS gateways with their configured HTTPS endpoint
  • reviewed 2026-08-29T05:14:46.533Z sha 849bdfa54c0e62ac4ddc1b80788548050f427e86 :: needs changes before merge. :: [P1] Distinguish collector spawns from completion children | [P2] Do not cache fulfilled bootstrap work for a connection epoch
  • reviewed 2026-08-29T05:25:04.113Z sha 557090c1f9508ea2f6436acdcc8dee5b4d4418f6 :: needs changes before merge. :: [P1] Distinguish collector spawns from completion children
  • reviewed 2026-08-29T05:45:26.480Z sha 090a27aa4a84a5ad1fb089c4fb79fa7d75c5b28b :: found issues before merge. :: [P2] Clear fulfilled bootstrap tasks before allowing another refresh
  • reviewed 2026-08-29T06:06:16.784Z sha 8f9fd730dfdd884d0627049bfed1e92788f6fd7d :: found issues before merge. :: [P1] Propagate visible-child completion ownership | [P2] Evict settled bootstrap tasks before repeat refreshes

@galiniliev galiniliev self-assigned this Aug 29, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 29, 2026
@galiniliev
galiniliev force-pushed the galin/LocaFixesForOCReviewer branch from f60711f to fedefa7 Compare August 29, 2026 03:24
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Aug 29, 2026
@galiniliev
galiniliev force-pushed the galin/LocaFixesForOCReviewer branch from 6e8ab9d to 849bdfa Compare August 29, 2026 05:04
@galiniliev

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 29, 2026
@galiniliev
galiniliev force-pushed the galin/LocaFixesForOCReviewer branch from de210e8 to 9ee827c Compare September 1, 2026 02:46
@galiniliev

Copy link
Copy Markdown
Contributor Author

Windows Scheduled Task evidence (limited)

Redacted Windows evidence was captured on September 1, 2026 for PR head de210e8fb9e48efde045d0cc52c967ed9a1abcf0 (the current PR head is newer).

  • The generated task used InteractiveToken (Task Scheduler logon type 3) and LeastPrivilege.
  • Task Scheduler owned the process chain: node.exe -> cmd.exe -> wscript.exe -> svchost.exe -s Schedule.
  • The isolated Gateway returned HTTP 200 from /healthz at 52,011 ms and /readyz at 52,071 ms after schtasks /Run.
  • The default Gateway remained on its original port; the temporary task/profile and proof port were removed afterward.

This is proof of InteractiveToken scheduling, Scheduler ownership, endpoint reachability, and cleanup only. It is not a passing task-supervisor integration result: the canonical --task-supervisor scenario exited with Windows result 134 before the Gateway bound its port, and the successful isolated run omitted that option. The original raw logs and artifacts remain private because they contain machine-specific paths and failed exploratory attempts.

@galiniliev

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@galiniliev
galiniliev merged commit 14e26a3 into main Sep 1, 2026
274 checks passed
@galiniliev
galiniliev deleted the galin/LocaFixesForOCReviewer branch September 1, 2026 06:09
@galiniliev

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
* fix(gateway): recover startup under load

* fix(ci): preserve gateway recovery checks after rebase

* refactor(ui): split bootstrap theme runtime

* fix(ui): handle reactive gateway refreshes

* fix(agents): preserve yielded requester settlement

* fix(cli): cover gateway readiness mocks

* test(ui): await scheduled profile appearance refresh

* fix(ci): keep daemon lifecycle suite within its limit

* fix(gateway): probe TLS readiness

* fix(gateway): remove unused probe exports

* fix(agents): gate continuations on completion owners

* refactor(agents): isolate ACP spawn results

* fix(ui): remove duplicate bootstrap ownership

* fix(ui): compact reconnect bootstrap work

* fix: complete continuation and bootstrap cleanup

* refactor(reply): split deferred final flush

* fix(ci): restore startup checks

* perf(ui): compact connection bootstrap

* perf(ui): defer connection bootstrap scheduler

* test(ui): await deduplicated bootstrap work

* test(ci): track qa setup suppression

* test(infra): split media persistence fixtures

* fix(ci): restore daemon lifecycle fixture

* test(auto-reply): cover revoked continuation delivery

* fix(ci): clear rebase lint drift

* test(agents): split terminal resolution state coverage

* fix(daemon): preserve interactive task logon

* fix(gateway): load current TLS runtime

* test(cli): align TLS probe mock

* perf(ui): defer workshop admission owner

* chore(ui): refresh boot manifest

* fix(ui): keep session roster immediate

* fix(reply): release continuation after commentary failure

* fix(ui): capture connected client for bootstrap work

* test(cli): keep lifecycle mock within lint budget

---------

Co-authored-by: Galin Iliev <[email protected]>
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 docs Improvements or additions to documentation 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant