Repository navigation
Description
Description
SAP AI Core works in my installed V1 client, but a V2 source-run server fails while importing the provider, before making a model request:
Cannot initialize sap-ai-core/anthropic--claude-4.8-opus:
First argument must be an Error object
Reproduced through both session generation (HTTP 503) and an isolated V2 server's /api/experimental/generate endpoint (HTTP 400), using an in-memory database, temporary configuration, and no user plugins. Supplying AICORE_SERVICE_KEY does not prevent the initialization failure.
Steps to reproduce
- Run the V2 CLI/server from source under Bun 1.4.2 using the normal
packages/cliconfiguration, which preloads@opentui/solid/preload. - Configure SAP AI Core and send a short prompt to a SAP model after the model catalog is ready.
- Provider initialization fails with the error above.
The isolated server was started from packages/cli with bun run src/index.ts serve --hostname 127.0.0.1 --port <port>, OPENCODE_DB=:memory:, a temporary OPENCODE_CONFIG_DIR, project configuration disabled, and AICORE_SERVICE_KEY supplied. The first stateless generation call can return Model unavailable while the catalog settles; subsequent calls reproduce the initialization error.
Diagnosis and verified controls
The failing server has Babel's stackTraceRewriter installed as Error.prepareStackTrace. The SAP SDK import reaches @sap-cloud-sdk/util → axios → follow-redirects, where creating a custom error type triggers Bun's native formatter error:
TypeError: First argument must be an Error object
at ErrorPrepareStackTrace (native)
at captureStackTrace (native)
at new CustomError (.../follow-redirects/index.js:656:13)
at createErrorType (.../follow-redirects/index.js:664:27)
at <anonymous> (.../follow-redirects/index.js:70:29)
at <anonymous> (.../axios/dist/node/axios.cjs:13:5)
at <anonymous> (.../@sap-cloud-sdk/util/dist/url.js:8:17)
Fresh-process controls with the same installed SAP provider:
- Import SAP SDK directly: initialization succeeds.
- Run OpenTUI's
transformSolidSourceonexport const x = <box />, then import SAP SDK: the same exception occurs. - Save the original
Error.prepareStackTracebefore that transform and restore it before importing SAP SDK: initialization succeeds. This was a diagnostic control, not a proposed global production workaround.
This matches the existing Bun bug oven-sh/bun#41151; its proposed fix is oven-sh/bun#41395 (still open when checked).
Expected: TUI/Babel transformation should not make provider imports fail in the V2 server. Please consider isolating the server from the transform's global stack formatter side effect, or tracking the required Bun fix. This report is limited to the initialization crash, not SAP credential refresh or AI SDK V2 usage conversion.
Plugins
No user plugins required; reproduced in an isolated server.
OpenCode version
V2 local source checkout; packages/cli version 2.0.26. Local HEAD: 10867bb4dd5ce2eade2aa487c88c97eeb537029f (local revision, not claiming this SHA is available upstream). The upstream v2 branch has the same CLI preload configuration and SAP provider loader.
Bun 1.4.2; @opentui/solid 0.5.17; @babel/core 7.29.7; @jerome-benoit/sap-ai-provider-v2 5.0.3.
Operating System
macOS / Darwin 27.0.0, arm64.
Terminal
Not terminal-specific; reproduced via HTTP against a headless server.
Activity
[-]bug(v2): SAP AI Core initialization fails after Babel stack rewriting on Bun 1.4.2[/-][+]bug(v2): SAP AI Core initialization fails [/+]opencode-agent commentedon Oct 12, 2026
Thanks for the detailed report. I reproduced this on the latest
dev(bcf23b6) under Bun 1.4.2.What I ran: a headless server started from
packages/cliwithbun run src/index.ts serve, which loads the@opentui/solid/preloadpreload. It used an in-memory database, a temporary config directory, project config disabled and a fakeAICORE_SERVICE_KEY. Every/api/experimental/generatecall forsap-ai-core/anthropic--claude-4.8-opusreturned:Your diagnosis holds:
transformSolidSourceruns,Error.prepareStackTraceis Babel'sstackTraceRewriter, and importing@jerome-benoit/sap-ai-provider-v2@5.0.3throws fromfollow-redirects.prepareStackTracerestored, the import works.The released
@opencode/cli@2.0.26binary is not affected. With the same setup it gets past initialization and only fails later at the token request, as expected with fake credentials. So this seems limited to running from source with the Solid preload, which ties it to the Bun bug you linked (oven-sh/bun#41151).The script below reproduces it against a source checkout (
devmode) or an installed release (releasemode).Reproduction script (server.sh)
Run it:
bash server.sh