Repository navigation
fix(update): stop skipping Doctor-owned migrations - #136529
fuller-stack-dev wants to merge 35 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 2, 2026, 10:39 PM ET / September 3, 2026, 02:39 UTC. ClawSweeper reviewWhat this changesThe PR unifies Doctor migration mode through detection and execution, adds per-step migration receipts, and adds a hidden read-only update command that plans migrations for a copied state snapshot. Merge readiness⛔ Blocked before merge - 4 items remain Keep open for maintainer scope review: the mode-latch repair addresses the reported silent omission, but this Member-authored, maintainer-labeled PR also introduces a large candidate migration-planning protocol that needs an explicit product-boundary decision. Priority: P2 Review scores
Verification
How this fits togetherDoctor preflight prepares configuration and legacy state before startup or update recovery. This change feeds the selected migration mode into the migration owner, which then reports completed, skipped, warning, or refused state-repair steps. flowchart LR
A[Config snapshot] --> B[Doctor preflight]
B --> C[Migration mode selection]
C --> D[Legacy-state detection]
D --> E[Migration steps and receipts]
E --> F[SQLite and state repair]
B --> G[Read-only candidate plan]
Decision needed
Why: The mode repair is concrete, but the hidden command and plan schema add a durable operator-facing update boundary whose intended owner and completion path are not settled by this bug fix alone. Before merge
Agent review detailsSecurityNone. PR surfaceSource +1875, Tests +1311. Total +3186 across 15 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the single mode latch and receipt boundary, then either narrow this PR to that repair or explicitly sponsor the candidate-plan protocol as part of the update transaction tracked by #124396. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: the verified baseline delta shows Doctor detection followed by automatic-only step construction, while the branch’s focused suite covers the affected exec-approval and TUI migration paths. Is this the best way to solve the issue? Unclear. Carrying one mode through the migration owner is the maintainable repair, but adding a standalone candidate planning protocol is a separate updater-direction choice. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 41419be40bbb. LabelsLabel changes:
Label 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 (1 earlier review cycle)
|
|
Packaged CLI proof found a blocking failure in the unpublished repair candidate. This is not a green result for the public PR head. AWS/Linux run run_821eb055bfd3 installed the package built from The prewritten negative used malformed legacy TUI state plus pending legacy exec approvals. The actual installed command was Caller inspection found that The retained npm debug log confirms the packaged preinstall/postinstall hooks completed with code 0. The allow-scripts warnings were preserved; no permission override or install replay was used. Raw observations SHA-256: |
|
Requesting @openclaw/openclaw-secops involvement for the pending Doctor planning changes in The pending changes add artifact-preserving inspection of shared auth state and an inspection-only ownership read that does not populate the process-stable runtime cache. The intended boundary is that planning must not initialize or repair the source database, alter its artifacts, or change runtime ownership through a planning read. No schema or protocol version change is proposed. The current public head |
|
Following up on the existing owner request, @openclaw/openclaw-secops: we need an owner to direct or author the copied-auth inspection change, or actively review the proposed bytes below. The required behavior is that Doctor copied-state planning reads auth ownership and legacy cleanup facts without changing the source DB/WAL/SHM or populating the process-stable runtime ownership cache. Ordinary live auth behavior must stay intact. No schema, protocol, credential representation, or new persistence owner is proposed. The deferred proposal is exactly two files, +54/-21, from Public head Could an authorized owner take one of these concrete actions: direct the implementation at these helpers, author an equivalent repair, or review this scoped proposal and identify the required corrections? A reviewer assignment or pending team request alone will not be recorded as involvement. Final published-head review, CI and behavior gates remain required. Deferred two-helper proposaldiff --git a/src/agents/auth-profiles/path-resolve.ts b/src/agents/auth-profiles/path-resolve.ts
index 3e05342f05a..a3c93c227bc 100644
--- a/src/agents/auth-profiles/path-resolve.ts
+++ b/src/agents/auth-profiles/path-resolve.ts
@@ -78,6 +78,20 @@ export function resolveSharedAuthStoreOwnership(
return ownership;
}
+/** Inspect copied migration state without populating the process-stable runtime owner cache. */
+export function inspectSharedAuthStoreOwnership(
+ env: NodeJS.ProcessEnv = process.env,
+): SharedAuthStoreOwnership {
+ const databasePath = path.resolve(resolveOpenClawStateSqlitePath(env));
+ return parseSharedAuthStoreOwnership(
+ readConfigMachineState<unknown>(
+ SHARED_AUTH_STORE_STATE_KEY,
+ { env, path: databasePath },
+ { artifactPreservingReadOnly: true },
+ ),
+ );
+}
+
/** Update the process-stable cache after this process commits the ownership row. */
export function noteCommittedSharedAuthStoreOwnership(
ownership: SharedAuthStoreOwnership,
diff --git a/src/agents/auth-profiles/shared-store-bootstrap.ts b/src/agents/auth-profiles/shared-store-bootstrap.ts
index f621940803e..6f54f9aa2a1 100644
--- a/src/agents/auth-profiles/shared-store-bootstrap.ts
+++ b/src/agents/auth-profiles/shared-store-bootstrap.ts
@@ -4,9 +4,13 @@ import type { DatabaseSync } from "node:sqlite";
import { hasErrnoCode } from "../../infra/errno.js";
import { executeSqliteQueryTakeFirstSync, getNodeSqliteKysely } from "../../infra/kysely-sync.js";
import { openNodeSqliteDatabase } from "../../infra/node-sqlite.js";
+import { prepareSqliteReadOnlyLocationSyncInProcess } from "../../infra/sqlite-readonly-location.js";
import { writeConfigMachineState } from "../../state/config-machine-state.js";
import type { DB as OpenClawAgentKyselyDatabase } from "../../state/openclaw-agent-db.generated.js";
-import { withExistingOpenClawStateDatabaseReadOnly } from "../../state/openclaw-state-db-readonly.js";
+import {
+ withExistingOpenClawStateDatabaseArtifactPreservingReadOnly,
+ withExistingOpenClawStateDatabaseReadOnly,
+} from "../../state/openclaw-state-db-readonly.js";
import { tableExists } from "../../state/openclaw-state-db-schema-helpers.js";
import type { DB as OpenClawStateKyselyDatabase } from "../../state/openclaw-state-db.generated.js";
import { resolveUserPath } from "../../utils.js";
@@ -105,14 +109,21 @@ export function readSharedAuthLegacyRowsFromDatabase(database: DatabaseSync): Sh
return { store, state };
}
-export function inspectSharedAuthLegacyRowsReadOnly(sourcePath: string): SharedAuthLegacyRows {
+export function inspectSharedAuthLegacyRowsReadOnly(
+ sourcePath: string,
+ behavior: { artifactPreservingReadOnly?: boolean } = {},
+): SharedAuthLegacyRows {
if (inspectSharedAuthLegacySourceFile(sourcePath).status === "missing") {
return { store: null, state: null };
}
+ const prepared = behavior.artifactPreservingReadOnly
+ ? prepareSqliteReadOnlyLocationSyncInProcess(sourcePath)
+ : undefined;
let database: DatabaseSync;
try {
- database = openNodeSqliteDatabase(sourcePath, { readOnly: true });
+ database = openNodeSqliteDatabase(prepared?.location ?? sourcePath, { readOnly: true });
} catch (error) {
+ prepared?.cleanup();
throw new SharedAuthStoreSourceInspectionError(sourcePath, "open", error);
}
try {
@@ -121,28 +132,36 @@ export function inspectSharedAuthLegacyRowsReadOnly(sourcePath: string): SharedA
throw new SharedAuthStoreSourceInspectionError(sourcePath, "read", error);
} finally {
database.close();
+ prepared?.cleanup();
}
}
-export function hasPendingSharedAuthCleanup(env: NodeJS.ProcessEnv, sourcePath: string): boolean {
+export function hasPendingSharedAuthCleanup(
+ env: NodeJS.ProcessEnv,
+ sourcePath: string,
+ behavior: { artifactPreservingReadOnly?: boolean } = {},
+): boolean {
+ const read = ({ db: database }: { db: DatabaseSync }) => {
+ if (behavior.artifactPreservingReadOnly && !tableExists(database, "migration_sources")) {
+ return false;
+ }
+ const db = getNodeSqliteKysely<SharedAuthMigrationDatabase>(database);
+ const row = executeSqliteQueryTakeFirstSync(
+ database,
+ db
+ .selectFrom("migration_sources")
+ .select("source_key")
+ .where("migration_kind", "=", SHARED_AUTH_STORE_MIGRATION_KIND)
+ .where("source_path", "=", sourcePath)
+ .where("removed_source", "=", 0)
+ .limit(1),
+ );
+ return Boolean(row);
+ };
return (
- withExistingOpenClawStateDatabaseReadOnly(
- ({ db: database }) => {
- const db = getNodeSqliteKysely<SharedAuthMigrationDatabase>(database);
- const row = executeSqliteQueryTakeFirstSync(
- database,
- db
- .selectFrom("migration_sources")
- .select("source_key")
- .where("migration_kind", "=", SHARED_AUTH_STORE_MIGRATION_KIND)
- .where("source_path", "=", sourcePath)
- .where("removed_source", "=", 0)
- .limit(1),
- );
- return Boolean(row);
- },
- { env },
- ) ?? false
+ (behavior.artifactPreservingReadOnly
+ ? withExistingOpenClawStateDatabaseArtifactPreservingReadOnly(read, { env })
+ : withExistingOpenClawStateDatabaseReadOnly(read, { env })) ?? false
);
} |
Keep live caller authority separate from artifact-preserving copied-state planning. Carry planned endpoints and requiredness through ordered receipts, close required refusals, and settle deferred plugin work after its writer. Continue the migration work from openclaw#136529 by Jason (Json), @fuller-stack-dev, without replacing the original public branch or history.
…139683) * fix(doctor): bind migration authority and ordered receipts Keep live caller authority separate from artifact-preserving copied-state planning. Carry planned endpoints and requiredness through ordered receipts, close required refusals, and settle deferred plugin work after its writer. Continue the migration work from #136529 by Jason (Json), @fuller-stack-dev, without replacing the original public branch or history. * fix(doctor): preserve caller locks during snapshot hashing Isolate snapshot file descriptors from caller-held SQLite transactions. Keep framed worker input and ordered refusal semantics, classify deliberate foreign-store omissions at their owner, and retain exact CLI controls. * fix(doctor): preserve uncached caller locks during planning * test(doctor): bind final traversal refusal diagnostics * fix(sqlite): preserve publisher cleanup ownership
|
Superseded by the landed, credited continuation #139683, merged as 6277d6da1331b039c2603ae89caae5a9bd3c1df0 from verified head 98dd65039879b5da3930c70c0dd8401500661da9. The landed replacement covers this PR's scoped contract:
This is a corrected continuation, not a byte-identical merge of the original proposal. It includes the later CLI-refusal, caller-lock and publication-cleanup fixes. The relevant migration/planner, Doctor config/health, auth-reader and SQLite files in the squash commit match the verified final head. Exact-head CI and native preparation/merge passed. Native completion receipt. Original author Jason (Json), @fuller-stack-dev, is credited in the replacement and landed commit. Closing this original PR as superseded, not merged. Its public head |
…penclaw#139683) * fix(doctor): bind migration authority and ordered receipts Keep live caller authority separate from artifact-preserving copied-state planning. Carry planned endpoints and requiredness through ordered receipts, close required refusals, and settle deferred plugin work after its writer. Continue the migration work from openclaw#136529 by Jason (Json), @fuller-stack-dev, without replacing the original public branch or history. * fix(doctor): preserve caller locks during snapshot hashing Isolate snapshot file descriptors from caller-held SQLite transactions. Keep framed worker input and ordered refusal semantics, classify deliberate foreign-store omissions at their owner, and retain exact CLI controls. * fix(doctor): preserve uncached caller locks during planning * test(doctor): bind final traversal refusal diagnostics * fix(sqlite): preserve publisher cleanup ownership
Related: #124396
What Problem This Solves
Fixes an issue where update and Doctor repair flows could detect Doctor-owned legacy state, then build an automatic-mode migration list that omitted it. Exec approvals and TUI last-session state could remain behind without a recorded reason.
Why This Change Was Made
The migration owner now derives one mode and carries it through detection, planning, and execution. Each selected step has a stable ID, exact source and target, requiredness, reversibility, and an outcome or refusal. Execution returns matching per-step receipts.
This also adds a hidden, read-only candidate command for the staged updater work:
The running candidate supplies its own package root and version. The caller supplies the candidate and copied-state digests, and the plan integrity hash binds the complete result.
Planning cannot acquire write authority. It binds HOME, config, and state to the copied snapshot, disables config observation and shell fallback, uses core-only config validation, does not call migration runners, and defers plugin-owned planning with
plugin-planning-deferred. Detection warnings produce a top-level refusal. Tests verify that planning neither creates nor registers SQLite databases and does not change copied bytes or create WAL/SHM files.This PR does not implement activation, rollback, plugin compatibility, or the rest of the update transaction. It follows OCM's preparation/finalization separation only far enough to give the later updater stages a closed plan and execution receipts. There is no SQLite schema change.
User Impact
Doctor repair no longer drops Doctor-owned migrations when it is called through the automatic migration helper. A successful
doctor --fixrun also does not advise the operator to rundoctor --fixagain after the required migration completed.The hidden candidate command can inspect an isolated copied snapshot while the incumbent Gateway remains live. Plugin migration planning stays with the separate candidate/plugin compatibility stage.
Evidence
0ebdbe6155adc2413896989f61ca6fadc5fb4b12: Doctor detection found exec approvals and TUI state, but the automatic-mode step builder returned no changes, warning, or receipt and left both sources in place.bc99f5123989125853de8b697f036f173e73c475, based on canonical837ef59df9d9d9d86dd761102c21c1cf879ca7d5.pnpm check:changed: passed.6589799deb8c452569e09e02ed2ba1bd8abca467: 8 of 8 in-scope checks passed with two varied fixtures. Exact fields and digests changed with each fixture; the copied trees remained byte-identical; malformed config refused with exit 1. The later additive merge contains only Signal, WhatsApp, iMessage, CI, and locale changes.Production delta is +722/-132 lines; tests add 356 lines. The production growth is the closed plan/receipt contract, stable metadata for the existing migration owners, and its candidate CLI. The execution mode fix itself replaces the split mode checks with one mode value.