Skip to content

fix(tracing): forward Codex reasoning effort from turn_context - #85

Merged
hassiebp merged 3 commits into
mainfrom
fix/forward-reasoning-effort
Sep 22, 2026
Merged

hassiebp merged 3 commits into
mainfrom
fix/forward-reasoning-effort

Conversation

@milanagm

@milanagm milanagm commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Linear: LFE-16502

Summary

Export Codex's per-turn reasoning effort to Langfuse.

  • Read the value from turn_context. Codex writes it as effort; reasoning_effort is accepted as a forward-compatible alias.
  • Export it as generation modelParameters.reasoning_effort, plus codex.reasoning_effort metadata on the turn and on each generation.

Supersedes #43, which targets the same gap but was written before #78 landed.

Why #43's thread_settings_applied branch is not carried over

Measured across all 119 local rollouts (Codex up to 0.155.0):

field occurrences
turn_context.effort 1618 / 1618 turn_context lines
turn_context.reasoning_effort 0
thread_settings_appliedthread_settings.reasoning_effort 44 total — 42 between turns, 2 inside an open turn (both equal to turn_context.effort)

Since #78, parseSession guards non-turn-opening events with else if (!turn) continue;, and finishTurn sets turn = null. Codex emits thread_settings_applied after task_complete with turn_id: null, so 42 of the 44 never reach a handler at all. #43's branch is dead code against current main, and the 2 occurrences that would fire carry a value turn_context already provided. turn_context is also the per-turn record of what was actually sent to the model, which makes it the authoritative source.

Note that #43 prefers reasoning_effort over effort — i.e. it prefers the key that never appears in practice. This PR inverts that precedence.

Verification

Two fresh codex exec runs on Codex 0.155.0 (-c model_reasoning_effort=high and =low), each exported through the real Stop hook bundle:

modelParameters codex.reasoning_effort
main {} absent
this branch, high run {"reasoning_effort":"high"} high
this branch, low run {"reasoning_effort":"low"} low

The low/high pair confirms the value is read per turn rather than set to a constant.

tsc --noEmit clean, prettier --check clean, 57 of 58 tests pass.

Pre-existing failure, not introduced here

trace.test.ts > convertRollout > "does not re-export a settings event between turns on every invocation" fails on this branch and on mainmain's CI has been red since a1eb683. The test calls convertRollout, which only returns the exported turn ids; the dedup sidecar is written by the hook in src/index.ts. The second-pass dedup it asserts therefore cannot happen. Left untouched here so the fix stays reviewable on its own.

Commits

  • refactor: removed unnecessary comments — removes 94 comment lines from src/, no code change
  • added effort to be traced — the feature itself

The branch is one commit behind main (the OpenTelemetry bump in #19). GitHub diffs against the merge base, so that bump does not appear here; use "Update branch" before merging.

@milanagm
milanagm requested a review from hassiebp September 19, 2026 07:45

@claude claude 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.

Looks good — small, well-tested, additive change.

What was reviewed: the turn_context parsing in parse.ts (effort preferred over reasoning_effort, matching the measured field usage described in the PR), the new reasoningEffort propagation into root metadata, generation modelParameters, and generation metadata in trace.ts, and the corresponding new tests in parse.test.ts/trace.test.ts. Checked that the comment removals are purely cosmetic (diffed logic lines only, no behavior change). Also confirmed the pre-existing convertRollout dedup test failure noted in the PR description is unrelated to this change (it stems from an earlier commit, #78) and not newly introduced here.

Extended reasoning...

Overview

The diff adds an optional reasoningEffort field threading from turn_context payloads (parse.ts/types.ts) through to Langfuse observation metadata and generation modelParameters (trace.ts). It also strips a large number of pre-existing explanatory comments with no logic changes, verified by diffing only non-comment lines and confirming behavior is unchanged.

Security risks

None. This is a read-only metadata enrichment: it reads a string field (effort/reasoning_effort) already present in Codex rollout JSON and forwards it as observation metadata/model parameters to Langfuse. No new external input parsing beyond an existing trusted-format field, no auth/permissions/crypto code touched, no injection surface introduced.

Level of scrutiny

Low-to-moderate is appropriate: the change is small, additive, mechanical, and confined to an internal tracing/observability plugin (not a critical path like auth or payment). The precedence logic (effort over reasoning_effort) is simple and directly tested. I verified the fallback logic manually: typeof p.effort === "string" ? p.effort : p.reasoning_effort, then only assigns if the result is a string — this correctly preserves the previous turn's value when a later turn_context lacks the field, consistent with the existing t.model = p.model ?? t.model pattern already in the file.

Other factors

New test coverage in parse.test.ts directly exercises the two claimed properties (turn_context-per-turn vs. thread_settings between turns, and the effort/reasoning_effort alias precedence), and trace.test.ts asserts the metadata and modelParameters propagation end-to-end. The PR description's claim about a pre-existing unrelated test failure (does not re-export a settings event...) is plausible and traces to an earlier commit (#78), not this diff. The bug-hunting system reported no findings, and my own read of the diff found no logic issues, so this is a solid candidate for approval without requiring further human review.

@milanagm
milanagm force-pushed the fix/forward-reasoning-effort branch from a034fcd to e32fc79 Compare September 19, 2026 07:52
@hassiebp
hassiebp merged commit cabcbf7 into main Sep 22, 2026
2 checks passed
@milanagm
milanagm deleted the fix/forward-reasoning-effort branch September 22, 2026 09:56
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.

2 participants