Skip to content

server: integration.connect.* and integration.oauth.* return IntegrationNotFound until the location's plugins activate #59730

Open

Description

@btriapitsyn

Description

In a location that has just booted, POST /api/integration/:id/connect/key returns 404 IntegrationNotFoundError for an integration that a plugin provides. Retrying a moment later succeeds. integration.list doesn't have this problem because it does yield* Plugin.awaitActivation first. integration.get, connect.key, connect.external and oauth.* go straight to service.get(id), so they can run before the plugin has registered the integration.

From the server log, with nothing else touching that location:

message="location services booted" directory=/Users/me durationMs=22
message="Sent HTTP response" http.method=POST http.url=/api/integration/opencode/connect/key http.status=404

Same thing as #51282 (agent.list) and #59237 (plugin.list). Should these handlers await activation the same way integration.list does?

OpenCode version

2.2.0

Steps to reproduce

  1. Start the server and don't make any request in some directory D.
  2. POST /api/integration//connect/key with a valid key, scoped to D.
  3. You get 404 IntegrationNotFoundError. The same request a second later returns 204.

Operating System

macOS (Darwin 27.0.0, arm64)

Activity

  1. opencodejr commented on Oct 27, 2026

    @opencodejr
    Contributor

    Thanks for the clear report, I can confirm this. I started opencode serve on 2.2.0 and sent one request per endpoint to a fresh directory (via x-opencode-directory), then repeated it 2 seconds later:

    • GET /api/integration/opencode: 404 at first, then 200
    • POST /api/integration/opencode/connect/key: 404 IntegrationNotFoundError at first, then 204
    • POST /api/integration/github-copilot/connect/oauth: 500 at first, then 200

    It still happens on the latest dev (f7d0ce1). In packages/server/src/handlers/integration.ts, only integration.list waits for plugin activation before reading the integration service.

    The script below reproduces it. Related reports of the same race in other handlers: #51282 (agent.list), #59237 (plugin.list), #51173 / #51947 (vcs), #54192 (MCP).

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #59730: integration.get / connect.key / oauth.connect return
    # IntegrationNotFoundError on a cold location until its plugins activate.
    # Usage: ./repro.sh            (uses `opencode` on PATH)
    #        OC="bun ... packages/cli/src/index.ts" ./repro.sh   (from source)
    set -u
    OC=${OC:-opencode}
    PORT=${PORT:-4199}
    WORK=$(mktemp -d)
    export HOME=$WORK/home; mkdir -p "$HOME"
    $OC serve --port "$PORT" >"$WORK/serve.log" 2>&1 &
    SRV=$!
    trap 'kill $SRV 2>/dev/null' EXIT
    for _ in $(seq 1 60); do grep -q "server password" "$WORK/serve.log" && break; sleep 0.5; done
    PW=$(grep "server password" "$WORK/serve.log" | awk '{print $3}')
    req() { # method path dir [body]
      curl -s --max-time 15 -o /dev/null -w "%{http_code}" -u "opencode:$PW" -X "$1" "http://127.0.0.1:$PORT$2" \
        -H "x-opencode-directory: $3" -H "content-type: application/json" ${4:+-d "$4"}
    }
    for kind in get key oauth; do
      D=$WORK/cold-$kind; mkdir -p "$D"
      case $kind in
        get)   M=GET;  P=/api/integration/opencode; B= ;;
        key)   M=POST; P=/api/integration/opencode/connect/key; B='{"key":"sk-test"}' ;;
        oauth) M=POST; P=/api/integration/github-copilot/connect/oauth; B='{"methodID":"device","answer":{"deploymentType":"github.com"}}' ;;
      esac
      first=$(req $M $P "$D" "$B"); sleep 2; second=$(req $M $P "$D" "$B")
      echo "$kind $M $P (fresh dir): first=$first  after 2s=$second"
    done

    Run it: bash repro.sh

  2. Aafimalek commented on Oct 28, 2026

    @Aafimalek

    I would like to investigate the integration activation race and add regression coverage. Could you assign this issue to me?

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