refactor: remove debug logging and simplify event identifier extraction
This commit is contained in:
@@ -3,7 +3,7 @@ import type { Logger } from "pino";
|
|||||||
|
|
||||||
import { createTestLogger } from "../../../test-utils/test-logger.js";
|
import { createTestLogger } from "../../../test-utils/test-logger.js";
|
||||||
import { AgentManager } from "../agent-manager.js";
|
import { AgentManager } from "../agent-manager.js";
|
||||||
import { ClaudeAgentClient } from "./claude-agent.js";
|
import { ClaudeAgentClient, readEventIdentifiers } from "./claude-agent.js";
|
||||||
import type { AgentStreamEvent, AgentTimelineItem } from "../agent-sdk-types.js";
|
import type { AgentStreamEvent, AgentTimelineItem } from "../agent-sdk-types.js";
|
||||||
|
|
||||||
const sdkMocks = vi.hoisted(() => ({
|
const sdkMocks = vi.hoisted(() => ({
|
||||||
@@ -325,13 +325,7 @@ describe("ClaudeAgentSession redesign invariants", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("extracts identifiers from fixture-driven protocol shape variants", async () => {
|
test("extracts identifiers from fixture-driven protocol shape variants", () => {
|
||||||
const spy = createSpyLogger();
|
|
||||||
const session = await createSessionWithLogger(spy.logger);
|
|
||||||
const internal = session as unknown as {
|
|
||||||
routeSdkMessageFromPump: (message: Record<string, unknown>) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const fixtures = [
|
const fixtures = [
|
||||||
{
|
{
|
||||||
name: "root identifiers take priority over nested variants",
|
name: "root identifiers take priority over nested variants",
|
||||||
@@ -406,23 +400,12 @@ describe("ClaudeAgentSession redesign invariants", () => {
|
|||||||
},
|
},
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
try {
|
for (const fixture of fixtures) {
|
||||||
for (const fixture of fixtures) {
|
expect(
|
||||||
spy.debug.mockClear();
|
readEventIdentifiers(
|
||||||
internal.routeSdkMessageFromPump(
|
fixture.message as unknown as Parameters<typeof readEventIdentifiers>[0]
|
||||||
fixture.message as unknown as Record<string, unknown>
|
)
|
||||||
);
|
).toEqual(fixture.expected);
|
||||||
const routingCall = spy.debug.mock.calls.find(
|
|
||||||
(args) => args[1] === "Claude query pump routing decision"
|
|
||||||
);
|
|
||||||
expect(routingCall).toBeDefined();
|
|
||||||
const payload = routingCall?.[0] as
|
|
||||||
| { identifiers?: Record<string, string | null> }
|
|
||||||
| undefined;
|
|
||||||
expect(payload?.identifiers).toEqual(fixture.expected);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
await session.close();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1280,7 +1280,7 @@ function isMetadataOnlySdkMessage(message: SDKMessage): boolean {
|
|||||||
return isTaskNotificationUserContent(message.message?.content);
|
return isTaskNotificationUserContent(message.message?.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
function readEventIdentifiers(message: SDKMessage): EventIdentifiers {
|
export function readEventIdentifiers(message: SDKMessage): EventIdentifiers {
|
||||||
const root = message as unknown as Record<string, unknown>;
|
const root = message as unknown as Record<string, unknown>;
|
||||||
const messageType = readTrimmedString(root.type);
|
const messageType = readTrimmedString(root.type);
|
||||||
const streamEvent = root.event as Record<string, unknown> | undefined;
|
const streamEvent = root.event as Record<string, unknown> | undefined;
|
||||||
@@ -2445,10 +2445,6 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private emitRunEvent(run: RunRecord, event: AgentStreamEvent): void {
|
private emitRunEvent(run: RunRecord, event: AgentStreamEvent): void {
|
||||||
this.logger.debug(
|
|
||||||
{ runId: run.id, owner: run.owner, eventType: event.type },
|
|
||||||
"Claude run event dispatch"
|
|
||||||
);
|
|
||||||
if (run.owner === "foreground" && run.queue) {
|
if (run.owner === "foreground" && run.queue) {
|
||||||
run.queue.push(event);
|
run.queue.push(event);
|
||||||
if (
|
if (
|
||||||
@@ -2480,12 +2476,6 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
this.preReplayMetadataSeen = false;
|
this.preReplayMetadataSeen = false;
|
||||||
}
|
}
|
||||||
this.transitionTurnStateFromActiveRuns(`run ${run.id} terminal`);
|
this.transitionTurnStateFromActiveRuns(`run ${run.id} terminal`);
|
||||||
this.logDerivedSessionLifecycle("terminal_event");
|
|
||||||
}
|
|
||||||
|
|
||||||
private logDerivedSessionLifecycle(context: string): void {
|
|
||||||
const lifecycle = this.runTracker.deriveLifecycle(this.pendingPermissions.size);
|
|
||||||
this.logger.debug({ lifecycle, context }, "Claude session lifecycle derived");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async transitionAutonomousToForeground(): Promise<void> {
|
private async transitionAutonomousToForeground(): Promise<void> {
|
||||||
@@ -2829,17 +2819,6 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.debug(
|
|
||||||
{
|
|
||||||
routeReason: route.reason,
|
|
||||||
runId: route.run?.id ?? null,
|
|
||||||
turnState: this.turnState,
|
|
||||||
metadataOnly,
|
|
||||||
identifiers,
|
|
||||||
},
|
|
||||||
"Claude query pump routing decision"
|
|
||||||
);
|
|
||||||
|
|
||||||
const messageEvents = this.translateMessageToEvents(message, {
|
const messageEvents = this.translateMessageToEvents(message, {
|
||||||
suppressAssistantText: true,
|
suppressAssistantText: true,
|
||||||
suppressReasoning: true,
|
suppressReasoning: true,
|
||||||
@@ -2934,17 +2913,13 @@ class ClaudeAgentSession implements AgentSession {
|
|||||||
message.type === "tool_progress"
|
message.type === "tool_progress"
|
||||||
) {
|
) {
|
||||||
this.runTracker.transition(run, "streaming");
|
this.runTracker.transition(run, "streaming");
|
||||||
this.logDerivedSessionLifecycle("streaming_event");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === "result") {
|
if (message.type === "result") {
|
||||||
this.runTracker.transition(run, "finalizing");
|
this.runTracker.transition(run, "finalizing");
|
||||||
this.logDerivedSessionLifecycle("result_event");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logDerivedSessionLifecycle("non_terminal_event");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private shouldSuppressLocalReplayActivity(message: SDKMessage): boolean {
|
private shouldSuppressLocalReplayActivity(message: SDKMessage): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user