fix grammar rejection cache: content-based keys, index-only values - #2434
Draft
Reithan wants to merge 1 commit into
Draft
fix grammar rejection cache: content-based keys, index-only values#2434Reithan wants to merge 1 commit into
Reithan wants to merge 1 commit into
Conversation
Assisted-by: Claude Sonnet
Owner
|
you should PR to the experimental branch, and i think this PR conflicts with your previous one. Also I don't actually think there is any performance improvement in fact I think that this actually performs worse. |
Author
|
Let me re-target to experiment and I'll mark this as draft and run a few more tests. 👍 |
Reithan
marked this pull request as draft
September 6, 2026 02:54
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.
Overview
Fix two bugs in the grammar rejection cache (
candidates_memos) that prevented cross-step cache hits and introduced a use-after-free.The cache stores results from
reject_candidates_for_stackand persists across tokens for the duration of a request. Two problems prevented it from working correctly.First, the hash function used pointer identity for the
code_pointsfield rather than the content at those pointers. Each step's apply call rebuilds the candidate list with new allocations, so the pointers differ across steps even when the content is identical. The cache could not produce hits across steps.Second, cache values stored full candidate structs, which include raw
code_pointspointers into a buffer local to the apply call. Retaining those pointers after the call returns leaves dangling references; a cache hit in a later step dereferences freed memory.The two bugs interacted: the hash bug prevented cross-step hits, which masked the use-after-free because the stale pointers were never read in practice.
Additional information
Changes:
Existing grammar tests cover the rejection logic. The bugs required cross-step conditions that existing tests do not exercise, so no new tests are added.
Requirements