fix: terminate telemetry work on disposal

Give the best-effort telemetry adapter a terminal ACTIVE/DISPOSED lifecycle.
dispose() now removes the pagehide listener, clears the queue, invalidates
scheduled callback generations and aborts the in-flight sink; emit after
dispose is a no-op and a sink that ignores the abort cannot reschedule or
update post-dispose state. flush() joins the active delivery instead of
resolving early, and runtime infrastructure teardown disposes telemetry first.

Telemetry and diagnostics capacities are validated at construction against a
documented ceiling, so NaN or Infinity can no longer disable eviction.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-08-13 23:05:43 +09:00
co-authored by Claude Opus 5
parent e06e4377ca
commit 6d1e44f206
7 changed files with 269 additions and 25 deletions
+32
View File
@@ -138,6 +138,38 @@ describe("runtime adapter composition", () => {
adapters.infrastructure.dispose();
});
it("runtime infrastructure disposal disposes telemetry first", async () => {
const fetcher = vi.fn(async () => new Response(null, { status: 204 }));
const adapters = await createRuntimeAdapters({
runtime: {
...runtime,
config: {
...runtime.config,
TELEMETRY_ENABLED: true,
TELEMETRY_ENDPOINT: "https://telemetry.test/events",
},
} as Runtime,
release,
host: {},
fetcher: fetcher as unknown as typeof fetch,
});
adapters.outputPorts.telemetry.emit("api.request.failed", {
error_kind: "SERVER_FAILURE",
http_status_group: "5xx",
attempt_count_bucket: "1",
route_id: "TEST_ROUTE",
});
expect(adapters.outputPorts.telemetry.pendingCount()).toBe(1);
adapters.infrastructure.dispose();
expect(adapters.outputPorts.telemetry.pendingCount()).toBe(0);
await Promise.resolve();
await Promise.resolve();
expect(fetcher).not.toHaveBeenCalled();
});
it("replaces the QueryClient and coordinator for each session generation", async () => {
const adapters = await createRuntimeAdapters({ runtime, release, host: {} });
const previousClient = adapters.infrastructure.queryClient;