Skip to content

fix: probe libc before selecting bundled CLI binary (#296)#305

Draft
MukundaKatta wants to merge 1 commit into
anthropics:mainfrom
MukundaKatta:fix/libc-aware-binary-discovery
Draft

fix: probe libc before selecting bundled CLI binary (#296)#305
MukundaKatta wants to merge 1 commit into
anthropics:mainfrom
MukundaKatta:fix/libc-aware-binary-discovery

Conversation

@MukundaKatta
Copy link
Copy Markdown

Note on repo structure

This repository is issues-only: the published @anthropic-ai/claude-agent-sdk package is built from a separate source tree. The fix here lives under proposed-fixes/issue-296/ as a self-contained TS module plus vitest tests for the team to integrate into the closed-source sdk.mjs build. Happy to convert to a comment on #296 if that is the preferred channel.

Summary

Reference implementation for #296. The bundled sdk.mjs resolver on Linux tries the musl variant first and never verifies the resolved path exists on disk. This breaks two install scenarios:

  • pnpm: both optional packages installed, musl chosen, spawn fails on glibc hosts because the musl loader is missing.
  • npm on glibc: musl correctly skipped by the libc filter, but the resolver still returns a musl-shaped path that does not exist.

What it does

  1. Detects libc on Linux in priority order: process.report.getReport().header.glibcVersionRuntimeldd --version parse → filesystem probe of loader paths → default to glibc when inconclusive.
  2. Orders platform-package candidates by detected libc.
  3. Verifies each candidate exists on disk before returning, falling through to the other variant otherwise; throws a clear error when neither path resolves.

Test plan

  • npm test → 21/21 vitest unit tests pass (detection heuristics, candidate ordering, existence fallback, null-when-truly-missing).
  • tsc --noEmit → clean.
  • Maintainer-side verification on real Alpine and glibc containers still pending.

Reference implementation for issue anthropics#296. The bundled sdk.mjs resolver
on Linux currently tries the musl variant first and never verifies that
the resolved path exists on disk. This breaks two real install layouts:

- pnpm installs both optional packages, the resolver picks musl, and
  spawn fails on glibc hosts because the musl ld-linker is missing
- npm correctly skips the musl optional dep on glibc, but the resolver
  still hands back a musl-shaped path that doesn't exist on disk

The new module:
- detects glibc vs musl via process.report.getReport(), then ldd
  --version, then a filesystem probe of known loader paths
- orders candidates by detected libc (glibc-first when unknown)
- verifies each candidate exists on disk before returning it, falling
  through otherwise

This repo is issues-only; the fix lives under proposed-fixes/issue-296
as a self-contained TS module + vitest tests for Anthropic to drop
into the closed-source sdk.mjs build. 21 tests cover detection, ordering,
existence fallback, and the null-when-truly-missing case.

Closes anthropics#296.
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