Gate Claude SDK stream trace logs behind PASEO_CLAUDE_DEBUG

Per-token trace logs from the query pump fire twice per streaming event
and contribute to memory growth under heavy use. Gate them behind an
opt-in env var so they're available for debugging but silent by default.
This commit is contained in:
Mohamed Boudra
2026-04-10 10:05:13 +07:00
parent edfd2564a3
commit 9f09a19a09
2 changed files with 26 additions and 17 deletions
+3
View File
@@ -18,3 +18,6 @@ PASEO_LISTEN=127.0.0.1:6767
# Debug recordings (dictation + STT input + TTS output) # Debug recordings (dictation + STT input + TTS output)
# When enabled, recordings are saved under `${cwd}/.debug/recordings/` # When enabled, recordings are saved under `${cwd}/.debug/recordings/`
PASEO_DICTATION_DEBUG=1 PASEO_DICTATION_DEBUG=1
# Enable verbose Claude SDK stream logging (trace-level per-token logs)
PASEO_CLAUDE_DEBUG=1
@@ -1047,6 +1047,8 @@ export function readEventIdentifiers(message: SDKMessage): EventIdentifiers {
}; };
} }
const claudeDebug = process.env.PASEO_CLAUDE_DEBUG === "1";
export class ClaudeAgentClient implements AgentClient { export class ClaudeAgentClient implements AgentClient {
readonly provider: "claude" = "claude"; readonly provider: "claude" = "claude";
readonly capabilities = CLAUDE_CAPABILITIES; readonly capabilities = CLAUDE_CAPABILITIES;
@@ -2454,15 +2456,17 @@ class ClaudeAgentSession implements AgentSession {
while (!this.closed && this.query === activeQuery) { while (!this.closed && this.query === activeQuery) {
try { try {
for await (const message of activeQuery) { for await (const message of activeQuery) {
this.logger.trace( if (claudeDebug) {
{ this.logger.trace(
claudeSessionId: this.claudeSessionId, {
messageType: message.type, claudeSessionId: this.claudeSessionId,
messageSubtype: "subtype" in message ? message.subtype : undefined, messageType: message.type,
messageUuid: "uuid" in message ? message.uuid : undefined, messageSubtype: "subtype" in message ? message.subtype : undefined,
}, messageUuid: "uuid" in message ? message.uuid : undefined,
"Claude query pump: raw SDK message", },
); "Claude query pump: raw SDK message",
);
}
consecutiveInterruptAbortRecoveries = 0; consecutiveInterruptAbortRecoveries = 0;
if (await this.handleMissingResumedConversation(message, activeQuery)) { if (await this.handleMissingResumedConversation(message, activeQuery)) {
return; return;
@@ -2538,14 +2542,16 @@ class ClaudeAgentSession implements AgentSession {
const turnId = this.activeForegroundTurnId ?? this.autonomousTurn?.id ?? null; const turnId = this.activeForegroundTurnId ?? this.autonomousTurn?.id ?? null;
const identifiers = readEventIdentifiers(message); const identifiers = readEventIdentifiers(message);
this.logger.trace( if (claudeDebug) {
{ this.logger.trace(
claudeSessionId: this.claudeSessionId, {
messageType: message.type, claudeSessionId: this.claudeSessionId,
turnId, messageType: message.type,
}, turnId,
"Claude query pump: SDK message", },
); "Claude query pump: SDK message",
);
}
const messageEvents = this.translateMessageToEvents(message, { const messageEvents = this.translateMessageToEvents(message, {
suppressAssistantText: true, suppressAssistantText: true,