Skip to content

fix(update): prevent candidate Doctor authority stack overflows - #157273

Merged
steipete merged 2 commits into
mainfrom
upd/update-history-reconciliation-overflow
Sep 24, 2026
Merged

steipete merged 2 commits into
mainfrom
upd/update-history-reconciliation-overflow

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Fixes #157011. Thanks @yoyo837 for the report and retained failure evidence.

What Problem This Solves

Chat-triggered managed updates can roll back during candidate Doctor with authority-check-failed: Maximum call stack size exceeded, even on the first attempt.

User Impact

The candidate can finish Doctor while retaining failed update history and continuing to reject revoked requesters. The repair needs no history reset, schema migration, new option, or dependency change.

Why This Change Was Made

The recursion is a callback cycle at the shared SQLite maintenance-admission owner:

getCachedOpenClawStateDatabase
  → maintenance.assertAdmission / assertOwnerCurrent
  → candidate Doctor assertCurrent → requester.isCurrent
  → readCurrentConfigForPolicyCheck → readDeferredPluginMigrations
  → cached read → getCachedOpenClawStateDatabase

Profile-backed requesters can also re-enter through their identity lookup, but configured owners already reproduce the defect. Warning text mentioning another run or a macOS path is not traversed as a graph. Reconciliation reads bounded ledger rows; rewriting that valid history would not fix this call cycle.

The canonical synchronous read adapter now uses read admission. It preserves the maintenance scope and its resource custody, checks lifecycle closure, and skips only an authority callback already evaluating its own policy rows. Other scope checks still run. Full effect admission rejects recursive effects, and revocation remains enforced after asynchronous work. An initial autoreview finding about a separately revoked child scope was fixed and covered by regression.

