Skip to content

fix(desktop): ship chat-runtime migrations + Claude SDK binary path to host-service - #6217

Merged
saddlepaddle merged 3 commits into
mainfrom
chat-v3-migrations-wiring
Aug 10, 2026
Merged

saddlepaddle merged 3 commits into
mainfrom
chat-v3-migrations-wiring

Conversation

@saddlepaddle

@saddlepaddle saddlepaddle commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Two twin bundling bugs found by the CDP gate, both 'runtime file dependency unresolvable from the bundled host-service': (1) chat.db migrations — folder now ships like host-migrations (vite copy + extraResources + coordinator env), turbo passthrough added; verified live: chat.db gets its tables. (2) The Agent SDK's bundled Claude CLI — adapter/mount accept pathToClaudeCodeExecutable, coordinator resolves from the bun store in dev (SUPERSET_CHAT_V3_CLAUDE_BIN); packaged builds are an IOU (231MB binary — extraResources vs resolving user's installed claude, to decide). Also deletes the corrupted zero-table chat.db recovery case by failing loud.

https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h


Summary by cubic

Fixes two bundling issues and a session status bug: ships chat.db migrations as resources, wires the Claude SDK CLI path via env, and emits session idle after a turn so the UI doesn’t stick on “Working”.

  • Bug Fixes
    • Ship chat-runtime migrations with the app and pass their path via SUPERSET_CHAT_V3_MIGRATIONS (Vite copy + Electron extraResources; Turbo env passthrough). Host-service reads this to run migrations.
    • Resolve the Claude Agent SDK CLI in dev by threading pathToClaudeCodeExecutable and setting SUPERSET_CHAT_V3_CLAUDE_BIN from the Bun store. Host-service forwards it to createClaudeAdapter.
    • Emit a "session idle" event after a turn completes or interrupts to reset session status and prevent the UI from staying on “Working”.

Written for commit 3fc2ec0. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Improvements
    • Improved Claude-powered chat integration by supporting the appropriate Claude Code executable in development environments.
    • Ensured chat database migrations are included and available in both development and packaged desktop builds.
    • Improved reliability when the Claude Code executable is unavailable or cannot be located.
    • Added clearer session-idle notifications after completed or interrupted chat interactions.
  • Tests
    • Updated chat session behavior checks to reflect the new completion and idle-event sequence.

…esolvable from bundled host-service

Same failure mode as the migrations folder: the Agent SDK resolves its
bundled CLI relative to its own module, which breaks inside the bundled
host-service (and bun's isolated linker hides the platform package from
apps/desktop). Adapter/mount accept an explicit path; coordinator resolves
it from the bun store in dev via SUPERSET_CHAT_V3_CLAUDE_BIN. Packaged
builds are an open IOU (231MB binary).

Claude-Session: https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change packages chat migrations, exposes migration and Claude executable paths to the host service, forwards the optional Claude SDK executable path through the Claude harness, and emits idle session events after Claude results.

Changes

Chat V3 runtime integration

Layer / File(s) Summary
Chat resource packaging and environment
apps/desktop/vite/helpers.ts, apps/desktop/electron-builder.ts, apps/desktop/src/main/lib/host-service-coordinator.ts, turbo.jsonc
Builds copy chat migrations into resources. The host service receives migration paths and, in development builds, the discovered Claude SDK binary path.
Claude adapter executable configuration
packages/chat-runtime/src/harness/claude/..., packages/host-service/src/chat-v3/mount.ts
The Claude adapter and factory accept an optional executable path. The host mount passes SUPERSET_CHAT_V3_CLAUDE_BIN to the adapter, which forwards it to the SDK query.
Claude session idle events
packages/chat-runtime/src/harness/claude/translateStream/translateStream.ts, packages/chat-runtime/src/harness/claude/translateStream/translateStream.test.ts
The stream translator emits a session-idle event after interrupted, successful, or failed results. The zero-cost turn test verifies the event order.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DesktopHostServiceCoordinator
  participant HostServiceMount
  participant ClaudeAdapter
  participant ClaudeSDK
  participant StreamTranslator
  DesktopHostServiceCoordinator->>HostServiceMount: Set SUPERSET_CHAT_V3_CLAUDE_BIN
  HostServiceMount->>ClaudeAdapter: Pass pathToClaudeCodeExecutable
  ClaudeAdapter->>ClaudeSDK: Forward executable path in query options
  ClaudeSDK-->>StreamTranslator: Return Claude result
  StreamTranslator-->>HostServiceMount: Emit completed or interrupted turn
  StreamTranslator-->>HostServiceMount: Emit session-idle event
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary changes and follows the required conventional commit format.
Description check ✅ Passed The description explains the changes, testing result, known packaged-build limitation, and includes all required template sections.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chat-v3-migrations-wiring

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR ships chat-runtime migrations alongside the desktop host-service and threads an explicit Claude Agent SDK executable path through the host-service and chat adapter.

  • Copies chat migrations into development and packaged desktop resources.
  • Supplies migration and Claude executable paths through the host-service environment.
  • Extends the Claude adapter factory and query options to accept the executable path.
  • Adds both variables to Turbo's environment passthrough.

