Skip to content

fix(exec): recover after doctor migration without gateway restart - #118769

Merged
steipete merged 1 commit into
mainfrom
fix/execgate
Aug 3, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/execgate

Conversation

@steipete

@steipete steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Closes #118762

What Problem This Solves

Fixes an issue where agents using exec could remain blocked by a legacy-approvals migration error after an operator had successfully run openclaw doctor --fix. Because the running Gateway retained the refusal until restart, repeating the prescribed repair did not restore exec.

Why This Change Was Made

The migration gate cached both absence and presence for the process lifetime. A Gateway that observed the retired JSON or Doctor's temporary claim therefore kept treating that observation as current even when a separate Doctor CLI process removed the state.

The gate now caches only the steady-state absence. A real source or .doctor-importing claim still fails closed with the same typed, actionable error, but that positive observation is re-probed on the next attempt. This keeps the normal path free of repeated filesystem work and makes a completed separate-process Doctor migration visible without cross-process signaling.

The existing source-claim-source probe already bounds Doctor's rename window. A settle timer or retry delay would add timing policy without improving the required invariant: if an attempt overlaps the rename/removal window, it may fail closed once, then the next attempt re-probes. The obsolete same-process cache-reset hook was removed so correctness no longer depends on which process runs Doctor.

User Impact

After Doctor migrates and removes retired exec-approval state, the next exec attempt can proceed without restarting the Gateway. Exec remains blocked while either the legacy source or Doctor claim genuinely exists.

Evidence

Observed before the repair on maintainer build 39c506b: the Gateway continued returning ExecApprovalsMigrationRequiredError after a separate doctor --fix completed, and recovered only after restart.

Focused gate/store/Doctor proof:

$ node scripts/run-vitest.mjs src/infra/exec-approvals-store.test.ts src/infra/state-migrations.exec-approvals.test.ts
Test Files  2 passed (2)
Tests  33 passed (33)
[test] passed 1 Vitest shard in 7.27s

The regression runs the real filesystem order for both exec-approvals.json and .doctor-importing: present -> same typed/actionable error -> remove without reset -> next store call succeeds.

Exec and node-host caller proof:

$ node scripts/run-vitest.mjs src/agents/bash-tools.exec.security-floor.test.ts src/node-host/invoke-system-run.test.ts
Test Files  1 passed (1) / Tests  81 passed (81)
Test Files  1 passed (1) / Tests  15 passed (15)
[test] passed 2 Vitest shards in 16.17s

Touched-file gate:

$ node scripts/check-changed.mjs -- src/infra/exec-approvals-migration-gate.ts src/infra/exec-approvals-store.test.ts src/infra/state-migrations.exec-approvals.ts
exit 0

This covered formatting, production/test typechecks, targeted lint, Plugin SDK and dependency guards, dead exports, native schema v6, database-first legacy-store rules, runtime import cycles, and the remaining core architecture guards.

Codex autoreview: clean, no accepted/actionable findings (gpt-5.6-sol, high reasoning, 0.98 confidence).

LOC: production +13/-19 (net -6); tests +30/-13 (net +17). No config, schema, protocol, or public API changes.

@steipete
steipete marked this pull request as ready for review August 3, 2026 16:42
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 3, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 12:47 PM ET / 16:47 UTC.

ClawSweeper review

What this changes

The PR changes the exec-approval migration gate to cache only confirmed absence, allowing a long-lived Gateway to recover on its next exec attempt after a separate Doctor process removes legacy approval state.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this maintainer-labeled PR open for normal merge review. The patch fixes the confirmed cross-process cache-ownership bug without weakening the existing fail-closed source/claim check, and its focused regression covers the required present → removed → next read succeeds sequence.

Priority: P1
Reviewed head: c65258b631b695069cc0d9a4a7ddc324b66dc382

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-scoped repair with direct regression coverage and credible terminal evidence for the recovered runtime behavior.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body records the observed long-lived-Gateway failure on a maintainer build, focused terminal proof for the real filesystem state transition, and caller-level regression runs; no sensitive data is exposed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body records the observed long-lived-Gateway failure on a maintainer build, focused terminal proof for the real filesystem state transition, and caller-level regression runs; no sensitive data is exposed.
Evidence reviewed 5 items Current-main defect: Current main caches both a positive and negative legacy-state probe in legacyPresenceCache; after a Gateway sees the retired source or Doctor claim once, later calls keep throwing without probing filesystem state again.
Doctor lifecycle owner: Doctor first claims the legacy source under the .doctor-importing suffix, writes and verifies the canonical SQLite record, then removes the claim/source; the prior cache-reset hook only affected the process that ran Doctor.
Patch preserves the safety invariant: The proposed gate still performs the source → claim → source probe and throws whenever any probe sees legacy state, but only records a completed absence; positive observations are retried on the next caller attempt.
Findings None None.
Security None None.

How this fits together

Before agent shell execution can read the SQLite exec-approval store, Gateway and node-host callers pass through a migration gate that blocks retired JSON approval state. The Doctor CLI claims, migrates, and removes that retired state, after which the running process must observe the completed migration without a restart.

