64+def handleOpencodeLLMCtx(llm_ctx: LLMCtx, commitId: str) -> LLMCtx:
65+"""Tag opencode-gateway LLM contexts with the run's session header."""
66+ctx = llm_ctx
67+if ctx is not None and "opencode" in str(ctx.baseUrl):
Opencode session tagging overwrites configured LLM headers in place
- packages/api/src/app/workflows/triggers/_common.py:68 assigns ctx.defaultHeaders = {"x-opencode-session": …}, discarding existing entries.
- packages/api/src/app/services/llm/service.py:108,152 populate defaultHeaders from settings.llm_default_headers (gateway ids / tags per packages/api/src/app/core/config.py:227).
- packages/api/src/app/workflows/triggers/review.py:254,401 calls this on every trigger right after resolveLlmCtx, so opencode-gateway runs silently lose those headers; ctx = llm_ctx also mutates the caller's LLMCtx instead of copying.
Fix: Merge instead of replace on a copy, e.g. return ctx.model_copy(update={"defaultHeaders": {...}ctx.defaultHeaders, "x-opencode-session": f'session-{commitId[:6]}'}}).