Repository navigation
fix(tokenizer): finish and resume completed input only once - #2538
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to 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 |
|
There was a problem hiding this comment.
🟢 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.
There was a problem hiding this comment.
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
| resume(): void { | ||
| this.running = true; | ||
| if (this.index < this.buffer.length + this.offset) { | ||
| if (!this.finished && this.index < this.buffer.length + this.offset) { |
There was a problem hiding this comment.
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>
|
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>
9c3d433 to
8b57819
Compare
EOF entity decoding can leave the tokenizer's cursor before the end of the buffer.
resume()then re-parsed that suffix andend()could finish twice. Completed input is now finished and resumed only once; two tests pin both paths.🤖 Generated with Claude Code
Summary by CodeRabbit