Importer validation also caught an outdated repair-refusal assertion after 7815be4d94e8 (#156472) improved the ownership diagnostic. That existing E2E now checks the JSON refusal's exact run ID, requested phase, and missing driver/liveness evidence; all ledger-preservation, Gateway-health, and subsequent repair checks remain.

Release behavior: e1c2a0b476e introduced the maintenance owner callback after 2026.9.5; tagged 2026.9.6 contains it. Standalone Doctor lacks the candidate's requester callback, and 9.5 lacks this maintenance callback altogether. This is a candidate-side correction reachable through the installed updater; retained failed runs do not require an old-driver patch or data backport. The fix must be included in a corrective release for users targeting 2026.9.6; existing tags should not be rewritten. No release or backport is performed by this PR.

Reporter questions: There is no supported retained-history reset. update cleanup retires eligible recovery originals, and current update repair finishes/reconciles update work; neither clears the ledger. For the JS stack, NODE_OPTIONS=--stack-trace-limit=200 only increases the stored stack depth: it does not make 9.6's message-only catch emit frames in stderrTail. Maintainers can run the new requester regression against the pre-fix owner with NODE_OPTIONS=--stack-trace-limit=200 pnpm test src/infra/update-requester-authority.test.ts --maxWorkers=1; Vitest prints the caught error stack. For the released worker itself, a caught-exception debugger or instrumented isolated candidate is needed. Another production retry solely for a stack is unnecessary.

Evidence

  • Pre-fix regression failed with RangeError: Maximum call stack size exceeded through the exact cache/admission/requester chain. Its test body took 2.101s; the heavily loaded Mac's shared transform/setup dominated the 593.46s file wall time.
  • Final focused suites passed 3× on Linux Testbox with --maxWorkers=1: 14 tests across the requester and maintenance-scope files; command walls 34.64s, 15.22s, 15.22s. Warm file durations: requester 12.51s, scope 0.574s. The 500-run regression took 4.807s, two-run cases 72/81ms, and nested-authority regression 2ms. Coverage includes configured/profile requesters, prior-run references, macOS migration warnings, revocation, nested effects, and resource cleanup.
  • node scripts/check-changed.mjs --base 5331425e597912be4b7113a4e045d60b3b5d9170 passed on Testbox, including core typechecking, all 25 test type graphs, lint, formatting, docs and applicable guards. A first check against moving origin/main selected unrelated reverse differences; using this lane's actual base corrected that scope.
  • Real npm 2026.9.5 (ec9c1a1) installation and standalone Doctor passed in isolated HOME/state/config/workspace on Linux Node 24.19.0. The built candidate's real Doctor flow, with current requester authority, then returned {"exitCode":0,"status":"ok"}, with no refusal or failure facts. Reconciliation preserved every record at 2 and 500 retained runs, taking 35.000s cold / 26.916s respectively (worker startup dominates; no history-proportional recursion). Runtime build passed in 83.5s; final Doctor took 131.744s. Published-state Doctor proof, lease tbx_01m39fdxcw0bqrjvfak1t7f29f.
  • This is candidate Doctor-step isolation, not a full managed update. Two broader source-Doctor attempts hit an unrelated Ollama capture error resolving @openclaw/model-catalog-core; the final synthetic fixture used existing plugins.entries.ollama.enabled=false, preserving requester configuration and all history. Full declaration preparation also stalled after context canceled; supported runtime-only builds were used for JS consumers while the separate type gates remained enabled.
  • The corrected existing ownership E2E passed 7/7, with 129.829s test time / 154.963s one-worker wall. Its explicit-path check:changed --base 10063393421798eae5a3dbf435109d0d01852caf -- test/gateway-external-state-ownership.e2e.test.ts passed, including the root-test type graph and all selected guards/lint. Proof, lease tbx_01m39kyjwwyzvhkgna76h8g4he.
  • The 1,497-file importer inventory was exercised/accounted for as detailed below. The broader sweep retains 18 baseline-reproduced test failures and one unresolved teardown failure; it is not claimed green.
  • Fresh Codex autoreview through P2 used --mode branch --base origin/main and returned scoped-clean for final head 7e4d071996ad374344b4cfa6b8f47764c1a98912. All task-owned Testboxes are stopped.

Production/test/docs LOC: +45/−11 production, +137/−3 tests, +15 docs. No unrelated fixture experiment remains in the diff. Hosted PR CI and its timings are pending.

Importer sweep and remaining validation gaps

The direct-importer and one-barrel lists contain 1,497 files. All groups use isolated Blacksmith Testboxes, fixed input order and source-hash assertions. Existing platform/live opt-ins remain respected.

Group Files Passing tests Result
Barrel 1 213 3,803 210 passed files; 2 platform skips; 1 credential-gated live skip
Barrel 2 214 3,550 213 passed files; 1 Windows-only skip
Barrel 3 213 3,800 211 passed files; 1 Windows-only skip; 15 baseline-confirmed failures
Barrel 4 214 3,836 212 passed files; 1 existing skip; 1 unresolved teardown failure
Barrel 5 213 3,306 212 passed files; 1 Windows-only skip
Barrel 6 214 2,809 211 passed files; 1 Windows-only skip; 2 baseline-confirmed failures; 1 live-provider file excluded
Direct importers 216 4,314 in initial sweep 211 passed files; 2 platform skips; 2 initial failing files; 1 live-only file excluded. Ownership assertion subsequently repaired and its whole file passed 7/7.

src/flows/doctor-health.update-schema.test.ts produced 15 ENOENT realpath("\\") failures after the Windows-path fixture. The same eight-file order reproduced them on unchanged base 5331425e5979. Cleanup experiments passed reused runs but failed cold validation and were removed. Remaining 205 files in that group passed.

test/oauth-refresh-authority-chain.e2e.test.ts:616 and :722 returned undefined from shared-credential readback; both failures reproduced in the original 14-file order on the unchanged base. Preceding refresh assertions passed. The swallowed read rejection remains unidentified. The baseline also showed a requester-status failure that passed on the candidate. An optional diagnostic/native-skip attempt was blocked before execution by a two-minute provider sync timeout.

src/gateway/session-transcript-readers.test.ts passed all 16 assertions but failed teardown with Agent database resource drainage failed / WorkerTaskError: worker exited with code 1. A bounded 43-file candidate/baseline comparison passed 613 tests on each, but Vitest changed scheduling relative to the larger run. That does not establish a fix or clear the original intermittent failure; synchronous fixture closure versus async drainage remains only a hypothesis.

The direct E2E group also reproduced retains ambiguous Discord announcement custody after an unidentified send on unchanged base: candidate 108.857s, baseline 116.927s, both timing out at the compound settlement predicate (task complete, delivery ambiguous, numeric next attempt, queue row, and expected log). The fixture removes diagnostics during cleanup, so the unmet term is still unknown. The baseline was stopped after reproducing both initial failures, before redundant rendering cases; it is not reported as a completed passing run. The stale ownership assertion is the only additional test repair retained.

Exact Windows-mock baseline input order (--maxWorkers=4):

src/flows/doctor-gateway-token-repair.test.ts
src/flows/doctor-health-contribution-runners.state.paths.test.ts
src/flows/doctor-health-contributions.auth-import-order.test.ts
src/flows/doctor-health-contributions.windows-cloud-state.test.ts
src/flows/doctor-health.deletion-recovery.test.ts
src/flows/doctor-health.unsupported-state.test.ts
src/flows/doctor-health.update-budget.test.ts
src/flows/doctor-health.update-schema.test.ts

Exact direct E2E baseline input order (OPENCLAW_E2E_USE_PREBUILT_DIST=1, --maxWorkers=4):

test/gateway-external-state-ownership.e2e.test.ts
test/e2e/gateway-transcripts-discord-capture.e2e.test.ts
test/e2e/qa-lab/runtime/channel-progress-presentation.e2e.test.ts
src/daemon/schtasks.integration.e2e.test.ts

Validation used native Blacksmith Testboxes after the repository wrapper stalled in source staging. Some full declaration preparations stalled after context canceled; JS/private-QA preparation used the existing skip-declarations and prebuilt-dist controls, with type gates run separately. Native resync also hit two-minute full-sync failures. One fresh testbox retained hydration Git metadata despite matching source bytes; the task's Git bundle corrected only HEAD/index, then the sole test diff and all source hashes were reverified before testing. No source, ignore, baseline, retry, or timeout workaround was used. Slow pre-existing files were recorded under the campaign's explicit waiver.

These results do not claim the whole importer sweep or CI is green.

@clawsweeper

clawsweeper Bot commented Sep 24, 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 24, 2026 12:19
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Sep 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 24, 2026, 5:55 PM ET / 21:55 UTC (Revision 3).

ClawSweeper review

What this changes

The branch changes shared SQLite admission so candidate Doctor can read requester policy during an authority check, adds regression tests, and documents recovery guidance.

Regression provenance

Possible regression — suspected (failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open. Current main still has the admission cycle implicated by the linked managed-update failures, and the proposed repair is focused. The remaining merge gate is an end-to-end upgrade from the published updater into this candidate.

Priority: P0
Reviewed head: d91641e6b76fb354b2e24d1443e5fd92b255a89a

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair and candidate Doctor result give useful confidence, while the required complete released-updater path is still unproven.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (terminal): The PR body reports a pre-fix overflow and an after-fix status-ok result through built candidate Doctor on isolated npm 2026.9.5 state with retained runs. That exercises the changed read-admission behavior; the separate full published-updater handoff remains a compatibility gate. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body reports a pre-fix overflow and an after-fix status-ok result through built candidate Doctor on isolated npm 2026.9.5 state with retained runs. That exercises the changed read-admission behavior; the separate full published-updater handoff remains a compatibility gate. No stored-data contract changes.
Evidence reviewed 9 items Introduced repair: The pinned PR delta adds a separate admission path for cached reads, suppresses only a reentrant check of the same scope, and retains full admission for effects.
Current-main behavior: The fetched main revision still calls full maintenance admission when obtaining a cached database, including for the policy-read path.
Candidate Doctor boundary: Delegated Doctor checks the executor fence and current requester before running Doctor; a failed check records an authority refusal.
Findings None None.
Security None None.

How this fits together

A chat-triggered update passes requester authority from the installed updater to candidate Doctor. Doctor reads configuration and shared SQLite state before it records the validation result and the updater completes or rolls back.

flowchart LR
A[Chat update request] --> B[Installed updater]
B --> C[Candidate Doctor]
C --> D[Requester check]
D --> E[SQLite policy read]
E --> F[Maintenance read admission]
F --> G[Doctor and update result]
Loading

Before merge

  • Resolve merge risk (P1) - A published 2026.9.5 updater has not been shown completing a chat-managed upgrade into this candidate with retained history. Candidate Doctor success alone does not establish the handoff, finalization, and recovery outcome for existing installations.
  • Complete next step (P2) - Capture one isolated chat-managed update from published 2026.9.5 into this candidate with retained history, recording candidate Doctor, finalization, and Gateway or rollback outcomes before merge.
Agent review details

Security

None.

PR surface

Source +34, Tests +134, Docs +15. Total +183 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 45 11 +34
Tests 3 137 3 +134
Docs 1 15 0 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 197 14 +183

Review metrics

Metric Value Why it matters
Production and test growth production net +34 lines; tests net +134 lines The production growth serves one shared admission repair, with regression coverage for history and revocation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #157011
Summary: This PR is the candidate repair for the linked candidate Doctor failure; the merged repair-diagnostic PR addressed separate refusal wording.

Members:

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

Merge-risk options

Maintainer options:

  1. Prove the released updater handoff (recommended)
    Run the published 2026.9.5 updater into this candidate in isolated retained state and capture Doctor, finalization, and Gateway outcomes.

Technical review

Best possible solution:

Land the candidate-side admission repair after an isolated published-2026.9.5-to-candidate managed update demonstrates completion with retained history and a recorded Gateway outcome, then include the fix in a corrective release.

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

Yes. Current main's cached policy read can reenter full maintenance admission during candidate Doctor authority checking, and the linked report documents repeated released-version failures; this read-only review did not execute the regression.

Is this the best way to solve the issue?

Yes. Separating reentrant policy reads from effect admission addresses the shared callback cycle while retaining revocation checks; clearing update history would not fix it.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P0: The linked report documents users blocked from managed update who needed manual package installation to proceed.
  • merge-risk: 🚨 compatibility: A released updater must hand control to this candidate safely, and the complete upgrade path remains unproven.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body reports a pre-fix overflow and an after-fix status-ok result through built candidate Doctor on isolated npm 2026.9.5 state with retained runs. That exercises the changed read-admission behavior; the separate full published-updater handoff remains a compatibility gate. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports a pre-fix overflow and an after-fix status-ok result through built candidate Doctor on isolated npm 2026.9.5 state with retained runs. That exercises the changed read-admission behavior; the separate full published-updater handoff remains a compatibility gate. No stored-data contract changes.

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)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Capture an isolated managed update driven by published 2026.9.5 into this candidate, including Doctor completion and finalization with retained history.

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-24T12:27:05.784Z sha 7e4d071 :: blocked before merge. :: none
  • reviewed 2026-09-24T17:25:33.351Z sha ab252d1 :: blocked before merge. :: none

@steipete
steipete enabled auto-merge (squash) September 24, 2026 12:28
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Sep 24, 2026
@steipete
steipete disabled auto-merge September 24, 2026 20:46
Keep synchronous policy reads within their maintenance resource scope without recursively evaluating the same authority callback. Preserve independent parent and child checks, reject nested effects, and retain update history. Cover configured and profile requesters, revocation, nested scopes, and 500 retained runs.

Reported by @yoyo837 in #157011.
Assert the current CLI JSON refusal with its run, phase, and driver liveness evidence. Preserve the existing checks that active history and the serving Gateway are unchanged before inactive-run repair.
@steipete
steipete force-pushed the upd/update-history-reconciliation-overflow branch from ab252d1 to d91641e Compare September 24, 2026 21:46
@steipete
steipete enabled auto-merge (squash) September 24, 2026 22:02
@steipete
steipete merged commit 44e7181 into main Sep 24, 2026
217 checks passed
@steipete
steipete deleted the upd/update-history-reconciliation-overflow branch September 24, 2026 22:35
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…claw#157273)

* fix(update): prevent candidate Doctor authority stack overflows

Keep synchronous policy reads within their maintenance resource scope without recursively evaluating the same authority callback. Preserve independent parent and child checks, reject nested effects, and retain update history. Cover configured and profile requesters, revocation, nested scopes, and 500 retained runs.

Reported by @yoyo837 in openclaw#157011.

* test(update): verify structured repair ownership refusals

Assert the current CLI JSON refusal with its run, phase, and driver liveness evidence. Preserve the existing checks that active history and the serving Gateway are unchanged before inactive-run repair.
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant