Skip to content

Hotfix SDK Dropping Logs#37

Open
mchlggr wants to merge 1 commit into
mainfrom
hotfix/sdk-dropping-logs
Open

Hotfix SDK Dropping Logs#37
mchlggr wants to merge 1 commit into
mainfrom
hotfix/sdk-dropping-logs

Conversation

@mchlggr

@mchlggr mchlggr commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Refined session ID capture logic for improved session management accuracy.
  • Improvements

    • Enhanced OpenAI API key integration to properly utilize configured credentials during execution.
    • Improved message processing and output handling for synthetic user messages.

@coderabbitai

coderabbitai Bot commented Mar 25, 2026

Copy link
Copy Markdown

Walkthrough

The changes introduce OpenAI API key configuration support across two executor services. In claude-cli-executor.ts, the executeTask method now reads the OpenAI API key from ConfigManager and sets it as an environment variable before spawning the Claude CLI. Similarly, claude-executor.ts expands its environment setup to include the OpenAI API key from configuration. Additionally, claude-executor.ts now handles synthetic user messages by extracting text content and displaying it to stdout in cyan, while removing the previous generic session ID capture fallback logic.

Poem

🐰 Hoppy changes bring such glee,

OpenAI keys now flow so free,

Synthetic messages hop in sight,

Painted cyan, oh what a delight!

Config magic, clean and bright,

The Claude CLI takes flight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Hotfix SDK Dropping Logs' directly addresses the main issue being fixed: SDK messages (logs) being dropped. The changes in both files add handling for synthetic user messages from the SDK that were previously being lost, and adjust environment setup for API keys. The title accurately reflects this primary concern.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/sdk-dropping-logs

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/services/claude-executor.ts`:
- Around line 216-233: The CI flagged Prettier formatting issues around the
synthetic user-message handling block (the code checking message.type === 'user'
and message.isSynthetic and updating currentResponse and calling
process.stdout.write(chalk.cyan(...))). Re-run the formatter (npx prettier
--write) on src/services/claude-executor.ts or manually adjust formatting in
that block so the nested ternary and array processing (the content-to-text
conversion), the process.stdout.write(chalk.cyan(text) + '\n'), and
currentResponse += text + '\n' lines conform to project Prettier rules
(consistent indentation, line breaks, and spacing) to resolve the CI failure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 84aaca4c-941f-40c6-aa7f-bcccf74b3ac2

📥 Commits

Reviewing files that changed from the base of the PR and between 1cdf9af and c5b365f.

📒 Files selected for processing (2)
  • src/services/claude-cli-executor.ts
  • src/services/claude-executor.ts
📜 Review details
🧰 Additional context used
🪛 GitHub Actions: CI
src/services/claude-executor.ts

[warning] 1-1: Prettier --check reported formatting/style issues in this file.

🔇 Additional comments (4)
src/services/claude-cli-executor.ts (1)

43-46: LGTM!

The truthiness check if (openaiKey) correctly prevents overwriting a valid pre-existing OPENAI_API_KEY environment variable when the config value is an empty string. This defensive approach properly handles the case where openaiApiKey is initialized as '' in the config defaults (as shown in src/config.ts:418).

src/services/claude-executor.ts (3)

45-48: LGTM!

The OPENAI_API_KEY handling is correctly implemented with a truthiness guard, consistent with the approach in claude-cli-executor.ts.


216-233: LGTM!

The synthetic user message handling is well-implemented:

  • Correctly checks message.isSynthetic to filter hook-injected context
  • Handles both string and array content formats with proper type narrowing
  • The type predicate filter safely narrows the content block type

This change addresses the "SDK Dropping Logs" issue by ensuring hook-injected content (e.g., ivan learnings) is now displayed and logged.


251-256: Verify that session ID is reliably captured from system-init messages.

The code now captures session_id only from system messages with subtype === 'init'. The caller in src/services/task-executor.ts (lines 740, 855) depends on the returned sessionId to maintain context across consecutive executeTask() calls. If the SDK sends session_id in other message types (e.g., during resume or other events), those will no longer be captured, potentially breaking session continuity.

Confirm with the SDK documentation that session_id is always reliably emitted in the system-init message and not in other message types during typical execution flows.

Comment on lines +216 to +233
} else if (message.type === 'user') {
// Synthetic user messages carry hook-injected context (e.g. ivan learnings)
if (message.isSynthetic) {
const content = message.message.content;
const text =
typeof content === 'string'
? content
: Array.isArray(content)
? content
.filter((b): b is { type: 'text'; text: string } => b.type === 'text')
.map((b) => b.text)
.join('\n')
: null;
if (text) {
process.stdout.write(chalk.cyan(text) + '\n');
currentResponse += text + '\n';
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Address Prettier formatting issues flagged by CI.

The pipeline reports formatting issues in this file. Please run the formatter to resolve:

npx prettier --write src/services/claude-executor.ts
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/claude-executor.ts` around lines 216 - 233, The CI flagged
Prettier formatting issues around the synthetic user-message handling block (the
code checking message.type === 'user' and message.isSynthetic and updating
currentResponse and calling process.stdout.write(chalk.cyan(...))). Re-run the
formatter (npx prettier --write) on src/services/claude-executor.ts or manually
adjust formatting in that block so the nested ternary and array processing (the
content-to-text conversion), the process.stdout.write(chalk.cyan(text) + '\n'),
and currentResponse += text + '\n' lines conform to project Prettier rules
(consistent indentation, line breaks, and spacing) to resolve the CI failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant