Skip to content

Commit 0388d00

Browse files
authored
fix(cli): keep logs startup read-only (#116869)
Keep log retrieval diagnostic-first and non-mutating while core configuration validation remains active. Explicit Doctor runs continue to own plugin-sensitive validation and state migration.\n\nFixes #116853
1 parent f22cc1f commit 0388d00

4 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎src/cli/argv.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ describe("argv helpers", () => {
759759

760760
it.each([
761761
{ argv: ["node", "openclaw", "status"], expected: true },
762+
{ argv: ["node", "openclaw", "logs", "--plain"], expected: false },
762763
{ argv: ["node", "openclaw", "health"], expected: false },
763764
{ argv: ["node", "openclaw", "sessions"], expected: false },
764765
{ argv: ["node", "openclaw", "--profile", "work", "status"], expected: true },
@@ -784,6 +785,7 @@ describe("argv helpers", () => {
784785

785786
it.each([
786787
{ path: ["status"], expected: true },
788+
{ path: ["logs"], expected: false },
787789
{ path: ["update", "status"], expected: false },
788790
{ path: ["gateway", "call"], expected: false },
789791
{ path: ["gateway", "health"], expected: true },

‎src/cli/argv.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ export function shouldMigrateStateFromPath(path: string[]): boolean {
615615
return true;
616616
}
617617
const [primary, secondary] = path;
618-
if (primary === "health" || primary === "sessions") {
618+
if (primary === "health" || primary === "logs" || primary === "sessions") {
619619
return false;
620620
}
621621
// Remote RPC clients must not migrate state owned by the running gateway.

‎src/cli/program/config-guard.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ describe("ensureConfigReady", () => {
168168
commandPath: ["update", "status"],
169169
expectedDoctorCalls: 0,
170170
},
171+
{
172+
name: "skips doctor flow for logs",
173+
commandPath: ["logs"],
174+
expectedDoctorCalls: 0,
175+
},
171176
{
172177
name: "skips doctor flow for remote gateway calls",
173178
commandPath: ["gateway", "call"],
@@ -206,6 +211,15 @@ describe("ensureConfigReady", () => {
206211
expect(readConfigFileSnapshotMock).toHaveBeenCalledWith({ observe: false });
207212
});
208213

214+
it("keeps logs config guard reads non-observing and independent of plugin state", async () => {
215+
await runEnsureConfigReady(["logs"]);
216+
217+
expect(readConfigFileSnapshotMock).toHaveBeenCalledWith({
218+
observe: false,
219+
skipPluginValidation: true,
220+
});
221+
});
222+
209223
it("keeps remote gateway call config reads non-observing", async () => {
210224
await runEnsureConfigReady(["gateway", "call"]);
211225

@@ -235,6 +249,16 @@ describe("ensureConfigReady", () => {
235249
expect(loadAndMaybeMigrateDoctorConfigMock).not.toHaveBeenCalled();
236250
});
237251

252+
it("keeps logs from migrating existing local legacy state", async () => {
253+
const root = useTempOpenClawHome();
254+
writeStateMarker(root, "cron/runs/legacy-job.jsonl");
255+
256+
await runEnsureConfigReady(["logs"]);
257+
258+
expect(loadAndMaybeMigrateDoctorConfigMock).not.toHaveBeenCalled();
259+
expect(fs.existsSync(path.join(root, ".openclaw", "cron/runs/legacy-job.jsonl"))).toBe(true);
260+
});
261+
238262
it.each(["restart-sentinel.json", "restart-sentinel.json.doctor-importing"])(
239263
"runs doctor flow when lightweight startup detection finds %s",
240264
async (relativePath) => {

‎src/cli/program/config-guard.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ function isGatewayStartupCommand(commandPath: string[]): boolean {
189189
);
190190
}
191191

192-
async function getConfigSnapshot(options?: { observe: false }) {
192+
async function getConfigSnapshot(options?: { observe: false; skipPluginValidation?: true }) {
193193
if (options?.observe === false) {
194194
return readConfigFileSnapshot(options);
195195
}
@@ -268,12 +268,14 @@ export async function ensureConfigReady(
268268
preflightSnapshot = await runStateMigrationPreflight();
269269
}
270270

271-
// Status reads its materialized/source pair; remote Gateway calls must not
272-
// record config health in the state owned by the Gateway being queried.
271+
// Read-only diagnostics must not record config health; logs also skips plugin
272+
// metadata discovery because opening the shared state DB creates SQLite sidecars.
273273
const configSnapshotOptions =
274-
commandName === "status" || (commandName === "gateway" && subcommandName === "call")
275-
? ({ observe: false } as const)
276-
: undefined;
274+
commandName === "logs"
275+
? ({ observe: false, skipPluginValidation: true } as const)
276+
: commandName === "status" || (commandName === "gateway" && subcommandName === "call")
277+
? ({ observe: false } as const)
278+
: undefined;
277279
let snapshot = preflightSnapshot ?? (await getConfigSnapshot(configSnapshotOptions));
278280
if (
279281
!preflightSnapshot &&

0 commit comments

Comments
 (0)