Skip to content

fix: dedup suffix chunks in terminal IME re-emission#772

Merged
xiaolai merged 1 commit intomainfrom
fix/audit-768
Apr 12, 2026
Merged

fix: dedup suffix chunks in terminal IME re-emission#772
xiaolai merged 1 commit intomainfrom
fix/audit-768

Conversation

@xiaolai
Copy link
Copy Markdown
Owner

@xiaolai xiaolai commented Apr 12, 2026

Closes #768

Summary

  • onData IME dedup used lastCommittedText.startsWith(data), which blocked prefix chunks but let suffix chunks slip through when xterm split a commit like "你好世界" into "你好" + "世界".
  • Added a consumed-prefix pointer (lastCommittedConsumed + lastSeenCommitTime) on SessionEntry so each chunk is matched against the remainder of lastCommittedText, and the pointer resets when a new commit lands.
  • Preserves existing equal/prefix/full-text match behavior; only tightens the split-chunk case.

Test plan

  • pnpm test src/components/Terminal — 282 tests, all pass (includes 4 new #768 tests covering: split suffix blocking, unrelated text passthrough after full consumption, pointer reset across commits, and data longer than remainder)
  • pnpm check:all — 17855 tests pass, build succeeds
  • Manual (macOS, CJK IME): type a multi-character phrase; terminal shows the phrase exactly once

The onData dedup safety net used `lastCommittedText.startsWith(data)`,
which only matched prefix chunks. When xterm split a committed IME
phrase like "你好世界" into "你好" + "世界" across two onData calls,
the suffix chunk slipped through and duplicated into the PTY.

Track a consumed-prefix pointer on SessionEntry that advances as
chunks are absorbed. Reset it when `instance.lastCommitTime` changes
so prior-chunk state doesn't leak across commits. Suffix chunks now
match against the remainder of the committed text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xiaolai xiaolai added the audit Codebase audit finding label Apr 12, 2026
@xiaolai
Copy link
Copy Markdown
Owner Author

xiaolai commented Apr 12, 2026

VERIFIED — The audit finding is resolved. The diff adds lastCommittedConsumed/lastSeenCommitTime fields and slices lastCommittedText against the consumed pointer so suffix chunks (e.g., "世界" after "你好") are absorbed, with pointer reset on new commits and tests covering split-chunk dedup, unrelated passthrough, new-commit reset, and over-length data — scope is limited to useTerminalSessions.ts and the co-located test file as required.

@xiaolai xiaolai enabled auto-merge (squash) April 12, 2026 12:46
@xiaolai xiaolai merged commit 07bb17b into main Apr 12, 2026
8 checks passed
@xiaolai xiaolai deleted the fix/audit-768 branch April 12, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit Codebase audit finding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[audit] terminal: IME dedup startsWith check misses suffix chunks on split re-emission

1 participant