Confidence Score: 4/5

The host-service adoption path must be updated before merging so existing processes cannot bypass the migration and Claude runtime-path fixes.

Newly spawned services receive the required paths, but healthy services adopted after an upgrade or from another worktree retain their old environment and can continue hitting the unresolved runtime dependencies this change is intended to fix.

Files Needing Attention: apps/desktop/src/main/lib/host-service-coordinator.ts

Important Files Changed

Filename Overview
apps/desktop/src/main/lib/host-service-coordinator.ts Adds migration and Claude executable environment values, but adopted host-service processes never receive them.
apps/desktop/electron-builder.ts Adds the generated chat migration directory to packaged resources with a layout matching the coordinator path.
apps/desktop/vite/helpers.ts Copies chat migration files into desktop build resources alongside host-service migrations.
packages/host-service/src/chat-v3/mount.ts Threads the Claude executable environment value into the harness while retaining the module-relative migration fallback.
packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts Adds the SDK executable option to the adapter and forwards it to each Claude query.
packages/chat-runtime/src/harness/claude/createClaudeAdapter/createClaudeAdapter.ts Extends the adapter factory with an optional executable path.
turbo.jsonc Allows the two new chat-runtime environment variables through Turbo task isolation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Desktop[Desktop coordinator] -->|spawn with environment| Host[Host service]
  Desktop -.->|adopt existing process; environment unchanged| Existing[Existing host service]
  Host -->|migration folder| ChatDB[(chat.db migrations)]
  Host -->|Claude executable path| Adapter[Claude adapter]
  Existing -->|fallback module path| ChatDB
  Existing -->|undefined executable path| Adapter
Loading
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/main/lib/host-service-coordinator.ts:791-802
**Adoption preserves stale runtime paths**

If an upgrade or another development worktree leaves a healthy older host-service running, the coordinator adopts it without rebuilding its environment or checking build compatibility. The adopted service therefore lacks the explicit migration and Claude executable paths, causing chat database initialization or Claude session startup to fail until the service is replaced.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(chat-runtime): thread pathToClaudeCo..." | Re-trigger Greptile

