Repository navigation
fix(tokens): count literal special-token markers as ordinary text - #1062
Merged
Merged
Conversation
Add offline-vocabulary token estimator and knowledge ingestion regressions for #1041.
dovvnloading
commented
Nov 25, 2026
dovvnloading
left a comment
Owner
Author
There was a problem hiding this comment.
Maintainer-requested code review
Verdict: no blocking code findings; suitable for squash merge on the verified automated gates.
- Reviewed both changed files and issue #1041, and traced the shared estimator through
backend/token_counter.pyandbackend/knowledge_chunking.py.encode_ordinary()counts marker spellings as user text, rather than raising or enabling special-token IDs; empty input and missing-encoding fallback are preserved. - The real-tiktoken byte-vocabulary regression, explicit dispatch/fallback tests and file-to-SQLite ingestion regression cover the failure mode, exact stored text, token counts and offsets. No provider encoding, dependency, schema or CI changes.
- CI run 45588129470 succeeded on the reviewed head: Windows Python checks (8,293 passed, 56 skipped, 22 subtests passed; separate performance suite 16 passed), POSIX permissions/Bash E2E, frontend checks and wheel build/install/import. The optional nightly Playwright job is skipped by design on PRs per
AGENTS.md. - Compared the current
mainwith the branch merge base: three intervening commits touch unrelated DAG/layout, workflow preset and documentation files, with no overlap with this fix. GitHub reports a clean merge and there are no outstanding review threads.
Limitations: no independent local native desktop launch or manual composer/import walkthrough; local GitHub DNS resolution and missing tiktoken prevent a configured checkout here. The automated real-tokenizer and ingestion tests are the basis for proceeding at the maintainer's request; manual UI verification remains unchecked. This is a review comment, not independent approval, because the connected account is also the PR author. No checks or branch protections are being overridden.
dovvnloading
marked this pull request as ready for review
November 25, 2026 10:22
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.
Summary
Fixes #1041. Graphlink estimates tokens for arbitrary chat and document text, but tiktoken's default
encode()rejects strings matching reserved special-token spellings. Useencode_ordinary()instead, so literal markers are counted as ordinary text rather than rejected or interpreted as control-token IDs. Empty input and the existing character-count fallback are unchanged.What Changed
TokenEstimator.count_tokensimplementation; no separate ingestion workaround or changes to provider request encoding.Why
Validation
python -m compileall -q .passes (run from the repo root - matches CI)python -m pytest -qpasses (run from the repo root - matches CI)cd web_ui && npm run checkpasses (matches CI)Local full checkout is blocked by GitHub DNS resolution, and tiktoken cannot be installed in this environment. The five real-tokenizer parameterized cases and file-to-SQLite regression are committed but not run locally. The isolated checks do not load the full application or repository conftest. Full CI, lint, dependency checks, and manual verification remain outstanding.
Focused verification in a configured Python 3.12 checkout:
Manual verification: import a UTF-8
.txtdocument containing literal<|endoftext|>and<|fim_prefix|>markers into a temporary workspace, confirm the import succeeds, search for the surrounding text, and verify the stored excerpt retains both marker spellings. Also enter ordinary text and literal markers in the chat composer and confirm the token estimate remains usable.UI Notes
Additional Context
No dependency, schema, frontend, CI or unrelated changes. No direct changes to
main.Maintainer-requested review and validation update
All four required PR CI jobs passed (run 45588129470), including the full Windows pytest suite with coverage (8,293 passed, 56 skipped, 22 subtests passed), 16 serial performance tests, compile/lint/audit, POSIX permissions and Bash E2E, frontend checks, and wheel build/install/import. The prior local-validation limitations above are retained for transparency. App launch and manual native UI verification remain unchecked; the reviewed real-tokenizer and file-to-SQLite regression tests provide automated verification of this backend fix. No independent approval is claimed and no required gate is bypassed. See the submitted review for details.