Skip to content

Commit 1692264

Browse files
committed
perf(doctor): skip plugin scans for unrelated session state
1 parent 1ab00c4 commit 1692264

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/commands/doctor-session-state-providers.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
applySessionRouteStateRepair,
44
resolveConfiguredDoctorSessionStateRoute,
55
scanSessionRouteStateOwners,
6+
storeMayContainPluginSessionRouteState,
67
} from "./doctor-session-state-providers.js";
78

89
const codexOwner = {
@@ -15,6 +16,35 @@ const codexOwner = {
1516
};
1617

1718
describe("doctor session state provider routes", () => {
19+
it("skips plugin route-state scans for unrelated recovery metadata", () => {
20+
expect(
21+
storeMayContainPluginSessionRouteState({
22+
"agent:main:subagent:wedged-child": {
23+
sessionId: "session-wedged-child",
24+
updatedAt: 1,
25+
abortedLastRun: true,
26+
subagentRecovery: {
27+
automaticAttempts: 2,
28+
lastAttemptAt: 1,
29+
wedgedAt: 2,
30+
wedgedReason: "blocked",
31+
},
32+
},
33+
}),
34+
).toBe(false);
35+
36+
expect(
37+
storeMayContainPluginSessionRouteState({
38+
"agent:main:telegram:direct:1": {
39+
sessionId: "session-codex",
40+
updatedAt: 1,
41+
modelProvider: "openai-codex",
42+
model: "gpt-5.4",
43+
},
44+
}),
45+
).toBe(true);
46+
});
47+
1848
it("preserves raw configured CLI runtimes before harness policy normalization", () => {
1949
expect(
2050
resolveConfiguredDoctorSessionStateRoute({

src/commands/doctor-session-state-providers.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ function resolvePluginDoctorSessionRouteStateOwners(params: {
126126
return listPluginDoctorSessionRouteStateOwners({ env: params.env });
127127
}
128128

129+
function entryMayContainPluginSessionRouteState(entry: SessionEntry): boolean {
130+
const record = entry as unknown as Record<string, unknown>;
131+
return (
132+
normalizeString(record.providerOverride) !== undefined ||
133+
normalizeString(record.modelOverride) !== undefined ||
134+
normalizeString(record.modelOverrideSource) !== undefined ||
135+
record.liveModelSwitchPending !== undefined ||
136+
normalizeString(record.modelProvider) !== undefined ||
137+
normalizeString(record.model) !== undefined ||
138+
normalizeString(record.agentHarnessId) !== undefined ||
139+
record.cliSessionBindings !== undefined ||
140+
record.cliSessionIds !== undefined ||
141+
normalizeString(record.authProfileOverride) !== undefined ||
142+
normalizeString(record.authProfileOverrideSource) !== undefined
143+
);
144+
}
145+
146+
export function storeMayContainPluginSessionRouteState(
147+
store: Record<string, SessionEntry>,
148+
): boolean {
149+
return Object.values(store).some((entry) => entryMayContainPluginSessionRouteState(entry));
150+
}
151+
129152
export type DoctorSessionRouteState = {
130153
defaultProvider: string;
131154
configuredModelRefs: string[];
@@ -434,6 +457,9 @@ export async function runPluginSessionStateDoctorRepairs(params: {
434457
warnings: string[];
435458
changes: string[];
436459
}): Promise<void> {
460+
if (!storeMayContainPluginSessionRouteState(params.store)) {
461+
return;
462+
}
437463
const owners = resolvePluginDoctorSessionRouteStateOwners({ env: params.env });
438464
if (owners.length === 0) {
439465
return;

0 commit comments

Comments
 (0)