flowchart LR
  LegacyState[Legacy approval file or Doctor claim] --> Gate[Exec migration gate]
  Doctor[Doctor migration process] --> LegacyState
  Gateway[Gateway exec request] --> Gate
  NodeHost[Node-host exec request] --> Gate
  Gate --> Store[SQLite approval store]
  Store --> Exec[Agent shell execution]
Loading

Before merge

  • Complete next step (P2) - This open, maintainer-labeled PR already owns the linked repair; it needs normal merge review rather than a separate automated fix lane.
Agent review details

Security

None.

PR surface

Source -6, Tests +17. Total +11 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 13 19 -6
Tests 1 30 13 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 43 32 +11

Review metrics

Metric Value Why it matters
Production vs test delta production -6 net, tests +17 net The repair removes the same-process cache-reset path while adding direct regression coverage for both legacy-state forms.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/exec-approvals-store.test.ts, migration/backfill/repair: src/infra/state-migrations.exec-approvals.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #118762
Summary: This PR is the concrete candidate repair for the linked exec migration-gate regression.

Members:

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

Technical review

Best possible solution:

Land the focused cache-ownership repair after the remaining required checks complete, retaining the source/claim probe and the new regression that proves recovery without a Gateway restart.

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

Yes, from current-main source and the PR's stated live observation: make the gate see exec-approvals.json or .doctor-importing, remove it through a separate Doctor process, then retry exec in the unchanged Gateway process.

Is this the best way to solve the issue?

Yes. Caching only authoritative absence fixes the actual process-boundary ownership error while retaining the existing fail-closed probe whenever a source or active Doctor claim exists.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The defect blocks a live Gateway's agent exec workflow after the prescribed Doctor repair until the operator restarts it.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records the observed long-lived-Gateway failure on a maintainer build, focused terminal proof for the real filesystem state transition, and caller-level regression runs; no sensitive data is exposed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body records the observed long-lived-Gateway failure on a maintainer build, focused terminal proof for the real filesystem state transition, and caller-level regression runs; no sensitive data is exposed.

Label justifications:

  • P1: The defect blocks a live Gateway's agent exec workflow after the prescribed Doctor repair until the operator restarts it.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body records the observed long-lived-Gateway failure on a maintainer build, focused terminal proof for the real filesystem state transition, and caller-level regression runs; no sensitive data is exposed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records the observed long-lived-Gateway failure on a maintainer build, focused terminal proof for the real filesystem state transition, and caller-level regression runs; no sensitive data is exposed.

Evidence

What I checked:

  • Current-main defect: Current main caches both a positive and negative legacy-state probe in legacyPresenceCache; after a Gateway sees the retired source or Doctor claim once, later calls keep throwing without probing filesystem state again. (src/infra/exec-approvals-migration-gate.ts:45, 36a2b5b00b3f)
  • Doctor lifecycle owner: Doctor first claims the legacy source under the .doctor-importing suffix, writes and verifies the canonical SQLite record, then removes the claim/source; the prior cache-reset hook only affected the process that ran Doctor. (src/infra/state-migrations.exec-approvals.ts:257, 36a2b5b00b3f)
  • Patch preserves the safety invariant: The proposed gate still performs the source → claim → source probe and throws whenever any probe sees legacy state, but only records a completed absence; positive observations are retried on the next caller attempt. (src/infra/exec-approvals-migration-gate.ts:47, c65258b631b6)
  • Regression coverage: The changed store test exercises both the retired source and the Doctor claim: it observes the typed migration error, removes the observed path without an in-process reset, and confirms the following store read succeeds. (src/infra/exec-approvals-store.test.ts:386, c65258b631b6)
  • Feature provenance: The current migration gate and Doctor reset path were introduced by the same recent exec-approvals feature commit; this PR replaces that same-process-only reset design with a cross-process-safe cache rule. (src/infra/exec-approvals-migration-gate.ts:45, 3c085c18728b)

Likely related people:

  • steipete: The current migration gate, exec-approval store, Doctor migration flow, and this narrow cross-process repair all trace to Peter Steinberger commits; the GitHub context identifies the corresponding handle as steipete. (role: feature introducer and recent area contributor; confidence: high; commits: 3c085c18728b, c65258b631b6; files: src/infra/exec-approvals-migration-gate.ts, src/infra/exec-approvals-store.ts, src/infra/state-migrations.exec-approvals.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.

@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

ClawSweeper follow-up for head c65258b631b695069cc0d9a4a7ddc324b66dc382:

The latest review contains no Rank-up moves: section, so there are no moves to apply or skip. Its sole remaining “Before merge” item is normal maintainer review. Exact-head CI is green and the fresh post-CI Codex autoreview is clean; proceeding through the required scripts/pr review-artifact, prepare, and merge workflow.

@steipete
steipete merged commit 768e1f9 into main Aug 3, 2026
183 of 194 checks passed
@steipete
steipete deleted the fix/execgate branch August 3, 2026 16:55
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR 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.

exec tool stays blocked after doctor --fix until gateway restart (migration gate caches positive verdict)

1 participant