Skip to content

Commit 17b84b3

Browse files
committed
fix(gateway): make config.patch errors name the problem and the working next step
Three dead-end error texts in config.patch, per the never-dead-end-the-agent doctrine (failure text states what to try next): - "invalid config; fix before patching" hid the actual validation issues the handler already had in the snapshot; it now summarizes them (same summarizeConfigValidationIssues owner the sibling validation errors use), attaches structured details, and names openclaw doctor as the fix path. - The hashless-LWW rejection said "re-run config.get and retry" — wrong advice, since retrying hash-free fails identically; it now names the exact guarded paths and says to retry with baseHash. - The mutation-conflict handler appended "re-run config.get and retry" to every conflict; non-retryable conflicts (path ownership) fail the retry too, so the suffix is now gated on error.retryable. Both new regression tests fail pre-fix.
1 parent 4a6f99c commit 17b84b3

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎src/gateway/server-methods/config.test.ts‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,19 @@ describe("config.patch hash-free ui.prefs LWW", () => {
336336
);
337337
});
338338

339-
it("rejects a mixed hash-free patch", async () => {
339+
it("rejects a mixed hash-free patch and names the guarded path", async () => {
340340
const { respond } = await invokeConfigPatch({
341341
raw: { ui: { prefs: { theme: "knot" } }, gateway: { port: 19_001 } },
342342
});
343343

344344
expect(respond).toHaveBeenCalledWith(
345345
false,
346346
undefined,
347-
expect.objectContaining({ message: expect.stringContaining("config base hash required") }),
347+
// The operator must see which path needs the base hash; a bare
348+
// "hash required" with no path was a dead-end error.
349+
expect.objectContaining({
350+
message: expect.stringContaining("config base hash required for gateway.port"),
351+
}),
348352
);
349353
expect(storedConfig).toEqual({});
350354
});
@@ -466,6 +470,27 @@ describe("config.patch hash-free ui.prefs LWW", () => {
466470
);
467471
expect(storedConfig.ui?.prefs).toEqual({ locale: "de" });
468472
});
473+
474+
it("advises retry only for retryable mutation conflicts", async () => {
475+
configWriteMocks.commitGatewayConfigWrite.mockImplementationOnce(async () => {
476+
throw new ConfigMutationConflictError("config path owned by another writer", {
477+
retryable: false,
478+
});
479+
});
480+
481+
const { respond } = await invokeConfigPatch({
482+
raw: { ui: { prefs: { theme: "knot" } } },
483+
});
484+
485+
expect(respond).toHaveBeenCalledWith(
486+
false,
487+
undefined,
488+
// A non-retryable conflict fails the retry too; advising it is a dead end.
489+
expect.objectContaining({
490+
message: "config path owned by another writer",
491+
}),
492+
);
493+
});
469494
});
470495

471496
describe("config.patch ID-keyed arrays", () => {

‎src/gateway/server-methods/config.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,15 @@ async function commitGatewayConfigWriteOrRespond(
771771
if (!(error instanceof ConfigMutationConflictError)) {
772772
throw error;
773773
}
774+
// Non-retryable conflicts (e.g. path ownership) will fail the retry too;
775+
// only advise it when a fresh base hash can actually resolve the conflict.
774776
params.respond(
775777
false,
776778
undefined,
777-
errorShape(ErrorCodes.INVALID_REQUEST, `${error.message}; re-run config.get and retry`),
779+
errorShape(
780+
ErrorCodes.INVALID_REQUEST,
781+
error.retryable ? `${error.message}; re-run config.get and retry` : error.message,
782+
),
778783
);
779784
return null;
780785
}
@@ -958,7 +963,11 @@ export const configHandlers: GatewayRequestHandlers = {
958963
respond(
959964
false,
960965
undefined,
961-
errorShape(ErrorCodes.INVALID_REQUEST, "invalid config; fix before patching"),
966+
errorShape(
967+
ErrorCodes.INVALID_REQUEST,
968+
`${summarizeConfigValidationIssues(snapshot.issues)}; fix (openclaw doctor) before patching`,
969+
{ details: { issues: snapshot.issues } },
970+
),
962971
);
963972
return;
964973
}
@@ -1048,12 +1057,13 @@ export const configHandlers: GatewayRequestHandlers = {
10481057
}
10491058
const restoredChangedPaths = diffConfigLeafPaths(snapshot.config, restoredMerge.result);
10501059
if (hashlessPatch && !restoredChangedPaths.every(isHashlessPatchLwwPath)) {
1060+
const guardedPaths = restoredChangedPaths.filter((path) => !isHashlessPatchLwwPath(path));
10511061
respond(
10521062
false,
10531063
undefined,
10541064
errorShape(
10551065
ErrorCodes.INVALID_REQUEST,
1056-
"config base hash required; re-run config.get and retry",
1066+
`config base hash required for ${guardedPaths.join(", ")}; re-run config.get and retry with baseHash`,
10571067
),
10581068
);
10591069
return;

0 commit comments

Comments
 (0)