Repository navigation
Conversation
…concile When a rollout hits its step or context limit, the capture proxy answers pi with "Step budget exhausted; stopping." instead of calling the model. pi logs that reply like any other. reconcile() already discounts it, but recognises it by its text, and _pi_session_as_atif kept only token counts. Every pi rollout that hit a limit therefore had one more reply than the proxy captured, failed with turn_mismatch, and could not be trained on. Keep each reply's text and tool calls in the ATIF steps the pi reader returns, so the existing stop rule applies. The rule itself is unchanged: it still requires the proxy's own stop counter, zero tokens and no tool calls.
This branch has not been deployed
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
_pi_session_as_atifkeeps only token counts, butreconcilerecognises the proxy's budgetstop by its text. So every pi rollout that hits
agent_step_limitor the context limit failsreconciliation with
turn_mismatchand cannot be trained on. This keeps each reply's text andtool calls in the pi trace, so the existing stop rule applies.
Type of Change
Details
When a rollout hits its limit, the capture proxy answers the next request itself with
"Step budget exhausted; stopping." pi logs that as an ordinary assistant record (zero tokens,
responseId: "budget-…").reconcileis meant to discount it (proxy_budget_stops), but itmatches on
step["message"], which the pi reader never set. The pi trace then has one morereply than the capture, and the rollout fails.
Alignment Checklist
.claude/docs/PRINCIPLES.mdand this PR aligns with our principles.claude/docs/INVARIANTS.mdand no invariants are violatedRFC Status
Test Plan
Two tests in
tests/envs/test_harbor_reconcile.pywrite a pi session log and runload_tracereconcileon it:test_pi_rollout_ended_by_the_proxy_budget_stop_reconciles: fails onmain, passes here.test_pi_zero_token_reply_that_is_not_a_budget_stop_still_fails: an unexplained zero-tokenreply is still rejected.
PYTHONPATH=src:envs uv run pytest tests/envs/test_harbor*.py: 562 passed, 27 skipped, 1 failed.The failure,
test_start_refuses_a_port_held_by_a_non_capture_listener, also fails on anunmodified
mainon macOS. ruff format, ruff check and usort pass on the changed files.Note
Low Risk
Localized adapter fix for pi trace loading with regression tests; no change to core reconcile rules beyond supplying fields pi traces lacked.
Overview
pi session → ATIF fallback used to emit only
metrics.completion_tokens, soreconcilecould not recognize the proxy’s zero-token budget-stop reply (it matches onstep["message"]). Limit-hit pi rollouts then looked like an extra assistant turn and failed withturn_mismatch, blocking training._pi_session_as_atifnow maps assistant text and tool calls from pi’smessage.content(including string content), alongside token counts. The existingproxy_budget_stopspath applies unchanged.Tests build synthetic pi
*.jsonllogs viaload_traceand assert budget-stop rollouts reconcile (withproxy_budget_stops) while other zero-token replies still fail.Reviewed by Cursor Bugbot for commit 8fd35e3. Bugbot is set up for automated code reviews on this repo. Configure here.