Comment on lines +791 to +802
SUPERSET_CHAT_V3_MIGRATIONS: app.isPackaged
? path.join(process.resourcesPath, "resources/chat-migrations")
: path.join(
app.getAppPath(),
"../../packages/chat-runtime/src/db/drizzle",
),
// The Claude Agent SDK's bundled CLI binary is unresolvable from the
// bundled host-service (isolated linker + bundling), so its path comes
// in as env too. Packaged builds are an open IOU (231MB binary).
...(chatV3ClaudeBin()
? { SUPERSET_CHAT_V3_CLAUDE_BIN: chatV3ClaudeBin() as string }
: {}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Adoption preserves stale runtime paths

If an upgrade or another development worktree leaves a healthy older host-service running, the coordinator adopts it without rebuilding its environment or checking build compatibility. The adopted service therefore lacks the explicit migration and Claude executable paths, causing chat database initialization or Claude session startup to fail until the service is replaced.

Knowledge Base Used: Desktop App (Electron main + renderer)

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/lib/host-service-coordinator.ts
Line: 791-802

Comment:
**Adoption preserves stale runtime paths**

If an upgrade or another development worktree leaves a healthy older host-service running, the coordinator adopts it without rebuilding its environment or checking build compatibility. The adopted service therefore lacks the explicit migration and Claude executable paths, causing chat database initialization or Claude session startup to fail until the service is replaced.

**Knowledge Base Used:** [Desktop App (Electron main + renderer)](https://app.greptile.com/personal-org-6810/-/custom-context/knowledge-base/superset-sh/superset/-/docs/desktop-app.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/desktop/src/main/lib/host-service-coordinator.ts`:
- Around line 1131-1139: Update the native SDK lookup around the
readdirSync(store) call to identify the exact SDK version required by the
bundled JavaScript SDK before selecting an entry. Do not use the first matching
directory; resolve the matching installed version explicitly, and return
undefined or otherwise reject the lookup when multiple candidates remain
ambiguous, ensuring the selected claude binary matches the bundled SDK version.
- Around line 797-802: Update the environment construction in the host-service
coordinator around chatV3ClaudeBin() to provide a packaged-build fallback for
SUPERSET_CHAT_V3_CLAUDE_BIN, resolving the Claude executable from the bundled
SDK via the established extraction mechanism such as extractFromBunfs. Preserve
the existing chatV3ClaudeBin() path for non-packaged builds and ensure the
resulting pathToClaudeCodeExecutable is set when running a packaged Claude
session.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 596a7385-5ad4-4994-8b68-bc06c1c79071

📥 Commits

Reviewing files that changed from the base of the PR and between c822ffa and e149b51.

📒 Files selected for processing (7)
  • apps/desktop/electron-builder.ts
  • apps/desktop/src/main/lib/host-service-coordinator.ts
  • apps/desktop/vite/helpers.ts
  • packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts
  • packages/chat-runtime/src/harness/claude/createClaudeAdapter/createClaudeAdapter.ts
  • packages/host-service/src/chat-v3/mount.ts
  • turbo.jsonc

Comment on lines +797 to +802
// The Claude Agent SDK's bundled CLI binary is unresolvable from the
// bundled host-service (isolated linker + bundling), so its path comes
// in as env too. Packaged builds are an open IOU (231MB binary).
...(chatV3ClaudeBin()
? { SUPERSET_CHAT_V3_CLAUDE_BIN: chatV3ClaudeBin() as string }
: {}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n 'SUPERSET_CHAT_V3_CLAUDE_BIN|pathToClaudeCodeExecutable|claude-agent-sdk/extract' \
  apps/desktop packages/host-service packages/chat-runtime
# Expected: packaged startup resolves an executable path or uses the SDK extraction API.

Repository: superset-sh/superset

Length of output: 1051


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Locate and inspect the relevant host-service coordinator section and related Claude setup.
wc -l apps/desktop/src/main/lib/host-service-coordinator.ts
sed -n '760,815p' apps/desktop/src/main/lib/host-service-coordinator.ts
sed -n '1108,1138p' apps/desktop/src/main/lib	host-service-coordinator.ts

# Search package manifests for the exact SDK version and any packaging extras/resources/config.
rg -n '"`@anthropic-ai/claude-agent-sdk`"|pathToClaudeCodeExecutable|SUPPORTED_EXECUTABLE_DIR|extract|extraResources|pack' package.json packages apps -g 'package.json' -g '*.ts' -g '*.tsx' -g '*.js' -g '*.json'

Repository: superset-sh/superset

Length of output: 2784


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Complete the source inspection and package/config search.
sed -n '1124,1144p' apps/desktop/src/main/lib/host-service-coordinator.ts

# Search package manifests for the Claude SDK version and packaging-related values.
printf '%s\n' '--- package.json / manifests / source/config references ---'
rg -n '"`@anthropic-ai/claude-agent-sdk`"|pathToClaudeCodeExecutable|SUPPORTED_EXECUTABLE_DIR|extract|extraResources|electron-builder|forge:build|asar|pack' \
  --glob 'package.json' \
  --glob '*.json' \
  --glob '*.ts' \
  --glob '*.tsx' \
  --glob '*.js' \
  package.json apps packages . -g '!**/node_modules/**' \
  -g '!**/.next/**' \
  -g '!**/dist/**' \
  -g '!**/build/**' || true

Repository: superset-sh/superset

Length of output: 50377


🌐 Web query:

@anthropic-ai/claude-agent-sdk package 0.3.201 pathToClaudeCodeExecutable extraction bundled CLI binary

💡 Result:

In the @anthropic-ai/claude-agent-sdk, particularly version 0.3.201 and later, the pathToClaudeCodeExecutable option is used to explicitly specify the path to the Claude Code CLI binary [1][2]. This is primarily required when the SDK's automatic resolution of the bundled native binary fails, such as when using bun build --compile or when optional binary dependencies are skipped during installation [1][3]. When bundling an application with bun build --compile, the bundled native binary resides within a virtual filesystem ($bunfs) where standard path resolution fails [3][4]. To resolve this, the SDK provides the extractFromBunfs utility, which extracts the binary from the virtual filesystem to a temporary directory on the host system [1][2]. The recommended pattern for bundled applications is: 1. Import the platform-specific binary as a file asset: import binPath from '@anthropic-ai/claude-agent-sdk-/claude' with { type: 'file' }; 2. Extract and use the path: import { extractFromBunfs } from '@anthropic-ai/claude-agent-sdk/extract'; const cliPath = extractFromBunfs(binPath); // Pass to options options: { pathToClaudeCodeExecutable: cliPath } Note that pathToClaudeCodeExecutable requires an absolute path; providing a bare command name (e.g., "claude") may fail because the SDK performs a strict filesystem check (fs.existsSync) before attempting to spawn the process [5]. Additionally, while the SDK supports native binary paths, users should ensure the binary is compatible with their host environment (e.g., libc/musl compatibility) [2].

Citations:


Handle the Claude executable in packaged builds.

In packaged mode, chatV3ClaudeBin() returns undefined, so SUPERSET_CHAT_V3_CLAUDE_BIN is omitted. pathToClaudeCodeExecutable then stays unset, and @anthropic-ai/claude-agent-sdk 0.3.201 does not fall back from the bundled binary when it is bundled by Electron. Add a packaged fallback path such as extractFromBunfs for @anthropic-ai/claude-agent-sdk-<platform>/claude, or cover this case with a packaged Claude session smoke test.

🧰 Tools
🪛 ast-grep (0.45.0)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import * as childProcess from "node:child_process";
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/desktop/src/main/lib/host-service-coordinator.ts` around lines 797 -
802, Update the environment construction in the host-service coordinator around
chatV3ClaudeBin() to provide a packaged-build fallback for
SUPERSET_CHAT_V3_CLAUDE_BIN, resolving the Claude executable from the bundled
SDK via the established extraction mechanism such as extractFromBunfs. Preserve
the existing chatV3ClaudeBin() path for non-packaged builds and ensure the
resulting pathToClaudeCodeExecutable is set when running a packaged Claude
session.

Comment on lines +1131 to +1139
const prefix = `@anthropic-ai+claude-agent-sdk-${platform}-${arch}@`;
try {
const entry = fs.readdirSync(store).find((d) => d.startsWith(prefix));
if (!entry) return undefined;
const bin = path.join(
store,
entry,
`node_modules/@anthropic-ai/claude-agent-sdk-${platform}-${arch}/claude`,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

platform="$(node -p 'process.platform')"
arch="$(node -p 'process.arch')"
prefix="`@anthropic-ai`+claude-agent-sdk-${platform}-${arch}@"

find node_modules/.bun -maxdepth 1 -type d -name "${prefix}*" -print
# Expected: one matching package directory for the active platform and architecture.

Repository: superset-sh/superset

Length of output: 211


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "files:"
git ls-files | rg 'host-service-coordinator\.ts$|package\.json$|pnpm-lock\.yaml$|bun\.lockb?|pnpm-workspace' || true

echo
echo "coordinator outline around relevant symbols:"
FILE="$(git ls-files | rg 'apps/desktop/src/main/lib/host-service-coordinator\.ts$' | head -n1 || true)"
if [ -n "${FILE:-}" ]; then
  echo "$FILE"
  wc -l "$FILE"
  ast-grep outline "$FILE" --view compact | sed -n '1,220p' || true
  echo
  sed -n '1080,1170p' "$FILE" | cat -n
else
  echo "file not found"
fi

echo
echo "search bun store / native SDK refs:"
rg -n "readdirSync\\(store\\)|claude-agent-sdk|`@anthropic-ai`|node_modules/.?bun|BUN_*|bun" apps/desktop -S || true

Repository: superset-sh/superset

Length of output: 50377


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "target file:"
git ls-files | rg '(^|/)host-service-coordinator\.ts$' || true

echo
echo "relevant coordinator section:"
FILE="$(git ls-files | rg '(^|/)host-service-coordinator\.ts$' | head -n1)"
if [ -n "${FILE:-}" ]; then
  wc -l "$FILE"
  sed -n '1100,1155p' "$FILE" | cat -n
fi

echo
echo "search native SDK / store path refs:"
rg -n "readdirSync\\(store\\)|claude-agent-sdk|`@anthropic-ai`|node_modules/.?bun|Bun" apps/desktop -S --max-count 80 || true

echo
echo "lock/package deps for anthropic:"
rg -n "`@anthropic-ai/claude-agent-sdk`|\"`@anthropic-ai/claude-agent-sdk`\"|version.*claude-agent-sdk|name: `@anthropic-ai/claude-agent-sdk`" . --max-count 120 -g 'package.json' -g 'bun.lock' -g 'bun.lockb' -g 'pnpm-lock.yaml' || true

echo
echo "read-only behavior probe: find first matching string in list"
python3 - <<'PY'
from pathlib import Path

paths = [
  Path("node_modules/.bun/@[email protected]"),
  Path("node_modules/.bun/@[email protected]"),
]
prefix = "`@anthropic-ai`+claude-agent-sdk-darwin-x64@"
print([p for p in paths if p.name.startswith(prefix)][0].name if any(p.name.startswith(prefix) for p in paths) else None)
PY

Repository: superset-sh/superset

Length of output: 50377


Resolve the exact native SDK version before launching it.

readdirSync(store).find(...) can pick the first matching platform/architecture directory even if multiple SDK versions are cached, so the host service may launch a native claude binary that does not match the bundled JavaScript SDK. Resolve the exact installed version, or reject an ambiguous match.

🧰 Tools
🪛 ast-grep (0.45.0)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import * as childProcess from "node:child_process";
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/desktop/src/main/lib/host-service-coordinator.ts` around lines 1131 -
1139, Update the native SDK lookup around the readdirSync(store) call to
identify the exact SDK version required by the bundled JavaScript SDK before
selecting an entry. Do not use the first matching directory; resolve the
matching installed version explicitly, and return undefined or otherwise reject
the lookup when multiple candidates remain ambiguous, ensuring the selected
claude binary matches the bundled SDK version.

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

5 issues found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/desktop/src/main/lib/host-service-coordinator.ts">

<violation number="1" location="apps/desktop/src/main/lib/host-service-coordinator.ts:791">
P2: These new env vars (SUPERSET_CHAT_V3_MIGRATIONS, SUPERSET_CHAT_V3_CLAUDE_BIN) are only set when the coordinator spawns a fresh host-service process. If the coordinator instead adopts an already-running host-service (e.g. after an upgrade or from another worktree), that process won't have these variables set, so chat.db migrations or Claude session startup can fail until the stale process is replaced.</violation>

<violation number="2" location="apps/desktop/src/main/lib/host-service-coordinator.ts:800">
P3: The CLUDE_BIN env spread calls `chatV3ClaudeBin()` twice — once in the spread condition and once for the value — so buildEnv redundantly runs the bun-store `readdirSync`/`existsSync` scan on every host-service spawn. Compute it once into a local before the object and reuse it; that also removes the need for the `as string` cast.</violation>

<violation number="3" location="apps/desktop/src/main/lib/host-service-coordinator.ts:1141">
P3: `chatV3ClaudeBin()` swallows readdirSync/existsSync failures with an empty `catch { return undefined; }`. Since silently returning undefined is the intended best-effort behavior for a dev-only helper, add a one-line comment inside the catch (e.g. `// bun store absent in this env — fall back to SDK default resolution`) so the swallow reads as deliberate rather than accidental.</violation>
</file>

<file name="packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts">

<violation number="1" location="packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts:177">
P3: The new pathToClaudeCodeExecutable plumb-through has no test: the harness's mock query never asserts the option reaches the SDK. Consider a test that constructs ClaudeAdapter with a path and verifies the query receives it, since this option determines which Claude Code binary is executed.</violation>
</file>

<file name="packages/host-service/src/chat-v3/mount.ts">

<violation number="1" location="packages/host-service/src/chat-v3/mount.ts:41">
P2: The `SUPERSET_CHAT_V3_CLAUDE_BIN` path is never populated for packaged builds, so this wiring only fixes the unresolved-binary bug in dev. In `host-service-coordinator.ts`, `chatV3ClaudeBin()` returns `undefined` whenever `app.isPackaged` is true, so `buildEnv` omits the env var for released builds and `mount.ts` passes `pathToClaudeCodeExecutable: undefined` to the SDK. Since the Agent SDK's bundled CLI is unresolvable from the bundled host-service (the exact failure this PR targets), packaged/released claude-code sessions will still fail to spawn their binary. The PR acknowledges this as an open IOU (231MB binary), but the shipped change leaves production on the broken path. Consider shipping the binary via `extraResources` and resolving it into this env var for packaged builds (or deliberately failing loudly in prod rather than silently falling back), so the behavior is consistent across dev and release.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Desktop as Desktop App (Electron)
    participant Coordinator as HostServiceCoordinator
    participant FS as File System
    participant HostSvc as Host Service (Bundled)
    participant ChatRuntime as Chat Runtime
    participant ClaudeSDK as Claude Agent SDK

    Note over Desktop,ClaudeSDK: Startup & Migration Flow

    Desktop->>Coordinator: initialize environment
    
    Coordinator->>Coordinator: CHANGED: Build SUPERSET_CHAT_V3_MIGRATIONS path
    alt Dev mode
        Coordinator->>FS: path: app root / packages/chat-runtime/src/db/drizzle
    else Packaged
        Coordinator->>FS: path: resources/chat-migrations (extraResources)
    end

    Coordinator->>Coordinator: CHANGED: Resolve SUPERSET_CHAT_V3_CLAUDE_BIN
    alt Dev mode
        Coordinator->>FS: Scan bun store @anthropic-ai+claude-agent-sdk-*
        FS-->>Coordinator: Found binary path
    else Packaged or missing
        Coordinator->>Coordinator: Set undefined (IOU for future)
    end

    Coordinator->>Desktop: env vars set (including new CHAT_V3 vars)
    Desktop->>HostSvc: Spawn with env vars

    Note over HostSvc,ClaudeSDK: Runtime Initialization

    HostSvc->>ChatRuntime: mount chat-v3 harness
    ChatRuntime->>HostSvc: read SUPERSET_CHAT_V3_MIGRATIONS
    HostSvc->>FS: run migrations from migrations folder
    FS-->>HostSvc: tables created

    alt Claude Code available (dev)
        HostSvc->>ChatRuntime: createClaudeAdapter({ pathToClaudeCodeExecutable })
        ChatRuntime->>ClaudeSDK: query({ pathToClaudeCodeExecutable })
        ClaudeSDK-->>ChatRuntime: Claude Code process started
    else Claude Code unavailable (packaged)
        HostSvc->>ChatRuntime: createClaudeAdapter() without CLI path
        ChatRuntime->>ChatRuntime: Run without Claude Code CLI
    end
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

"claude-code",
() =>
createClaudeAdapter({
pathToClaudeCodeExecutable: process.env.SUPERSET_CHAT_V3_CLAUDE_BIN,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: The SUPERSET_CHAT_V3_CLAUDE_BIN path is never populated for packaged builds, so this wiring only fixes the unresolved-binary bug in dev. In host-service-coordinator.ts, chatV3ClaudeBin() returns undefined whenever app.isPackaged is true, so buildEnv omits the env var for released builds and mount.ts passes pathToClaudeCodeExecutable: undefined to the SDK. Since the Agent SDK's bundled CLI is unresolvable from the bundled host-service (the exact failure this PR targets), packaged/released claude-code sessions will still fail to spawn their binary. The PR acknowledges this as an open IOU (231MB binary), but the shipped change leaves production on the broken path. Consider shipping the binary via extraResources and resolving it into this env var for packaged builds (or deliberately failing loudly in prod rather than silently falling back), so the behavior is consistent across dev and release.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/host-service/src/chat-v3/mount.ts, line 41:

<comment>The `SUPERSET_CHAT_V3_CLAUDE_BIN` path is never populated for packaged builds, so this wiring only fixes the unresolved-binary bug in dev. In `host-service-coordinator.ts`, `chatV3ClaudeBin()` returns `undefined` whenever `app.isPackaged` is true, so `buildEnv` omits the env var for released builds and `mount.ts` passes `pathToClaudeCodeExecutable: undefined` to the SDK. Since the Agent SDK's bundled CLI is unresolvable from the bundled host-service (the exact failure this PR targets), packaged/released claude-code sessions will still fail to spawn their binary. The PR acknowledges this as an open IOU (231MB binary), but the shipped change leaves production on the broken path. Consider shipping the binary via `extraResources` and resolving it into this env var for packaged builds (or deliberately failing loudly in prod rather than silently falling back), so the behavior is consistent across dev and release.</comment>

<file context>
@@ -34,7 +34,13 @@ function migrationsFolder(): string {
+			"claude-code",
+			() =>
+				createClaudeAdapter({
+					pathToClaudeCodeExecutable: process.env.SUPERSET_CHAT_V3_CLAUDE_BIN,
+				}),
+		],
</file context>

// chat.db's migrations ship the same way host.db's do: the bundled
// host-service can't resolve them from its own module path, so the
// folder travels as a resource and the path comes in as env.
SUPERSET_CHAT_V3_MIGRATIONS: app.isPackaged

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: These new env vars (SUPERSET_CHAT_V3_MIGRATIONS, SUPERSET_CHAT_V3_CLAUDE_BIN) are only set when the coordinator spawns a fresh host-service process. If the coordinator instead adopts an already-running host-service (e.g. after an upgrade or from another worktree), that process won't have these variables set, so chat.db migrations or Claude session startup can fail until the stale process is replaced.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/main/lib/host-service-coordinator.ts, line 791:

<comment>These new env vars (SUPERSET_CHAT_V3_MIGRATIONS, SUPERSET_CHAT_V3_CLAUDE_BIN) are only set when the coordinator spawns a fresh host-service process. If the coordinator instead adopts an already-running host-service (e.g. after an upgrade or from another worktree), that process won't have these variables set, so chat.db migrations or Claude session startup can fail until the stale process is replaced.</comment>

<file context>
@@ -785,6 +785,21 @@ export class HostServiceCoordinator extends EventEmitter {
+			// chat.db's migrations ship the same way host.db's do: the bundled
+			// host-service can't resolve them from its own module path, so the
+			// folder travels as a resource and the path comes in as env.
+			SUPERSET_CHAT_V3_MIGRATIONS: app.isPackaged
+				? path.join(process.resourcesPath, "resources/chat-migrations")
+				: path.join(
</file context>

`node_modules/@anthropic-ai/claude-agent-sdk-${platform}-${arch}/claude`,
);
return fs.existsSync(bin) ? bin : undefined;
} catch {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: chatV3ClaudeBin() swallows readdirSync/existsSync failures with an empty catch { return undefined; }. Since silently returning undefined is the intended best-effort behavior for a dev-only helper, add a one-line comment inside the catch (e.g. // bun store absent in this env — fall back to SDK default resolution) so the swallow reads as deliberate rather than accidental.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/main/lib/host-service-coordinator.ts, line 1141:

<comment>`chatV3ClaudeBin()` swallows readdirSync/existsSync failures with an empty `catch { return undefined; }`. Since silently returning undefined is the intended best-effort behavior for a dev-only helper, add a one-line comment inside the catch (e.g. `// bun store absent in this env — fall back to SDK default resolution`) so the swallow reads as deliberate rather than accidental.</comment>

<file context>
@@ -1107,3 +1122,23 @@ export function getHostServiceCoordinator(): HostServiceCoordinator {
+			`node_modules/@anthropic-ai/claude-agent-sdk-${platform}-${arch}/claude`,
+		);
+		return fs.existsSync(bin) ? bin : undefined;
+	} catch {
+		return undefined;
+	}
</file context>

// The Claude Agent SDK's bundled CLI binary is unresolvable from the
// bundled host-service (isolated linker + bundling), so its path comes
// in as env too. Packaged builds are an open IOU (231MB binary).
...(chatV3ClaudeBin()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: The CLUDE_BIN env spread calls chatV3ClaudeBin() twice — once in the spread condition and once for the value — so buildEnv redundantly runs the bun-store readdirSync/existsSync scan on every host-service spawn. Compute it once into a local before the object and reuse it; that also removes the need for the as string cast.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/main/lib/host-service-coordinator.ts, line 800:

<comment>The CLUDE_BIN env spread calls `chatV3ClaudeBin()` twice — once in the spread condition and once for the value — so buildEnv redundantly runs the bun-store `readdirSync`/`existsSync` scan on every host-service spawn. Compute it once into a local before the object and reuse it; that also removes the need for the `as string` cast.</comment>

<file context>
@@ -785,6 +785,21 @@ export class HostServiceCoordinator extends EventEmitter {
+			// The Claude Agent SDK's bundled CLI binary is unresolvable from the
+			// bundled host-service (isolated linker + bundling), so its path comes
+			// in as env too. Packaged builds are an open IOU (231MB binary).
+			...(chatV3ClaudeBin()
+				? { SUPERSET_CHAT_V3_CLAUDE_BIN: chatV3ClaudeBin() as string }
+				: {}),
</file context>

options: {
cwd: startOptions.cwd,
model: startOptions.modelId,
pathToClaudeCodeExecutable: this.options.pathToClaudeCodeExecutable,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: The new pathToClaudeCodeExecutable plumb-through has no test: the harness's mock query never asserts the option reaches the SDK. Consider a test that constructs ClaudeAdapter with a path and verifies the query receives it, since this option determines which Claude Code binary is executed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/chat-runtime/src/harness/claude/claudeAdapter/claudeAdapter.ts, line 177:

<comment>The new pathToClaudeCodeExecutable plumb-through has no test: the harness's mock query never asserts the option reaches the SDK. Consider a test that constructs ClaudeAdapter with a path and verifies the query receives it, since this option determines which Claude Code binary is executed.</comment>

<file context>
@@ -172,6 +174,7 @@ export class ClaudeAdapter implements HarnessAdapter {
 			options: {
 				cwd: startOptions.cwd,
 				model: startOptions.modelId,
+				pathToClaudeCodeExecutable: this.options.pathToClaudeCodeExecutable,
 				includePartialMessages: true,
 				settingSources: [],
</file context>

The translator's only session-status event was 'running' at init, so the
projection's last word stayed Working forever once a turn completed —
found live in the pane, convicted by the journal (turn completed at seq 21,
no session event after). result() and the interrupt path now emit idle;
the runtime's queue-override still holds running while queued work exists.

Claude-Session: https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/chat-runtime/src/harness/claude/translateStream/translateStream.ts`:
- Line 354: Move the sessionIdle() emission into the public interrupt() method
so every direct interruption returns the idle session event after clearing
turnId; then remove the extra sessionIdle() append from the result path at the
shown return, preserving the existing interrupt reason events.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9007ad4c-d525-448c-b243-1f2b626f3afd

📥 Commits

Reviewing files that changed from the base of the PR and between e149b51 and 3fc2ec0.

📒 Files selected for processing (2)
  • packages/chat-runtime/src/harness/claude/translateStream/translateStream.test.ts
  • packages/chat-runtime/src/harness/claude/translateStream/translateStream.ts

this.settledBlocks.clear();
this.streamingBlocks.clear();
return this.interrupt(interruptReason);
return [...this.interrupt(interruptReason), this.sessionIdle()];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Emit the idle event from interrupt().

When a caller invokes the public interrupt(reason) method directly, it clears this.turnId but returns no session event. The idle event at line 354 is not reached because a later result() call exits when this.turnId is null. The session can remain running after cancellation.

Move this.sessionIdle() into interrupt() and remove the extra append here.

Proposed fix
 	interrupt(reason: string): AdapterEvent[] {
 		const events: AdapterEvent[] = [];
 		// ...
-		return events;
+		return [...events, this.sessionIdle()];
 	}

 	// ...
-			return [...this.interrupt(interruptReason), this.sessionIdle()];
+			return this.interrupt(interruptReason);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/chat-runtime/src/harness/claude/translateStream/translateStream.ts`
at line 354, Move the sessionIdle() emission into the public interrupt() method
so every direct interruption returns the idle session event after clearing
turnId; then remove the extra sessionIdle() append from the result path at the
shown return, preserving the existing interrupt reason events.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/chat-runtime/src/harness/claude/translateStream/translateStream.ts">

<violation number="1" location="packages/chat-runtime/src/harness/claude/translateStream/translateStream.ts:354">
P2: The new sessionIdle() emission is only wired into result()'s interrupt branch. If a caller invokes the public interrupt(reason) method directly (not via result()), turnId is cleared but no session-idle event is emitted, since a subsequent result() call will short-circuit once turnId is null. Consider moving the sessionIdle() emission into interrupt() itself so direct callers also get the idle transition.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

this.settledBlocks.clear();
this.streamingBlocks.clear();
return this.interrupt(interruptReason);
return [...this.interrupt(interruptReason), this.sessionIdle()];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: The new sessionIdle() emission is only wired into result()'s interrupt branch. If a caller invokes the public interrupt(reason) method directly (not via result()), turnId is cleared but no session-idle event is emitted, since a subsequent result() call will short-circuit once turnId is null. Consider moving the sessionIdle() emission into interrupt() itself so direct callers also get the idle transition.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/chat-runtime/src/harness/claude/translateStream/translateStream.ts, line 354:

<comment>The new sessionIdle() emission is only wired into result()'s interrupt branch. If a caller invokes the public interrupt(reason) method directly (not via result()), turnId is cleared but no session-idle event is emitted, since a subsequent result() call will short-circuit once turnId is null. Consider moving the sessionIdle() emission into interrupt() itself so direct callers also get the idle transition.</comment>

<file context>
@@ -347,7 +351,7 @@ export class ClaudeTranslator {
 			this.settledBlocks.clear();
 			this.streamingBlocks.clear();
-			return this.interrupt(interruptReason);
+			return [...this.interrupt(interruptReason), this.sessionIdle()];
 		}
 
</file context>

@saddlepaddle
saddlepaddle merged commit fc50e1a into main Aug 10, 2026
19 checks passed

This branch was previously deployed

1 inactive deployment
preview — 3fc2ec05 Deployed Aug 5, 2026 by saddlepaddle via Deploy Web #7193
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