Skip to content

Commit f1ced37

Browse files
authored
refactor(config): delete dead compat surfaces and write-only error payload (#124067)
* refactor(config): delete dead compat surfaces and write-only error payload Round-5 config-lane sweep; all three deletions verified against the strict root schema and current consumers. - ConfigMutationConflictError.currentHash was write-only: ~20 throw sites computed hashes (some hashing whole files on the failure path purely to populate it) and no consumer anywhere read it — responses carry only the message and .retryable. Field deleted, feeder expressions collapsed. - Root-level channel-key fallbacks (cfg[provider] beside cfg.channels[...]) in chunk limits, block streaming, and channel capabilities were unreachable: the root schema is z.strictObject, so a validated config cannot carry top-level channel keys; doctor owns those moves. Pre-strict-schema era leftovers, deleted. - resolveHeartbeatAckMaxChars existed as three identical constant-returning stubs (heartbeat-runner-config, server-chat, get-reply) left over from the retired heartbeat.ackMaxChars key; inlined the constant, deleted the stubs. - mergeScopedSearchConfig's legacy web-search key delete was a no-op — the agent-runtime schema rejects those keys at validation; helper and dead branch deleted (the schema-side Set remains the rejection boundary). * fix(web-search): restore retired-provider strip in runtime scoped merge The legacy-key delete in mergeScopedSearchConfig is runtime behavior, not schema-shadowed dead code: the merge input is runtime-merged state, so retired provider objects must still be stripped when no plugin config exists (proven by the existing web-search.test.ts regression).
1 parent a4f61d1 commit f1ced37

22 files changed

Lines changed: 36 additions & 116 deletions

‎src/agents/agent-create.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ export async function createAgent(params: CreateAgentParams): Promise<CreateAgen
294294
context.previousHash !== params.expectedConfigHash
295295
) {
296296
throw new ConfigMutationConflictError("config changed before first-agent creation", {
297-
currentHash: context.previousHash,
298297
retryable: false,
299298
});
300299
}

‎src/auto-reply/chunk.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ export function resolveTextChunkLimit(
7272
return undefined;
7373
}
7474
const channelsConfig = cfg?.channels as Record<string, unknown> | undefined;
75-
const providerConfig = (channelsConfig?.[provider] ??
76-
(cfg as Record<string, unknown> | undefined)?.[provider]) as ProviderChunkConfig | undefined;
75+
const providerConfig = channelsConfig?.[provider] as ProviderChunkConfig | undefined;
7776
return resolveChunkLimitForProvider(providerConfig, accountId);
7877
})();
7978
if (typeof providerOverride === "number" && providerOverride > 0) {
@@ -110,8 +109,7 @@ export function resolveChunkMode(
110109
return DEFAULT_CHUNK_MODE;
111110
}
112111
const channelsConfig = cfg?.channels as Record<string, unknown> | undefined;
113-
const providerConfig = (channelsConfig?.[provider] ??
114-
(cfg as Record<string, unknown> | undefined)?.[provider]) as ProviderChunkConfig | undefined;
112+
const providerConfig = channelsConfig?.[provider] as ProviderChunkConfig | undefined;
115113
const mode = resolveChunkModeForProvider(providerConfig, accountId);
116114
return mode ?? DEFAULT_CHUNK_MODE;
117115
}

‎src/auto-reply/reply/block-streaming.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ function resolveProviderBlockStreamingCoalesce(params: {
5151
return undefined;
5252
}
5353
const channelsConfig = cfg.channels as Record<string, unknown> | undefined;
54-
const providerCfg =
55-
channelsConfig?.[providerKey] ?? (cfg as Record<string, unknown>)[providerKey];
54+
const providerCfg = channelsConfig?.[providerKey];
5655
if (!providerCfg || typeof providerCfg !== "object") {
5756
return undefined;
5857
}

‎src/auto-reply/reply/get-reply.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ function classifyHeartbeatPendingFinalDelivery(text: string, ackMaxChars: number
112112
};
113113
}
114114

