Repository navigation
fix(doctor): import historical exec approval metadata - #118282
Conversation
|
Codex review: passed. Reviewed August 31, 2026, 1:55 AM ET / 05:55 UTC. ClawSweeper reviewWhat this changesThe PR lets Doctor import retired exec-approval JSON with two historical null usage fields and performs that import before config-dependent migration work. Merge readinessKeep open: current main still lacks the migration behavior, and the PR has credible exact-head CLI proof with no blocking code finding. Its explicit human-review label should remain the merge gate for this upgrade-time approval-policy change. Priority: P1 Review scores
Verification
How this fits togetherDoctor moves retired approval JSON into OpenClaw’s shared SQLite state before runtime approval checks use the canonical policy. The preflight path coordinates that migration with configuration repair and other state migrations. flowchart LR
A[Retired approval JSON] --> B[Doctor repair flow]
B --> C[Nullable usage cleanup]
C --> D[Strict policy validation]
D --> E[Shared SQLite policy]
E --> F[Runtime approval checks]
Decision needed
Why: The patch changes how retired persisted execution-approval policy is accepted during upgrade, so the final compatibility decision belongs to a maintainer despite strong proof and no code defect. Before merge
Agent review detailsSecurityNone. PR surfaceSource +49, Tests +147, Docs +8. Total +204 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the strict canonical parser and fail-closed migration ownership, then land this bounded Doctor-only recovery after human approval of the legacy compatibility decision. Do we have a high-confidence way to reproduce the issue? Yes, from source and the supplied head-pinned terminal trace: a retired allowlist entry with either null usage field reaches the strict parser on current main and is preserved as malformed instead of imported. Is this the best way to solve the issue? Yes: normalizing only non-authoritative null usage metadata at the Doctor-owned legacy boundary preserves strict canonical validation and avoids a runtime compatibility reader. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9ebf5aed2cfa. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
|
🦞🧹
This is fix-only; I will not merge this PR. Re-review progress:
|
|
🦞✅ Source: Why human review is needed: What the maintainer can do as a next step: I added |
c3e731b to
898b24d
Compare
|
Reviewing and preparing this for landing under maintainer direction. @obviyus, I picked up your updated head The bounded compatibility decision is to recover only I reproduced current-main behavior with the production migration boundary: the absent-metadata case passes, while the otherwise identical null-metadata case fails with |
898b24d to
3301b6d
Compare
|
🦞✅ Source: Why human review is needed: What the maintainer can do as a next step: I added |
Reuse JSON normalization and the preflight guard, preserve strict canonical policy parsing, and consolidate migration regressions with node-host and cleanup-retry coverage. Co-authored-by: Ayaan Zaidi <[email protected]>
|
Exact-head validation is complete for The PR body now includes the requested auditable terminal trace, not only a prose summary. The supported CLI build profile was rebuilt at the published head. Both valid and partially valid legacy configs recover with Doctor/approvals exit 0, canonical policy present, and receipted source removal. The adjacent malformed case ( This addresses every item in the latest ClawSweeper review: direct migration/preservation proof is attached inline, the 49 net production lines are confined to the necessary legacy-only normalization and early sequencing, and exact-head checks are complete. No runtime schema/policy relaxation or budget change. Proceeding through native prepare/merge. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞✅ Source: Why human review is needed: What the maintainer can do as a next step: I added |
|
Merged via squash.
|
* fix(doctor): import legacy exec approvals with null usage metadata * fix(doctor): migrate approvals before config repair * refactor(doctor): tighten legacy approval recovery Reuse JSON normalization and the preflight guard, preserve strict canonical policy parsing, and consolidate migration regressions with node-host and cleanup-retry coverage. Co-authored-by: Ayaan Zaidi <[email protected]> --------- Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com> Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
Fixes #118242.
What Problem This Solves
Fixes an issue where upgrading users with
lastUsedAt: nullorlastUsedCommand: nullin the retiredexec-approvals.jsoncould not recover approvals withopenclaw doctor --fix. The strict importer treated the file as malformed, and Doctor could reach approval-dependent config repairs before importing the file, sending the operator back to the command that had just failed. Partially valid legacy config exposed the same ordering problem.Why This Change Was Made
Normalize only these two usage fields at the Doctor-owned legacy import boundary, then validate the complete policy with the unchanged strict parser. Run that state-root import before config-dependent repairs. Canonical SQLite policy, authorization fields, source-byte receipt identity, exclusive migration ownership, canonical-state precedence, and malformed-source preservation remain unchanged. No schema, protocol, dependency, or configuration-surface change is introduced.
Maintainer review reused the existing JSON parser helper, shared the existing preflight guard, consolidated duplicate migration tests, and added coverage for wildcard entries, retained non-null metadata, malformed policy, strict canonical parsing, node-host startup, and interrupted cleanup. The bounded compatibility decision is recorded in #118282 (comment).
User Impact
openclaw doctor --fixrecovers otherwise-valid legacy approval policies without manual JSON editing, including while config itself needs repair. Verify withopenclaw approvals getusing the same state directory. Other malformed fields and conflicting legacy policies are still preserved for recovery rather than silently accepted.Thanks @sercada for the report and reproduction, and @obviyus for the preflight ordering repair and CLI regression.
Evidence
5b8920bc100913fdd3dfc804b5bcdae108e8b44f, including the merge-tree build with the main CSS repair.approvals get --jsonexits 0, the original allowlist is present without null usage fields, and source removal is recorded in the migration receipt. No operator Gateway or live state was used.Preserved malformed legacy exec approvals for operator recovery; the node-host null-metadata case also fails before the fix.node scripts/run-vitest.mjs src/infra/state-migrations.exec-approvals.test.ts src/infra/exec-approvals-config.test.ts src/infra/exec-approvals-store.test.ts src/node-host/startup-state-migrations.test.ts src/commands/doctor-config-preflight.process.test.ts.node scripts/check-changed.mjs -- src/commands/doctor-config-preflight.ts src/commands/doctor-config-preflight.process.test.ts src/infra/state-migrations.exec-approvals.ts src/infra/state-migrations.exec-approvals.test.ts src/infra/exec-approvals-config.test.ts src/node-host/startup-state-migrations.test.ts docs/tools/exec-approvals.mdpassed, including types, formatting, lint, import cycles, and architecture guards.git diff --checkpassed.pnpm buildcompleted runtime compilation and postbuild checks but both the unchanged baseline and candidate hit the same existing Control UI CSS limit: 54,809 B against 54,784 B. This is already repaired on main by fix(ci): deduplicate Control UI skeleton styles #133787 (54,781 B, unchanged budget). The exact-head merge-tree CI build is now green; no budget or baseline was changed here. The supportedcliStartupbuild profile was also rebuilt successfully at the exact published head for the terminal trace below.Actual CLI commands run in each isolated fixture:
Review summary
Best-fix verdict: best owner boundary. Runtime-wide nullable validation and indiscriminate null stripping were rejected because they would accept malformed canonical or authorization state. A downstream catch would preserve the recovery deadlock. The existing migration owner handles normalization, validation, transaction, receipt, and cleanup; preflight establishes the required order.
Production LOC: +50/-1 (net +49); tests: +160/-13 (net +147); docs: +8. Production growth is the necessary legacy-only normalization and early import sequencing; the maintainer pass removed 14 production lines from the incoming implementation. No new public surface or persistence representation.
Provenance: raw-parent diffs verify strict metadata validation in
9b1c36d23c3and its reuse by the SQLite Doctor importer in9eae43bd37c. Stablev2026.7.1readers accepted and preserved null metadata; the exact writer that created the reported nulls remains unknown. The fix does not depend on any Codex runtime contract.Follow-up: make genuinely malformed legacy-policy diagnostics identify a bounded field path without exposing commands, patterns, or credentials. That diagnostic improvement is separate from this null-recovery fix.
Exact-head terminal trace
Rebuilt the published head with
node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup(exit 0), then ran the CLI commands above in three isolated synthetic HOME/state directories withOPENCLAW_SERVICE_REPAIR_POLICY=external. The successful fixtures containlastUsedAt: nullandlastUsedCommand: null; the malformed alternative addsargPattern: null, which must not be normalized because it is policy.The trace below is the asserted command-runner output, including captured Doctor terminal lines and read-only SQLite receipt/policy checks. Only the temporary host path is omitted;
beforeExit/afterExitrefer toapprovals get --jsonbefore/after Doctor.{ "head": "5b8920bc100913fdd3dfc804b5bcdae108e8b44f", "phase": "after", "results": [ { "case": "valid-config", "beforeExit": 1, "doctorExit": 0, "afterExit": 0, "sourcePresent": false, "policyRecovered": true, "sourceRemovalReceipted": true, "doctorTrace": [ "- Imported legacy exec approvals into shared SQLite state.", "- Removed retired exec approvals JSON after recording its migration", "└ Doctor complete." ] }, { "case": "legacy-config", "beforeExit": 1, "doctorExit": 0, "afterExit": 0, "sourcePresent": false, "policyRecovered": true, "sourceRemovalReceipted": true, "doctorTrace": [ "- Imported legacy exec approvals into shared SQLite state.", "- Removed retired exec approvals JSON after recording its migration", "└ Doctor complete." ] }, { "case": "malformed-policy", "beforeExit": 1, "doctorExit": 1, "afterExit": 1, "sourcePresent": true, "sourceBytesUnchanged": true, "canonicalPolicyCreated": false, "receiptRemovedSource": 0, "runtimeStillBlocked": true, "doctorTrace": [ "- Preserved malformed legacy exec approvals for operator recovery." ] } ] }