Skip to content

Commit 907bc03

Browse files
SebTardifsteipete
andauthored
fix(agents): log warnings instead of swallowing subagent errors (#82943)
* fix: log subagent swallowed errors in hook emission and restore paths Wire createSubsystemLogger into the two silent catch blocks that discard errors during subagent lifecycle: 1. emitSubagentEndedHookOnce (subagent-registry-completion.ts): catch { return false } -> catch (err) { log.warn(...); return false } 2. restoreSubagentRunsOnce (subagent-registry.ts): catch { /* ignore */ } -> catch (err) { log.warn(...) } Both paths now log the error message before continuing, providing a diagnostic trail when hook emission or disk restore fails silently. Signed-off-by: Sebastien Tardif <[email protected]> * test(agents): keep provider test mocks current --------- Signed-off-by: Sebastien Tardif <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent f0061dd commit 907bc03

6 files changed

Lines changed: 48 additions & 3 deletions

src/agents/model-fallback.probe.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,42 @@ vi.mock("./provider-model-normalization.runtime.js", () => ({
2828
}));
2929

3030
const emptyPluginMetadataSnapshot = vi.hoisted(() => ({
31+
policyHash: "model-fallback-probe-test-empty-plugin-policy",
3132
configFingerprint: "model-fallback-probe-test-empty-plugin-metadata",
33+
index: {
34+
hostContractVersion: "test",
35+
compatRegistryVersion: "test",
36+
migrationVersion: 1,
37+
policyHash: "model-fallback-probe-test-empty-plugin-policy",
38+
generatedAtMs: 0,
39+
installRecords: {},
40+
plugins: [],
41+
diagnostics: [],
42+
},
43+
registryDiagnostics: [],
44+
manifestRegistry: { plugins: [], diagnostics: [] },
3245
plugins: [],
46+
diagnostics: [],
47+
byPluginId: new Map(),
48+
normalizePluginId: (pluginId: string) => pluginId,
49+
owners: {
50+
channels: new Map(),
51+
channelConfigs: new Map(),
52+
providers: new Map(),
53+
modelCatalogProviders: new Map(),
54+
cliBackends: new Map(),
55+
setupProviders: new Map(),
56+
commandAliases: new Map(),
57+
contracts: new Map(),
58+
},
59+
metrics: {
60+
registrySnapshotMs: 0,
61+
manifestRegistryMs: 0,
62+
ownerMapsMs: 0,
63+
totalMs: 0,
64+
indexPluginCount: 0,
65+
manifestPluginCount: 0,
66+
},
3367
}));
3468

3569
vi.mock("../plugins/current-plugin-metadata-snapshot.js", () => ({

src/agents/pi-embedded-runner-extraparams.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import { testing as extraParamsTesting } from "./pi-embedded-runner/extra-params.js";
66

77
vi.mock("../plugins/provider-hook-runtime.js", () => ({
8+
clearProviderRuntimePluginCacheForTest: vi.fn(),
89
testing: {
910
buildHookProviderCacheKey: () => "test-provider-hook-cache-key",
1011
},

src/agents/pi-embedded-runner.sanitize-session-history.test-harness.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function createSanitizeSessionHistoryProviderHookRuntimeMock(
8888
extra: Record<string, unknown> = {},
8989
) {
9090
return {
91+
clearProviderRuntimePluginCacheForTest: vi.fn(),
9192
resolveProviderRuntimePlugin: vi.fn(() => undefined),
9293
resolveProviderHookPlugin: vi.fn(() => undefined),
9394
resolveProviderPluginsForHooks: vi.fn(() => []),

src/agents/pi-embedded-runner.sanitize-session-history.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ vi.mock("./pi-embedded-helpers.js", async () => ({
2929
}));
3030

3131
vi.mock("../plugins/provider-hook-runtime.js", async () => ({
32+
clearProviderRuntimePluginCacheForTest: vi.fn(),
3233
testing: {},
3334
prepareProviderExtraParams: vi.fn(() => undefined),
3435
resolveProviderHookPlugin: vi.fn(() => undefined),

src/agents/subagent-registry-completion.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createSubsystemLogger } from "../logging/subsystem.js";
12
import { getGlobalHookRunner } from "../plugins/hook-runner-global.js";
23
import type { SubagentRunOutcome } from "./subagent-announce-output.js";
34
import {
@@ -10,6 +11,8 @@ import {
1011
} from "./subagent-lifecycle-events.js";
1112
import type { SubagentRunRecord } from "./subagent-registry.types.js";
1213

14+
const log = createSubsystemLogger("agents/subagent-registry-completion");
15+
1316
export function runOutcomesEqual(
1417
a: SubagentRunOutcome | undefined,
1518
b: SubagentRunOutcome | undefined,
@@ -113,7 +116,10 @@ export async function emitSubagentEndedHookOnce(params: {
113116
params.entry.endedHookEmittedAt = Date.now();
114117
params.persist();
115118
return true;
116-
} catch {
119+
} catch (err) {
120+
log.warn(
121+
`failed to emit subagent_ended hook for run ${runId}: ${err instanceof Error ? err.message : String(err)}`,
122+
);
117123
return false;
118124
} finally {
119125
params.inFlightRunIds.delete(runId);

src/agents/subagent-registry.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,10 @@ function restoreSubagentRunsOnce() {
646646
// Cold-start restore path: queue the same recovery pass that restart
647647
// startup also uses so resumed children are handled through one seam.
648648
scheduleSubagentOrphanRecovery();
649-
} catch {
650-
// ignore restore failures
649+
} catch (err) {
650+
log.warn(
651+
`failed to restore subagent runs from disk: ${err instanceof Error ? err.message : String(err)}`,
652+
);
651653
}
652654
}
653655

0 commit comments

Comments
 (0)