Skip to content

fix: let managed SSH Claude chats load the agent SDK - #26450

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/ssh-chat-orcad-esm-import-meta
Oct 11, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/ssh-chat-orcad-esm-import-meta

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​64 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61

ELI5

Every structured Claude chat on a managed SSH host failed with “Chat could not be started.” The server bundle erased the Claude SDK's module URL, so loading the SDK called createRequire(undefined) before Claude could start. This change lets the packaged server load that SDK successfully and prevents unsupported module metadata from silently becoming an empty object again.

What Changed

  • Give bundled modules the deployed server file's URL, using Node's path-to-file-URL conversion. Keep the existing CommonJS server, launcher, native-module layout, and filenames.
  • Treat esbuild's unsupported import.meta warning as a build error across the server, launcher, forked children, and staged watcher wrapper. Only import.meta.url is mapped; unsupported metadata access fails packaging.
  • Add a packaged-server check that reaches the real structured Claude connection's SDK import under plain Node, then stops before launching an agent. Every build:orcad invokes it, including the existing template-build workflow.
  • Add regression coverage for the actual server bundle, relocated paths containing spaces/#/%, and unsupported module metadata.

The server and launcher bytes already participate in the slot version and template checksums, so deployments automatically select a new version without changing the manifest format.

Why

The server graph has two executable import.meta sites, both in the Claude SDK: its module-load createRequire and its optional native-CLI lookup. Orca supplies its resolved executable explicitly, so that fallback does not need packaged SDK binaries; neither site needs a separate wasm or worker asset. The graph's other occurrence is source text for a generated plugin, which this mapping leaves as text.

Keeping CommonJS avoids changing the loader contract for native dependencies, workers, older launchers, and Windows hosts. Emitting ESM would require adapting that existing contract; externalizing the SDK would require shipping and hashing another package tree. The selected mapping supplies the same deployed-bundle location that a native ESM bundle would use, and the build error prevents silently accepting other metadata semantics. See esbuild's diagnostic override and Node's file-URL conversion.

Differences from the common pattern:

  • Intended: retain CommonJS delivery and supply the bundle URL explicitly instead of relying on native ESM metadata. The audited SDK uses this URL for Node's loader; Orca still resolves the provider executable on the execution host and stages native dependencies separately.
  • No temporary differences are introduced in execution ownership, transcript storage, or cursor replay.

Linked Issue

U29 from the managed SSH structured-chat investigation; no separate issue.

Visual Proof

Pending coordinator QA on the final branch: open structured Claude chat on a managed SSH host and send a message. This draft has automated packaged-module evidence, but no final-head rendered before/after evidence yet.

Testing

  • Automated tests added/updated.
  • Final-head managed SSH UI flow verified by the coordinator.

The new real-bundle test reproduced the live ERR_INVALID_ARG_VALUE / createRequire(undefined) failure before the URL mapping and passes with it. Four targeted files passed, 18 tests total: config/scripts/orcad-entry-build.test.mjs, src/main/orcad/orcad-bundle-native-load-order.test.ts, src/main/orcad/orcad-runtime-entry-artifacts.test.ts, and config/scripts/orcad-artifact-version.test.mjs.

The queued tc-node check passed. All 22 pre-push orca-ci-checks --no-typecheck checks passed after the queued Node typecheck. The complete macOS package build passed under local Node 26.5.0, including the new SDK smoke check, daemon load check, and profile-state workers. The pinned Node 24.21.0 package also built successfully after resuming and verifying the timed-out archive download. Invoking the packaged server’s structured-provider load check with that exact pinned runtime exited 0 with empty stderr. The blocking CI watch completed: static analysis/typecheck, all ten Node 24 unit shards, relay integration, both package jobs (including Windows), repository guards, and test-selection evidence passed. No red checks remain. Headless/template, compatibility, and UI qualification jobs were skipped by the draft/change-scope policy and are not counted as passes. The download timeout and watch interruption were infrastructure issues, both resolved without code changes.

All nine relay/companion entries also built with unsupported module metadata promoted to an error, with zero such warnings. The desktop daemon externalizes third-party packages; the CLI is compiled with TypeScript, so those paths do not perform this failing SDK transformation. Codex, ACP, and Pi use their existing command/protocol paths; the existing whole-server graph and native load-order checks passed.

Local checks used macOS arm64 and plain Node 26.5.0 plus the pinned Node 24.21.0, with no Electron UI, provider process, login, or credentials. Linux/Windows execution and an actual managed SSH turn remain for CI/coordinator QA. Other SSH chat lifecycle, configuration, and launch-environment fixes are separate work.

Review

Draft for coordinator review and end-to-end QA; do not merge or mark ready.

Agent skill upstream boundary

  • Not applicable; no upstream skill source copied.

Notes

No wire or persisted-data format changes. Native modules retain their deployed package directories. The content hash and template manifest continue to derive from the emitted bytes.

