Skip to content

fix: reconcile conflicting legacy approvals without replacing current policy - #153405

Open
RomneyDa wants to merge 11 commits into
mainfrom
fix/update-policy-conflict
Open

RomneyDa wants to merge 11 commits into
mainfrom
fix/update-policy-conflict

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Problem

Doctor deliberately retains a conflicting retired approvals file rather than silently replacing the current SQLite policy. Operators need a read-only comparison and an explicit way to retain the current policy and retire those legacy bytes.

Solution

Add openclaw approvals reconcile for a redacted, read-only preview, and --keep-current for explicit retirement under the existing maintenance/migration owner. Preserve the exact canonical policy row, archive exact legacy bytes with platform-enforced private creation, then remove the legacy source. Never import legacy credentials on that path. Reuse the current owner’s interrupted source/claim handling and keep policy preview available when separate credential custody needs repair; socket comparison is then explicitly unavailable rather than falsely equal. No new persisted schema or automatic policy selection.

Validation

  • Actual shipped CLI in isolated state: preview preserved the exact current row and legacy bytes; --keep-current preserved the exact row, archived exact private bytes, removed the legacy source, and repeated without changes. Synthetic legacy credential was not printed.
  • Focused migration, CLI, and passive-startup tests passed, including missing credential custody, an interrupted hard-link claim, contradictory retained names, missing/invalid current policy, exact archive bytes, absent/invalid-profile preview, and macOS native-helper refusal/restoration.
  • Core and scoped CLI/infra typechecks, touched lint/format, and diff checks passed; review-fix core typecheck also passed.
  • Independent local review identified archive privacy and read-only recovery gaps; these were repaired. Follow-up recovery reviews also caught absent/invalid-profile preview and native-helper diagnostic gaps; those are fixed and covered. The final small diagnostic/root-shape follow-up was locally inspected and tested, not sent through a fourth independent review.
  • A fresh installed-stable-to-this-head upgrade/service campaign was not run. Historical evidence on earlier heads is not current-head upgrade proof. New-head CI remains required.

Latest CI repair

CI follow-up: documented why the passive-startup fixture isolates config loading, plugins, terminal output, process exit and Gateway state probing. All 4 passive startup cases and the mock-export guard pass; no baseline exception or production behavior changed. New-head CI pending.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: M maintainer Maintainer-authored PR labels Sep 20, 2026
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 242de2053169a6a2267fc4a3698374537ec30ffd
  • Maintainer: @RomneyDa
  • Repository role: maintain

These security sensitive changes were made:

  • src/infra/exec-approvals-migration-gate.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 20, 2026
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Accepted and fixed both findings from the completed review artifact in workflow 35487739098: global reconciliation startup is passive for both command spellings/modes, and policy comparison excludes generated allowlist IDs. Current head: 171c0a34b5a.

Added real Commander pre-action coverage and deterministic ID-less allowlist regression; independent P2 review, focused tests, typechecks and lint pass. The PR body now includes actual e46e374 migration-conflict → candidate built-CLI recovery proof, unchanged canonical row/invalid config, verified archive, and successful isolated foreground Gateway startup/restart. No production state or service was changed. CI runs on the corrected head.

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Final CI correction at f5a0e97de85 removes a type-only catalog import cycle. There is no runtime value/policy change: readonly literal entries are still checked by the typed parent catalog. Madge now reports zero cycles, core typecheck passes, and independent peer review is clean. The previously posted isolated recovery/startup proof exercises the same runtime behavior. Full local changed-file checks also completed successfully.

Both accepted code findings and the related lint/architecture CI issues are addressed. Please review the current head; the PR body contains consolidated evidence.

@clawsweeper

clawsweeper Bot commented Sep 20, 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 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 1:05 AM ET / 05:05 UTC (Revision 6).

ClawSweeper review

What this changes

Adds a local approvals command that previews a legacy JSON conflict and, when explicitly requested, archives the legacy file while preserving the current SQLite policy.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still refuses conflicting legacy approvals without offering this operator recovery path. The inspected head addresses the earlier policy-comparison findings, and I found no actionable patch defect.

