Repository navigation
harbor: count reasoning tokens a trace logs apart - #1782
Merged
burtenshaw merged 4 commits intoDec 1, 2026
Merged
Conversation
reconcile() compares each captured call's sampled tokens with the ATIF step's completion_tokens. Harbor's opencode trace counts only the visible answer there and logs thinking in metrics.extra.reasoning_tokens, so every call of a thinking model differed by its reasoning, the rollout failed as a mismatch, and no opencode rollout of such a model could be trained on. The per-step sums replace the counts only when they then equal the capture or are a subsequence of it, so a difference reasoning does not explain still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The docs for this pull request are available at https://openenv.github.io/OpenEnv/pr-preview/pr-1782/ (commit 8740af0). The preview may take a minute to update and is removed when the pull request closes. |
Harbor's pi trace writes `metrics.extra.reasoning_tokens` too, but as thinking already counted in `completion_tokens`. When pi's own counts lined up through the auxiliary-call path and the reasoning sums happened to fit as well, the sums won: a real agent turn was marked auxiliary and masked, while the auxiliary call stayed trainable with the rollout's reward. The sums now apply only when the trace's own counts do not line up, so a rollout that reconciles today keeps its verdict and its auxiliary calls. Co-authored-by: Cursor <cursoragent@cursor.com>
The negative test only covered a call whose difference reasoning does not explain. Add a capture that lost one call's thinking: choosing the sum per step would accept it, so pin that the trace's reading applies to all steps and that the failure is the turn mismatch. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
reconcilecompares each captured call's sampled token count with the ATIF step'scompletion_tokens. Harbor's opencode trace counts only the visible answer there and logs the thinking inmetrics.extra.reasoning_tokens. The engine sampled both, so with a thinking model every call differs by its reasoning: the rollout fails the check and can't be trained on. This adds the logged reasoning back, but only when that makes the counts line up.Type of Change
What happened without it
opencode with a thinking model in GRPO training: every rollout failed the ATIF cross-check, and none was trainable. The captured counts were exactly
completion_tokens + reasoning_tokensper call.Changes
atif.py:_with_reasoning_tokensadds each step'smetrics.extra.reasoning_tokensto itscompletion_tokens.reconcileuses the sums only when they equal the captured counts or are a subsequence of them (the existing auxiliary-call path). Otherwise the original counts are kept and the existing failures apply.extra.reasoning_tokensand non-thinking runs give the same counts as before.Test Plan
Three tests added to
tests/envs/test_harbor_reconcile.py:The first two fail on
main.55 passed.
ruff format --check,ruff checkandusort checkare clean.Used in production as a runtime patch for opencode GRPO training with a thinking model.
RFC Status
🤖 Generated with Claude Code
Note
Medium Risk
Changes the trainability gate in
reconciletoken comparison, but only applies reasoning sums after the existing exact-match and subsequence checks to avoid masking real capture errors.Overview
Fixes ATIF reconciliation for thinking models when Harbor’s opencode trace reports only visible output in
completion_tokensand puts thinking tokens inmetrics.extra.reasoning_tokens, while the intercept counts both.reconcilenow builds the ATIF side via_with_reasoning_tokens: it adds per-stepreasoning_tokenstocompletion_tokensonly when the raw trace counts do not already match the capture, and the full adjusted list either equals captured turn lengths or fits as the existing auxiliary-call subsequence. If raw counts already align, or the adjusted totals still do not explain the gap, the original trace counts are kept so real mismatches still surface asturn_mismatch(including pi-style traces where reasoning is already insidecompletion_tokens).Adds reconcile tests for opencode-style split logging, auxiliary calls with reasoning, pi-style double-counting safety, and cases where reasoning does not explain the difference.
Reviewed by Cursor Bugbot for commit 8740af0. Bugbot is set up for automated code reviews on this repo. Configure here.