Checklist

  • This PR is small and focused.
  • I explained the problem, user-facing change, mechanism, and alternatives.
  • Final-head before/after rendered evidence attached.
  • Self-reviewed for correctness, security, and performance.
  • Cross-platform, SSH, and deployed path behavior considered.
  • Full package build, static checks, and CI classified on the final head; qualification skips remain explicit.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 8, 2026 18:03
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary

Problem: every Claude chat on an SSH host failed with "Chat could not be started". The managed SSH server is bundled as one CommonJS file, and the bundler turns import.meta into an empty object, so the Claude SDK's createRequire(import.meta.url) received undefined and threw.

User-facing change: Claude native chat starts on SSH hosts that run the managed server. Nothing visible changes elsewhere.

What the PR does: every server output (server, launcher, daemon and its child workers) maps import.meta.url to the running file's own URL, and any other import.meta use now fails the server build instead of silently becoming {}. The build also runs a load check that imports the Claude SDK the same lazy way production does, so this can't regress unnoticed.

Review (independent, head 90b0fdb): no findings.

  • The new tests pass on the branch. With main's build options swapped back in, all six fail, including the original createRequire ... Received undefined error.
  • A real server package build succeeded, and every output carries the mapping. Moving the package to a path with spaces, # and % still loads.
  • The only import.meta uses in the server's dependencies are the two in the Claude SDK. Codex, ACP agents and Pi run as separate CLI processes, so they don't hit this.
  • The server version is a hash of the built files, so hosts pick up the fixed package without a manual version bump.

Not verified: a full SSH chat (the load check stops before talking to the provider), native Linux/Windows runs, and the exact pinned Node 24 runtime (the review used Node 26). Live SSH QA across all the SSH chat fixes is still to come, and screenshots will go in the PR body before this is marked ready.

Still open: a conflict with main in config/scripts/build-orcad.mjs is being resolved now.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e2f68c7-c338-45d8-b5ce-657b96d80d59

📥 Commits

Reviewing files that changed from the base of the PR and between 7432f11 and c463d47.


📒 Files selected for processing (4)
  • config/scripts/build-orcad.mjs
  • config/scripts/orcad-entry-build.mjs
  • config/scripts/orcad-entry-build.test.mjs
  • src/main/orcad/main.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.



📝 Walkthrough

Walkthrough

The Orcad build configurations apply shared esbuild options that define import.meta.url from __filename. The Orcad main entry adds a command that runs a structured-provider smoke check. The build script runs the packaged server with this command and sets the build exit code to 1 if the process fails, times out, or returns truncated output. Tests cover packaged startup, relocated asset resolution, and rejected import.meta expressions.


Priority: ⬆️ High

Merge Risk: ⚪ Minimal · up to c463d

The change lets the managed server bundle load the Claude SDK by providing a module URL, and it adds a build-time check for that. No concrete merge-blocking risk was found. Live SSH chat behavior still needs QA.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely summarizes the main fix: enabling managed SSH Claude chats to load the agent SDK.
Description check Passed The description is detailed and covers the user impact, technical changes, rationale, testing, limitations, and checklist status. It clearly identifies outstanding managed SSH UI verification and does…
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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

…-orcad-esm-import-meta

# Conflicts:
#	config/scripts/build-orcad.mjs
@hack-the-void

Copy link
Copy Markdown

Confirming this on Orca 1.4.224 (macOS arm64) with orcad-0.1.0+15ec2904eb00 on a Linux SSH host (Node 20.19.2, Claude Code 2.1.296). Every Claude Chat fails with starting the provider failed / TypeError … 'filename' … Received undefined [ERR_INVALID_ARG_VALUE], traced to f3l=(0,Oqi.createRequire)(yXi.url) with yXi={} in orcad-server.js. Claude in a terminal tab works fine on the same host. Looking forward to this landing 🙏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Synced with main (head c463d47d167) so this can be merged safely.

Before this sync, merging would have broken main's build. This PR imported config/scripts/script-child-process.mjs, which main deleted in #26963. Both imports now come from where #26963 moved them: runProcessSync from @orca/process-host, and describeProcessFailure from ./process-failure-message.mjs. The PR's diff against main is still only its 5 files.

Checks

  • CI: 30 passed, 17 skipped, 0 failed. MERGEABLE / CLEAN.
  • Local: node typecheck clean; 69 targeted tests passing; orca-ci-checks 24/24.
  • Server build: build-orcad-node.mjs passes, including the structured-provider load check this PR adds.

Live check. I built this PR merged with #26464 into a local-only build and ran it over SSH on a Linux container with a stand-in Claude. Claude chats start and complete on the managed server. Without this PR, every chat start fails with TypeError: The argument 'filename' must be a file URL object … Received undefined.

Merge order: this PR first, then #26464.

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.

2 participants