Skip to content

fix(tokenizer): finish and resume completed input only once - #2538

Merged
fb55 merged 1 commit into
masterfrom
fix/resume-after-eof
Oct 11, 2026
Merged

fb55 merged 1 commit into
masterfrom
fix/resume-after-eof

Conversation

@fb55

@fb55 fb55 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

EOF entity decoding can leave the tokenizer's cursor before the end of the buffer. resume() then re-parsed that suffix and end() could finish twice. Completed input is now finished and resumed only once; two tests pin both paths.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where resuming after input was fully processed could emit duplicate events or parse input again, including for incomplete comments and character references.
    • After the parser is reset, it can process new input and emit its completion event normally. Repeated resumes after completion no longer emit additional events, including when parsing text containing a character reference followed by other text.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 00:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T00:17:32.249047Z 8b57819 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a98ef596-c082-4ef1-a5fe-12c9c1842146

📥 Commits

Reviewing files that changed from the base of the PR and between 9c3d433 and 8b57819.


📒 Files selected for processing (2)
  • src/Parser.spec.ts
  • src/Tokenizer.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

The tokenizer now tracks whether it has finished handling input. It does not finish or reparse input after completion. Reset clears the completion state. New parser tests cover paused input, repeated resumes, and reset.

Changes

Tokenizer Completion

Layer / File(s) Summary
Track completion and prevent reprocessing
src/Tokenizer.ts, src/Parser.spec.ts
Tokenizer sets a completion flag before processing trailing data and calling onend(). reset() clears the flag, and end() and resume() check it. Regression tests cover paused parsing, repeated resumes, and parsing after reset.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to 8b578

Input that has already been completed is now finished and resumed only once. Pausing during end still produces exactly one end event. No merge-blocking issues remain.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing repeated tokenizer finishing and resume processing.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit taps the parser’s door,
“No extra endings,” says the hare.
The tokenizer marks the final page,
Then reset starts a fresh one there.
“Next,” says the rabbit, and hops away.

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The completion guard addresses both failure paths and is covered by focused regression tests.

0 open findings

What changed in this PR

Prevents duplicate tokenizer completion and suffix reprocessing after EOF.

Changes:

  • Tracks completed tokenizer input and guards repeated end()/resume().
  • Adds regression tests for pause/resume, entity suffixes, and reset reuse.
File Description
src/​Tokenizer.ts Adds and resets completion state.
src/​Parser.spec.ts Covers duplicate completion and suffix parsing.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/Tokenizer.ts">

<violation number="1" location="src/Tokenizer.ts:263">
P3: `write()` is not guarded by the new `finished` flag, so the class is now internally inconsistent: after `end()` (which sets `finished` in `finish()`), a direct `write(chunk)` on the tokenizer still parses the chunk and emits callbacks, but a later `end()`/`resume()` is a no-op, so `onend` will never fire for that data. Before this change, the second `end()` in that misuse path redundantly re-emitted `onend`; now it emits nothing at all. `Parser` happens to protect against writes after `end()` via its own `ended` check, but `Tokenizer` is a public export used directly in `Tokenizer.spec.ts`, and all three `finished`-aware entry points (`end`, `resume`, and now `write`) should treat end-of-input the same way.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread src/Tokenizer.ts Outdated
resume(): void {
this.running = true;
if (this.index < this.buffer.length + this.offset) {
if (!this.finished && this.index < this.buffer.length + this.offset) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: write() is not guarded by the new finished flag, so the class is now internally inconsistent: after end() (which sets finished in finish()), a direct write(chunk) on the tokenizer still parses the chunk and emits callbacks, but a later end()/resume() is a no-op, so onend will never fire for that data. Before this change, the second end() in that misuse path redundantly re-emitted onend; now it emits nothing at all. Parser happens to protect against writes after end() via its own ended check, but Tokenizer is a public export used directly in Tokenizer.spec.ts, and all three finished-aware entry points (end, resume, and now write) should treat end-of-input the same way.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/Tokenizer.ts, line 263:

<comment>`write()` is not guarded by the new `finished` flag, so the class is now internally inconsistent: after `end()` (which sets `finished` in `finish()`), a direct `write(chunk)` on the tokenizer still parses the chunk and emits callbacks, but a later `end()`/`resume()` is a no-op, so `onend` will never fire for that data. Before this change, the second `end()` in that misuse path redundantly re-emitted `onend`; now it emits nothing at all. `Parser` happens to protect against writes after `end()` via its own `ended` check, but `Tokenizer` is a public export used directly in `Tokenizer.spec.ts`, and all three `finished`-aware entry points (`end`, `resume`, and now `write`) should treat end-of-input the same way.</comment>

<file context>
@@ -257,7 +260,7 @@ export default class Tokenizer {
     resume(): void {
         this.running = true;
-        if (this.index < this.buffer.length + this.offset) {
+        if (!this.finished && this.index < this.buffer.length + this.offset) {
             this.parse();
         }
</file context>

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

This PR makes completed input finish only once and prevents resume() from parsing an entity suffix again.

  • The tokenizer finishes completed input only once.

Reviews (2) · Last reviewed commit: "fix(tokenizer): finish and resume comple..." · Reviewed by Greptile

EOF entity decoding can leave the cursor before the end of the buffer. Prevent resume from parsing that suffix again as well as preventing a second finish.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@fb55
fb55 force-pushed the fix/resume-after-eof branch from 9c3d433 to 8b57819 Compare October 11, 2026 00:15
@fb55
fb55 merged commit 649a241 into master Oct 11, 2026
18 checks passed
@fb55
fb55 deleted the fix/resume-after-eof branch October 11, 2026 00:20
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