Skip to content

feat(session): session server v2 — opt-in trajectory-tree serving; v1 preserved byte-exact - #1771

Closed
guapisolo wants to merge 8 commits into
mainfrom
feat/session-rollback-mode
Closed

feat(session): session server v2 — opt-in trajectory-tree serving; v1 preserved byte-exact#1771
guapisolo wants to merge 8 commits into
mainfrom
feat/session-rollback-mode

Conversation

@guapisolo

@guapisolo guapisolo commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Motivation

The session server needs multi-lineage trajectory support (retries, compaction with carried assistants, subagent forests). Earlier revisions of this branch replaced the linear implementation in place; that made a brand-new system look like an evolution of the old one and put the default production path at risk. This revision restructures the work so that:

  • v1 (linear trajectory) is preserved byte-exactly and stays the default. git diff against the pre-branch base is empty for every v1 module and test file.
  • The tree implementation lands as an opt-in session server v2 (--use-session-server v2), fully contained in miles/rollout/session/v2/.

Commit series (atop the stacked picks)

  1. test(session): nine byte-exact HTTP pins for the v1 retry/rollback surface, verified against the untouched tree — the default path can never move silently. Includes a characterization pin for v1's few-shot prompt-assistant anchoring quirk (out of v1's append-only + one-step-retry envelope; such flows belong to v2).
  2. fix(tito): preserve-think kwargs become family constants on every template surface ("never cut think"), plus supports_midpath_assistant_rerender marking DeepSeek-V3.2's structural exception. Spike-verified byte-identical on pure tool loops.
  3. feat(session): v2 trajectory tree — node = end of one model generation, full root→node token snapshots, pure deepest-prefix attach search, append-only commits under the session lock (MAX_NODES=1024 backstop).
  4. feat(session): session server v2 — always-branch serving (mismatches grow siblings/new roots; retry semantics moves to the samples-op picker), --session-strict-append-only single-chain guard, compaction splice with zero-inheritance-root fallback, 409 on extending truncated generations, per-leaf assembly with default pick (temporal-supersession trim, roots never trimmed, non-retry-shaped trees 422) and default merge (exactly-once completion masking, rewards keyed by response id), both replaceable via --session-sample-picker-path / --session-merge-function-path. Version dispatch is a ~10-line seam in sessions.py; the codec is parameterized so the v1 wire stays byte-identical while v2 adds reward/metadata.
  5. feat(rollout): driver-side seam — the agent's semantic layer (per-branch rewards) travels through collect_samples under v2 and comes back applied by the server-side merge; the v1 driver path (metadata overlays, {"max_seq_len": ...} collect body) is byte-equal to before, pinned.
  6. test(session): tree-merge legality invariants — an independent oracle over randomized forests (seeded fuzz banks for retry shapes, truncation, guardrail-422 shapes) plus targeted edges (chained retries, equal-length twins, fork-below-fork ownership, mid-path length turns).

Testing

  • v1: restored suites pass unmodified; A-list byte-exactness proven by empty git diff against base; new v1 pins green against the pristine tree.
  • v2: HTTP matrix (branching, strict, truncation/compaction), session-state unit matrix (49), samples-op suite (16, incl. hook lanes), tree model (18), invariants fuzz (59). Router + session + generate_utils: 326 passed.
  • chat-template suite: 1463 passed (1 pre-existing failure on upstream picks, unrelated).

Follow-ups

  • GPU e2e for v2 branching flows (session_verify_runner branching-harness variant) on 4×H200 CI.
  • v2 twins of the race-condition / pretokenized e2e suites (v1-only today).

🤖 Generated with Claude Code

https://claude.ai/code/session_01NmYsBAGK6NDt1LzjA7VSqH

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@guapisolo
guapisolo force-pushed the feat/session-rollback-mode branch from 96f91e7 to 58bc6d5 Compare July 23, 2026 19:42
@guapisolo guapisolo changed the title feat(session): always-branch trajectory tree — serving policy moves to pluggable sample assembly feat(session): session server v2 — opt-in trajectory-tree serving; v1 preserved byte-exact Jul 23, 2026
@guapisolo
guapisolo force-pushed the feat/session-rollback-mode branch from 58bc6d5 to 0a603cb Compare July 25, 2026 01:30
@guapisolo
guapisolo requested a review from yushengsu-thu as a code owner July 25, 2026 01:30
@guapisolo
guapisolo marked this pull request as draft July 25, 2026 01:48
@guapisolo
guapisolo force-pushed the feat/session-rollback-mode branch from 0a603cb to 726d141 Compare July 29, 2026 02:25
@guapisolo
guapisolo changed the base branch from main to refactor/session-samples-op July 29, 2026 02:27
@guapisolo
guapisolo changed the base branch from refactor/session-samples-op to main July 29, 2026 02:27
@guapisolo
guapisolo force-pushed the feat/session-rollback-mode branch from 726d141 to 44aa107 Compare July 30, 2026 01:06
@guapisolo
guapisolo force-pushed the feat/session-rollback-mode branch 7 times, most recently from 02f26d7 to cca9e35 Compare August 2, 2026 23:14
@guapisolo
guapisolo force-pushed the feat/session-rollback-mode branch from 4e50fc2 to c19f244 Compare August 3, 2026 07:50
Select v2 explicitly for multi-role GPU verification and generic agentic and pretokenized CPU fixtures. Align test assertions with v2 trajectory lists and tree metadata while preserving intentional v1 characterization coverage.
@guapisolo
guapisolo force-pushed the feat/session-rollback-mode branch from 10548c5 to f52b9f4 Compare August 3, 2026 20:05
@guapisolo
guapisolo marked this pull request as ready for review August 3, 2026 22:19
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@guapisolo guapisolo closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant