fix(providers): thread opencode traceparent per call by Asthenia0412 · Pull Request #10622 · promptfoo/promptfoo · GitHub
Skip to content

fix(providers): thread opencode traceparent per call - #10622

Open
Asthenia0412 wants to merge 1 commit into
promptfoo:mainfrom
Asthenia0412:codex/opencode-traceparent
Open

fix(providers): thread opencode traceparent per call#10622
Asthenia0412 wants to merge 1 commit into
promptfoo:mainfrom
Asthenia0412:codex/opencode-traceparent

Conversation

@Asthenia0412

Copy link
Copy Markdown

Summary

  • Add an opt-in restart_server_per_call mode for opencode:sdk so promptfoo-owned OpenCode servers restart when the eval traceparent changes.
  • Temporarily set OPENCODE_TRACEPARENT only while spawning OpenCode, matching the current SDK behavior where the server inherits process.env at spawn time.
  • Reject incompatible baseUrl and persist_sessions combinations, and document the trajectory assertion tradeoff.

Fixes #10518.

Why

OpenCode telemetry plugins that read trace context at process startup cannot correlate per-test spans today because opencode:sdk keeps one owned server alive across calls and never forwards context.traceparent. That makes trajectory:* assertions unreliable for OpenCode runs.

Validation

  • npx vitest run test/providers/opencode-sdk.test.ts - 139 passed
  • npx @biomejs/biome check src/providers/opencode-sdk.ts test/providers/opencode-sdk.test.ts
  • npx prettier --check site/docs/providers/opencode-sdk.md
  • git diff --check

Also ran npm run tsc; it is currently blocked on unrelated existing src/providers/openai/codex-security.ts errors because @openai/codex-security is not available in this local checkout.

I could not run a real OpenCode + OTLP e2e locally because this machine does not have the opencode CLI on PATH. The provider lifecycle is covered with the existing mocked OpenCode SDK suite, including restart, env injection/restoration, default no-op behavior, and incompatible config rejection.

@promptfoo-scanner promptfoo-scanner Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 All Clear

I reviewed the changes adding per-traceparent server restarts and temporary OPENCODE_TRACEPARENT propagation in the OpenCode SDK provider, plus related docs and tests. The modifications affect server lifecycle and telemetry only and do not alter prompt construction, tool permissions, or output handling paths. Based on the diff, no new LLM security risks were introduced.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38737843a8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1870 to +1871
return await this.runSerializedServerLifecycleCall(
config.restart_server_per_call,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Disable cache reads for per-trace server restarts

When caching is enabled and a matching response already exists, getCachedResponse returns before this lifecycle block runs, so no server is started or retagged with the current traceparent; collectExternalTraceAfterProviderCall also explicitly skips fetching external traces for cached responses. Consequently, the documented trajectory:* use case can receive no trace evidence and produce incorrect assertion results on repeated prompts unless the user happens to pass --no-cache. Disable response caching whenever restart_server_per_call is active.

AGENTS.md reference: AGENTS.md:L370-L372

Useful? React with 👍 / 👎.

Comment on lines +1677 to +1680
await this.waitForPreviousSessionCall(previous, abortSignal);
return await run();
} finally {
release();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the mutex when a queued call is aborted

If call A is running, call B is waiting with its own abort signal, and call C queues behind B, aborting B makes waitForPreviousSessionCall reject and this finally resolves B's queue promise even though A still owns the lifecycle lock. C can then enter concurrently, see a different traceparent, and close A's active server mid-prompt. An aborted waiter must keep subsequent callers chained to its predecessor rather than releasing them immediately.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset tagged servers when restart mode is overridden

Because prepareCall merges context.prompt.config, one prompt can enable restart_server_per_call even when the provider default is false, leaving the shared client tagged with that prompt's traceparent. A later prompt that omits or disables the flag skips this guard, reuses the tagged client, and emits its OpenCode spans under the earlier test's trace. Either make this lifecycle option provider-level-only or restart an already-tagged client whenever the incoming call is not using the same trace context.

AGENTS.md reference: AGENTS.md:L370-L372

Useful? React with 👍 / 👎.

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.

opencode:sdk provider never threads per-call traceparent to the OpenCode server, breaking trajectory:* assertions

1 participant