Conversation
Greptile SummaryThis PR adds OpenCode trace extraction support by reading the
Confidence Score: 5/5Safe to merge; the new extractor is gated behind a feature flag that defaults to false, so existing deployments are unaffected. The change is additive and opt-in. The extractor follows the same shape as the Codex extractor, is well-tested, and the feature flag defaults to false so no existing behavior changes on upgrade. internal/server/middleware/trace.go — the extractor is missing whitespace trimming (noted in prior review threads) and has no trace-ID format validation, unlike the ClaudeCode path. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as OpenCode Client
participant MW as WithTrace Middleware
participant Ext as tryExtractTraceIDFromOpenCodeRequest
participant DB as TraceService
Client->>MW: POST /v1/chat/completions x-session-affinity: session-id
MW->>MW: getTraceIDFromHeader() → empty
MW->>Ext: "config.OpenCodeTraceEnabled == true"
Ext->>Ext: c.GetHeader("x-session-affinity")
Ext-->>MW: "traceID = session-id"
MW->>DB: GetOrCreateTrace(projectID, traceID)
DB-->>MW: trace entity
MW->>MW: contexts.WithTrace(ctx, trace)
MW->>MW: shared.WithSessionID(ctx, traceID)
MW-->>Client: continue to handler
Reviews (2): Last reviewed commit: "feat: opencode trace, close #1740" | Re-trigger Greptile |
| // OpenCodeTraceEnabled enables extracting trace IDs from OpenCode request headers. | ||
| // Default to false. | ||
| OpenCodeTraceEnabled bool `conf:"opencode_trace_enabled" yaml:"opencode_trace_enabled" json:"opencode_trace_enabled"` |
There was a problem hiding this comment.
🔴 Missing SetDefault for opencode_trace_enabled prevents env var configuration
The new OpenCodeTraceEnabled config field (internal/tracing/tracing.go:46) lacks a corresponding v.SetDefault("server.trace.opencode_trace_enabled", false) call in conf/conf.go:164, unlike the analogous claude_code_trace_enabled and codex_trace_enabled fields which both have defaults at conf/conf.go:163-164. With Viper v1.21.0, AutomaticEnv only intercepts explicit Get() calls — during Unmarshal, Viper builds a settings map from registered keys (defaults, config file, flags, overrides) and only checks env vars for those known keys. Without SetDefault, the key server.trace.opencode_trace_enabled is never registered, so setting AXONHUB_SERVER_TRACE_OPENCODE_TRACE_ENABLED=true (the standard env var pattern documented for other trace options) will be silently ignored. YAML config file values still work because Viper reads file contents directly.
Prompt for agents
The new OpenCodeTraceEnabled config field needs a default value registered in conf/conf.go's setDefaults function, just like the existing claude_code_trace_enabled and codex_trace_enabled fields. In conf/conf.go, after line 164 (v.SetDefault("server.trace.codex_trace_enabled", false)), add: v.SetDefault("server.trace.opencode_trace_enabled", false). Additionally, for consistency, add a corresponding entry in config.example.yml after the codex_trace_enabled line (around line 19): opencode_trace_enabled: false # Enable extracting trace IDs from OpenCode X-Session-Affinity header (env: AXONHUB_SERVER_TRACE_OPENCODE_TRACE_ENABLED)
Was this helpful? React with 👍 or 👎 to provide feedback.
Uh oh!
There was an error while loading. Please reload this page.