Skip to content

fix(branch): accept-before-decode in commit for correct PPL measurement#19

Merged
lloyal-research merged 2 commits intomainfrom
feat/commit-rollback-support
Feb 18, 2026
Merged

fix(branch): accept-before-decode in commit for correct PPL measurement#19
lloyal-research merged 2 commits intomainfrom
feat/commit-rollback-support

Conversation

@lloyal-research
Copy link
Copy Markdown
Contributor

commit() was calling decode before accept, so model_surprisal() measured against P(T+1|context,T) instead of P(T|context) — yielding PPL in the millions. Reorder to accept-first with RAII snapshot rollback on decode failure. Branch.commit() now routes through StoreCommitWorker so both single and batched paths share one code path.

commit() was calling decode before accept, so model_surprisal() measured
against P(T+1|context,T) instead of P(T|context) — yielding PPL in the
millions. Reorder to accept-first with RAII snapshot rollback on decode
failure. Branch.commit() now routes through StoreCommitWorker so both
single and batched paths share one code path.
Copilot AI review requested due to automatic review settings February 18, 2026 14:25
Triggers a real decode failure via KV exhaustion (nCtx=32 clamped to 256,
8 reseeded branches, ~32 rounds). Verifies PPLs are unchanged after the
failed batched commit and that single-branch commits still work.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a perplexity (PPL) measurement bug where commit() was calculating PPL against P(T+1|context,T) instead of P(T|context), resulting in PPL values in the millions. The fix reorders operations to accept-first (for correct metrics), then decode, with RAII-based snapshot rollback on decode failure.

Changes:

  • Unified commit path: Both Branch.commit() and BranchStore.commit() now route through StoreCommitWorker
  • Accept-first ordering with rollback: Tokens are accepted for correct PPL measurement before decode, with automatic state restoration on failure
  • Added PPL sanity test to verify perplexity stays within reasonable bounds (1 to 1000)

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/SessionContext.cpp Refactored StoreCommitWorker to implement accept-first ordering with RAII snapshot/rollback mechanism
lib/Branch.js Changed commit() to route through _storeCommit instead of calling decodeAndCaptureOne + accept
lib/index.d.ts Updated documentation to reflect accept-first ordering with rollback semantics
test/integration.js Added testPplSanity() to verify PPL remains in [1, 1000) range after commits
test/examples.js Tightened PPL assertion from >= 1 to > 1 && < 1000 with better error message

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lloyal-research lloyal-research merged commit 85c9625 into main Feb 18, 2026
5 checks passed
@lloyal-research lloyal-research deleted the feat/commit-rollback-support branch February 20, 2026 03:09
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