Skip to content

Split divergent token histories by default - #782

Merged
bradhilton merged 2 commits into
mainfrom
agent/reconcile-tokenizations
Jul 29, 2026
Merged

Split divergent token histories by default#782
bradhilton merged 2 commits into
mainfrom
agent/reconcile-tokenizations

Conversation

@bradhilton

@bradhilton bradhilton commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Make protocol-native trajectory histories preserve divergent served token identities by default instead of automatically reconciling text-equivalent prefixes.

  • split Chat Completions, Responses, Anthropic Messages, and string Completions histories when a later prompt does not extend the exact sampled-token lineage
  • add reconcile_text_equivalent_tokenizations=True as an explicit opt-in on history projection, Trajectory.tokenize(), and TrajectoryGroup.tokenize()
  • preserve exact sampled token IDs, SAMPLED provenance, and rollout logprobs when an unchanged generated suffix appears in a later split history
  • remove the reconciliation option from token-based Completions histories, whose token identity is already explicit
  • require exchange-based preprocessing/PipelineTrainer inputs to contain only inference-provided TokenFlag.EXACT tokens
  • cache parsed generation evidence so divergent long-history projection scales with captured input size instead of repeatedly reparsing prior generations

Why

Rendered text can remain identical while its token IDs differ from the sequence originally sampled by the policy. Treating those turns as one history silently changes the RL sequence. The safe default is now to expose separate histories; callers may explicitly opt into best-effort text-equivalent reconciliation.

Splitting must not discard valid rollout evidence. When a later exact prompt proves that an earlier sampled output is retained, that output keeps its original token IDs, logprobs, EXACT, and SAMPLED flags in the descendant history.

The preprocessing path fails closed when exchange tokenization required local rendering, matching its strict tokens-in/tokens-out requirement.

Validation

  • focused trajectory suites: 201 passed
  • CPU-compatible broader unit suite: 591 passed, 6 skipped
  • two unrelated OpenAI stream-close tests fail only in full-suite order on this workstation and pass 2/2 in isolation; CI is authoritative for their configured environment
  • Ruff lint/format, ty, prek, and lock consistency: passed
  • source distribution and wheel build: passed
  • divergent 100-turn Chat projection improved from the reviewer-observed ~24 seconds to ~0.20 seconds; regression coverage asserts each exact generation is parsed once

The full GitHub quality, package-install, and TrainerRank classification checks will rerun against the updated head.

@bradhilton
bradhilton force-pushed the agent/reconcile-tokenizations branch from bf680b8 to 627f0f3 Compare July 29, 2026 00:47
@bradhilton
bradhilton marked this pull request as ready for review July 29, 2026 02:12
@bradhilton
bradhilton merged commit 93f3832 into main Jul 29, 2026
10 checks passed
@bradhilton
bradhilton deleted the agent/reconcile-tokenizations branch July 29, 2026 02:18
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.

1 participant