Skip to content

bug(v2): SAP AI Core initialization fails  #54791

Open

Description

@ton618to

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

  1. Run the V2 CLI/server from source under Bun 1.4.2 using the normal packages/cli configuration, which preloads @opentui/solid/preload.
  2. Configure SAP AI Core and send a short prompt to a SAP model after the model catalog is ready.
  3. 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 transformSolidSource on export const x = <box />, then import SAP SDK: the same exception occurs.
  • Save the original Error.prepareStackTrace before 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

  1. changed the title [-]bug(v2): SAP AI Core initialization fails after Babel stack rewriting on Bun 1.4.2[/-] [+]bug(v2): SAP AI Core initialization fails [/+] on Oct 12, 2026
  2. opencode-agent commented on Oct 12, 2026

    @opencode-agent
    Contributor

    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/cli with bun run src/index.ts serve, which loads the @opentui/solid/preload preload. It used an in-memory database, a temporary config directory, project config disabled and a fake AICORE_SERVICE_KEY. Every /api/experimental/generate call for sap-ai-core/anthropic--claude-4.8-opus returned:

    Cannot initialize sap-ai-core/anthropic--claude-4.8-opus: First argument must be an Error object
    

    Your diagnosis holds:

    • After OpenTUI's transformSolidSource runs, Error.prepareStackTrace is Babel's stackTraceRewriter, and importing @jerome-benoit/sap-ai-provider-v2@5.0.3 throws from follow-redirects.
    • Without the transform, or with the original prepareStackTrace restored, the import works.

    The released @opencode/cli@2.0.26 binary 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 (dev mode) or an installed release (release mode).

    Reproduction script (server.sh)
    #!/usr/bin/env bash
    # Reproduce #54791 against a headless opencode server.
    # Usage: server.sh release   -> uses `opencode` from PATH (e.g. @opencode/cli@2.0.26)
    #        server.sh dev <repo> -> runs packages/cli/src/index.ts from a source checkout (bunfig preloads @opentui/solid/preload)
    set -u
    MODE=${1:-release}; REPO=${2:-/workspace/repo}; PORT=${PORT:-4610}
    TMP=$(mktemp -d); mkdir -p "$TMP/cfg" "$TMP/proj"
    export OPENCODE_DB=:memory: OPENCODE_CONFIG_DIR="$TMP/cfg" OPENCODE_DISABLE_PROJECT_CONFIG=1
    export AICORE_SERVICE_KEY='{"clientid":"x","clientsecret":"y","url":"https://auth.example.invalid","serviceurls":{"AI_API_URL":"https://api.example.invalid"}}'
    if [ "$MODE" = dev ]; then
      (cd "$REPO/packages/cli" && exec bun run src/index.ts serve --hostname 127.0.0.1 --port $PORT) > "$TMP/log" 2>&1 &
    else
      (cd "$TMP/proj" && exec opencode serve --hostname 127.0.0.1 --port $PORT) > "$TMP/log" 2>&1 &
    fi
    SRV=$!
    for i in $(seq 1 60); do grep -q password "$TMP/log" && break; sleep 1; done
    cat "$TMP/log"
    P=$(grep password "$TMP/log" | awk '{print $3}')
    for i in 1 2 3; do
      curl -s -u opencode:$P -X POST http://127.0.0.1:$PORT/api/experimental/generate \
        -H 'content-type: application/json' -H "x-opencode-directory: $TMP/proj" \
        -d '{"prompt":"hi","model":{"providerID":"sap-ai-core","id":"anthropic--claude-4.8-opus"}}'; echo
      sleep 3
    done
    kill $SRV 2>/dev/null

    Run it: bash server.sh

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions