fix(branch): accept-before-decode in commit for correct PPL measurement#19
Merged
lloyal-research merged 2 commits intomainfrom Feb 18, 2026
Merged
fix(branch): accept-before-decode in commit for correct PPL measurement#19lloyal-research merged 2 commits intomainfrom
lloyal-research merged 2 commits intomainfrom
Conversation
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.
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.
There was a problem hiding this comment.
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()andBranchStore.commit()now route throughStoreCommitWorker - 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.
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.
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.