mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 18:00:44 +00:00
perf(doctor): skip plugin scans for unrelated session state
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
applySessionRouteStateRepair,
|
||||
resolveConfiguredDoctorSessionStateRoute,
|
||||
scanSessionRouteStateOwners,
|
||||
storeMayContainPluginSessionRouteState,
|
||||
} from "./doctor-session-state-providers.js";
|
||||
|
||||
const codexOwner = {
|
||||
@@ -15,6 +16,35 @@ const codexOwner = {
|
||||
};
|
||||
|
||||
describe("doctor session state provider routes", () => {
|
||||
it("skips plugin route-state scans for unrelated recovery metadata", () => {
|
||||
expect(
|
||||
storeMayContainPluginSessionRouteState({
|
||||
"agent:main:subagent:wedged-child": {
|
||||
sessionId: "session-wedged-child",
|
||||
updatedAt: 1,
|
||||
abortedLastRun: true,
|
||||
subagentRecovery: {
|
||||
automaticAttempts: 2,
|
||||
lastAttemptAt: 1,
|
||||
wedgedAt: 2,
|
||||
wedgedReason: "blocked",
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
storeMayContainPluginSessionRouteState({
|
||||
"agent:main:telegram:direct:1": {
|
||||
sessionId: "session-codex",
|
||||
updatedAt: 1,
|
||||
modelProvider: "openai-codex",
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves raw configured CLI runtimes before harness policy normalization", () => {
|
||||
expect(
|
||||
resolveConfiguredDoctorSessionStateRoute({
|
||||
|
||||
@@ -126,6 +126,29 @@ function resolvePluginDoctorSessionRouteStateOwners(params: {
|
||||
return listPluginDoctorSessionRouteStateOwners({ env: params.env });
|
||||
}
|
||||
|
||||
function entryMayContainPluginSessionRouteState(entry: SessionEntry): boolean {
|
||||
const record = entry as unknown as Record<string, unknown>;
|
||||
return (
|
||||
normalizeString(record.providerOverride) !== undefined ||
|
||||
normalizeString(record.modelOverride) !== undefined ||
|
||||
normalizeString(record.modelOverrideSource) !== undefined ||
|
||||
record.liveModelSwitchPending !== undefined ||
|
||||
normalizeString(record.modelProvider) !== undefined ||
|
||||
normalizeString(record.model) !== undefined ||
|
||||
normalizeString(record.agentHarnessId) !== undefined ||
|
||||
record.cliSessionBindings !== undefined ||
|
||||
record.cliSessionIds !== undefined ||
|
||||
normalizeString(record.authProfileOverride) !== undefined ||
|
||||
normalizeString(record.authProfileOverrideSource) !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
export function storeMayContainPluginSessionRouteState(
|
||||
store: Record<string, SessionEntry>,
|
||||
): boolean {
|
||||
return Object.values(store).some((entry) => entryMayContainPluginSessionRouteState(entry));
|
||||
}
|
||||
|
||||
export type DoctorSessionRouteState = {
|
||||
defaultProvider: string;
|
||||
configuredModelRefs: string[];
|
||||
@@ -434,6 +457,9 @@ export async function runPluginSessionStateDoctorRepairs(params: {
|
||||
warnings: string[];
|
||||
changes: string[];
|
||||
}): Promise<void> {
|
||||
if (!storeMayContainPluginSessionRouteState(params.store)) {
|
||||
return;
|
||||
}
|
||||
const owners = resolvePluginDoctorSessionRouteStateOwners({ env: params.env });
|
||||
if (owners.length === 0) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user