115-
function resolveHeartbeatAckMaxChars(_cfg: OpenClawConfig, _agentId: string): number {
116-
return DEFAULT_HEARTBEAT_ACK_MAX_CHARS;
117-
}
118-
119115
const sessionResetModelRuntimeLoader = createLazyImportLoader(
120116
() => import("./session-reset-model.runtime.js"),
121117
);
@@ -697,7 +693,7 @@ export async function getReplyFromConfig(
697693
if (opts?.isHeartbeat) {
698694
const heartbeatPending = classifyHeartbeatPendingFinalDelivery(
699695
text,
700-
resolveHeartbeatAckMaxChars(cfg, agentId),
696+
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
701697
);
702698
if (heartbeatPending.shouldClear) {
703699
Object.assign(sessionEntry, PENDING_FINAL_DELIVERY_CLEAR_PATCH);

‎src/cli/plugins-update-command.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,12 @@ function projectUpdaterResultOntoSourceConfig(params: {
128128
}
129129

130130
function assertWriteOptionRecordFresh(params: {
131-
currentHash: string | null;
132131
current?: Record<string, string>;
133132
expected?: Record<string, string>;
134133
message: string;
135134
}): void {
136135
if (!isDeepStrictEqual(params.current ?? {}, params.expected ?? {})) {
137-
throw new ConfigMutationConflictError(params.message, {
138-
currentHash: params.currentHash,
139-
});
136+
throw new ConfigMutationConflictError(params.message);
140137
}
141138
}
142139

@@ -157,23 +154,18 @@ async function assertRecordsOnlyUpdateConfigFresh(params: {
157154
writeOptions.expectedConfigPath !== prepared.snapshot.path
158155
) {
159156
throw new ConfigMutationConflictError("config path changed since last load", {
160-
currentHash,
161157
retryable: false,
162158
});
163159
}
164160
if (params.baseHash !== undefined && params.baseHash !== currentHash) {
165-
throw new ConfigMutationConflictError("config changed since last load", {
166-
currentHash,
167-
});
161+
throw new ConfigMutationConflictError("config changed since last load");
168162
}
169163
assertWriteOptionRecordFresh({
170-
currentHash,
171164
current: prepared.writeOptions.includeFileTargetsForWrite,
172165
expected: params.writeOptions?.includeFileTargetsForWrite,
173166
message: "included config target changed since last load",
174167
});
175168
assertWriteOptionRecordFresh({
176-
currentHash,
177169
current: prepared.writeOptions.includeFileHashesForWrite,
178170
expected: params.writeOptions?.includeFileHashesForWrite,
179171
message: "included config changed since last load",

‎src/cli/update-cli.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,9 @@ vi.mock("../config/config.js", () => ({
157157
}
158158
},
159159
ConfigMutationConflictError: class ConfigMutationConflictError extends Error {
160-
readonly currentHash: string | null;
161-
162-
constructor(message: string, params: { currentHash: string | null }) {
160+
constructor(message: string) {
163161
super(message);
164162
this.name = "ConfigMutationConflictError";
165-
this.currentHash = params.currentHash;
166163
}
167164
},
168165
parseConfigJson5: (raw: string) => {

‎src/commands/configure.wizard.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,7 @@ describe("runConfigureWizard", () => {
998998
if (callCount === 1) {
999999
// First call: simulate plugin mutating config during promptAuthConfig
10001000
expect(params.baseHash).toBe(originalHash);
1001-
throw new ConfigMutationConflictError("config changed since last load", {
1002-
currentHash: newHashAfterMutation,
1003-
});
1001+
throw new ConfigMutationConflictError("config changed since last load");
10041002
}
10051003
// Second call: succeeds with refreshed hash
10061004
expect(params.baseHash).toBe(newHashAfterMutation);
@@ -1084,7 +1082,6 @@ describe("runConfigureWizard", () => {
10841082
});
10851083
mocks.assertConfigPathForWrite.mockImplementation(() => {
10861084
throw new ConfigMutationConflictError("config path changed since last load", {
1087-
currentHash: null,
10881085
retryable: false,
10891086
});
10901087
});

‎src/commands/onboard-non-interactive.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ async function runNonInteractiveMigrationImport(params: {
7373
}
7474
const latestConfig = latest.exists ? (latest.sourceConfig ?? latest.config) : {};
7575
if (!isDeepStrictEqual(latestConfig, expectedConfig)) {
76-
throw new ConfigMutationConflictError("config changed during migration promotion", {
77-
currentHash: latest.hash ?? null,
78-
});
76+
throw new ConfigMutationConflictError("config changed during migration promotion");
7977
}
8078
const committed = await replaceConfigFile({
8179
nextConfig: config,

‎src/config/channel-capabilities.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function resolveChannelCapabilities(params: {
3535
}
3636

3737
const channelsConfig = cfg.channels as Record<string, unknown> | undefined;
38-
const channelConfig = (channelsConfig?.[channel] ?? (cfg as Record<string, unknown>)[channel]) as
38+
const channelConfig = channelsConfig?.[channel] as
3939
| {
4040
accounts?: Record<string, { capabilities?: CapabilitiesConfig }>;
4141
capabilities?: CapabilitiesConfig;

‎src/config/io.snapshot.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ export async function readConfigFileSnapshotForWriteFromContext(
400400
const assertConfigPathForWrite = () => {
401401
if (resolveConfigPathForDeps(context.deps) !== context.configPath) {
402402
throw new ConfigMutationConflictError("config path changed since last load", {
403-
currentHash: null,
404403
retryable: false,
405404
});
406405
}

0 commit comments

Comments
 (0)