Priority: P2
Reviewed head: 87df87168f7477812b67e478c2609e12cedf2f10

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The branch has convincing recovery-path evidence and focused state-preservation regressions, with no concrete correctness finding on the inspected head.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The captured terminal trace exercises an old-version migration conflict through the built candidate CLI, then observes an unchanged SQLite row, one legacy archive, and a healthy isolated Gateway after restart. The final grant-timestamp comparison change has focused regression evidence; the trace does not separately exercise that comparison. Existing-state compatibility is supported by the unchanged-row assertion and the archived legacy bytes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured terminal trace exercises an old-version migration conflict through the built candidate CLI, then observes an unchanged SQLite row, one legacy archive, and a healthy isolated Gateway after restart. The final grant-timestamp comparison change has focused regression evidence; the trace does not separately exercise that comparison. Existing-state compatibility is supported by the unchanged-row assertion and the archived legacy bytes.
Evidence reviewed 9 items Current-main gap: The pinned main-to-head diff adds the reconcile command and its CLI policy; current main has the conflict refusal but lacks this recovery command.
Explicit policy preservation: The write transaction rereads the canonical row, requires it to parse, and records removal of the legacy source without writing a replacement approvals row.
Archive and ownership boundary: The migration creates a private archive from the claimed bytes, verifies its hash, and runs under the existing exclusive state-maintenance lock before retiring the source.
Findings None None.
Security None None.

How this fits together

Exec approvals control which agent commands and MCP tools may run. Doctor migrates the retired JSON policy into SQLite; when the two policies conflict, this command lets the operator inspect the conflict and choose to retain the SQLite policy.

flowchart LR
A[Doctor detects conflict] --> B[Legacy JSON policy]
C[Current SQLite policy] --> D[Local preview]
B --> D
D --> E{Keep current policy?}
E -->|No| F[No state change]
E -->|Yes| G[Archive and retire legacy file]
G --> H[SQLite policy remains]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +217, Tests +293, Docs +29. Total +539 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 7 262 45 +217
Tests 4 293 0 +293
Docs 1 29 0 +29
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 584 45 +539

Review metrics

Metric Value Why it matters
Operator recovery surface 1 command and 1 explicit action flag The flag makes retirement of a conflicting legacy policy an operator choice.
Production and test delta production +262/-45; tests +293/-0 The production growth implements the recovery path in the existing migration owner and adds boundary regressions.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/cli/exec-approvals-cli.reconcile.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #153401
Summary: This PR addresses the policy-reconciliation part of the broader update-recovery issue; the merged rehearsal PR addresses a distinct earlier update boundary.

Members:

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

Technical review

Best possible solution:

Keep the policy choice explicit and preserve the verified archive and SQLite row; a future Doctor or Fix interface could make this recovery easier for operators who cannot use the CLI.

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

Yes. Current-main migration source preserves a conflicting legacy file and blocks approval use; the captured PR body also reports an old-version conflict trace. I did not execute that path in this read-only review.

Is this the best way to solve the issue?

Yes. An explicit CLI choice routed through the existing migration owner is a narrow way to retain the current policy without making Doctor choose between conflicting policies automatically.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded recovery improvement for a specific legacy approvals conflict.
  • 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 (terminal): The captured terminal trace exercises an old-version migration conflict through the built candidate CLI, then observes an unchanged SQLite row, one legacy archive, and a healthy isolated Gateway after restart. The final grant-timestamp comparison change has focused regression evidence; the trace does not separately exercise that comparison. Existing-state compatibility is supported by the unchanged-row assertion and the archived legacy bytes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured terminal trace exercises an old-version migration conflict through the built candidate CLI, then observes an unchanged SQLite row, one legacy archive, and a healthy isolated Gateway after restart. The final grant-timestamp comparison change has focused regression evidence; the trace does not separately exercise that comparison. Existing-state compatibility is supported by the unchanged-row assertion and the archived legacy bytes.

Evidence

What I checked:

  • Current-main gap: The pinned main-to-head diff adds the reconcile command and its CLI policy; current main has the conflict refusal but lacks this recovery command. (src/cli/exec-approvals-cli.reconcile.ts:11, 87df87168f74)
  • Explicit policy preservation: The write transaction rereads the canonical row, requires it to parse, and records removal of the legacy source without writing a replacement approvals row. (src/infra/state-migrations.exec-approvals.ts:172, 87df87168f74)
  • Archive and ownership boundary: The migration creates a private archive from the claimed bytes, verifies its hash, and runs under the existing exclusive state-maintenance lock before retiring the source. (src/infra/state-migrations.exec-approvals.ts:362, 87df87168f74)
  • Earlier findings resolved in source: The comparison projects approval rules without generated allowlist IDs, usage fields, or MCP grant creation and use timestamps. The regression supplies unequal grant timestamps and checks that matching rules compare equal. (src/infra/state-migrations.exec-approvals.test.ts:490, 87df87168f74)
  • User guidance: The CLI documentation separates a non-mutating preview from the explicit keep-current operation and tells operators to stop processes using the state directory. Public docs: docs/cli/approvals.md. (docs/cli/approvals.md:103, 87df87168f74)
  • Real recovery evidence: The captured PR body reports a redacted old-version conflict followed by built-candidate CLI preview and keep-current output: the canonical row stayed unchanged, one archive was created, and an isolated Gateway passed health and restart checks. The later grant-timestamp repair is supported by the reported focused regression, not by a new terminal trace. (87df87168f74)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RomneyDa: 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 (5 earlier review cycles)
  • reviewed 2026-09-20T04:21:09.975Z sha f5a0e97de85ec22a866e1dd9448cd0bc7ea582a3 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-20T04:33:25.070Z sha 4fe2915 :: blocked before merge. :: none
  • reviewed 2026-09-30T01:37:22.553Z sha 27751ea57a3267bbc0a42fd37484f06ef31a362f :: needs changes before merge. :: [P2] Compare approval rules without usage history
  • reviewed 2026-09-30T03:12:54.880Z sha 5a46140cfdeef53460a9090755da55a6973005f3 :: needs changes before merge. :: [P2] Exclude grant creation time from policy equality
  • reviewed 2026-09-30T04:39:34.956Z sha d13947996f790fb190abd5f25249f101cea3e5b9 :: needs maintainer review before merge. :: none

@RomneyDa
RomneyDa force-pushed the fix/update-policy-conflict branch from f5a0e97 to 4fe2915 Compare September 20, 2026 04:27
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Head4fe2915b2ea is a clean rebase onto main6e5f6f95b10 following an unrelated artifact request-cancellation CI timeout. Range-diff shows all four patches unchanged; the failing case and then its full35-test file pass. All181 focused tests, core typecheck, and zero-cycle Madge pass on this head. The actual e46 migration-owner→candidate built-CLI recovery/config-preservation/health/restart proofs were also repeated successfully after rebase.

The previous head had Platinum Hermit, Diamond proof, no findings and Before merge None. Please validate the current rebased head; no behavioral changes were added by the rebase.

@clawsweeper

clawsweeper Bot commented Sep 20, 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:

@RomneyDa
RomneyDa force-pushed the fix/update-policy-conflict branch from 4fe2915 to 27751ea Compare September 30, 2026 01:29
@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Sep 30, 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 Sep 30, 2026
@RomneyDa
RomneyDa force-pushed the fix/update-policy-conflict branch from 27751ea to 5a46140 Compare September 30, 2026 03:05
@RomneyDa

Copy link
Copy Markdown
Member Author

Addressed the exact-head policy-equality feedback on 5a46140cfdeef53460a9090755da55a6973005f3:

  • the reconciliation preview now projects authorization rules without generated allowlist IDs or recorded-use fields (lastUsedAt, lastUsedCommand, lastResolvedPath);
  • the same owner also excludes MCP grant lastUsedAt, so sibling usage history cannot manufacture a policy conflict;
  • the existing deterministic-equality regression now covers differing exec and MCP usage metadata. It fails on the prior comparison and passes after the projection repair;
  • the PR body records measured test cost: 28 migration tests, 23.18s local single-worker wall on a compiler-cache hit (19.19s Vitest duration); exact-head CI timing is pending the new run.

Proof:

  • OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/infra/state-migrations.exec-approvals.test.ts — 28 passed;
  • node scripts/check-changed.mjs -- src/infra/state-migrations.exec-approvals.ts src/infra/state-migrations.exec-approvals.test.ts — passed;
  • Autoreview scoped-clean, no accepted/actionable findings.

Production LOC: +263/-45. Tests: +293/-0. Docs: +29/-0. This follow-up adds +11 net production LOC to make the preview compare authority rather than runtime observation metadata.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa
RomneyDa force-pushed the fix/update-policy-conflict branch from 5a46140 to d139479 Compare September 30, 2026 04:35
@RomneyDa

RomneyDa commented Sep 30, 2026 •

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Addressed the accepted policy-equality finding at exact head d13947996f7:

  • MCP grant addedAt is now treated as generated metadata, matching existing lastUsedAt handling.
  • Regression proof uses unequal legacy/canonical grant timestamps: it failed before the fix with policyMatches false and passes after it.
  • Focused migration suite: 28 passed.
  • Post-rebase changed gate passed for the selected core and core-test lanes.
  • Fresh post-rebase autoreview: clean, no accepted/actionable findings.
  • Repair delta: production 0/-1; test +1/-1.

Mechanical refresh: the prior exact-head CI failure was an unrelated Codex terminal-settlement timeout. Rebased cleanly onto current main and pushed exact head 87df871. Post-rebase migration suite remains 28/28 green and fresh autoreview remains clean; no approvals-policy behavior changed in the rebase.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 30, 2026
@RomneyDa
RomneyDa force-pushed the fix/update-policy-conflict branch from d139479 to 87df871 Compare September 30, 2026 05:01
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

This branch has not been deployed

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

Labels

cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: L 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.

1 participant