Repository navigation
Token budget filters: count_tokens, truncate_tokens, pack (0359, PR 3) - #788
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7p7ukGVxWu4F1K358p
…s (0359) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7p7ukGVxWu4F1K358p
…budget case (0359) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7p7ukGVxWu4F1K358p
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7p7ukGVxWu4F1K358p
…d 0408 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7p7ukGVxWu4F1K358p
…done (#777, #784) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7p7ukGVxWu4F1K358p
|
@codex review @codex security review — please include the prompt escaping paths merged in #777 and #784 ( Generated by Claude Code |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9b1f42759
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Host text may exceed maxSequenceSize, and a token budget does not bound the characters of the prefix (Codex P1 on #788). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWNL7p7ukGVxWu4F1K358p
|
Generated by Claude Code |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DTQTriEsFrrBgcYNKDUUF4
Mark 0359 done and sync the task index after #788
Problem
Task 0359: prompt templates need to fit retrieved content into a token budget. This is the last step of the approved 0358/0359 plan (/mnt/project-files/0358/plan.md, sections 4 and 7). The contract is in
docs/cpp-only-filters.mdanddocs/api-2.0.mdsection 3.3, merged in #766.Resulting behaviour
Tokenizeris a new class ininclude/jinja2cpp/prompt.h, set throughSettings::tokenizer.PromptEscaper, and compares by identity.ceil(utf8 bytes / 4), for narrow and wide templates alike.count_tokenscounts a string with the tokenizer. An empty string costs no call. A count above theint64range saturates.truncate_tokens(n, end='...')keeps the longest prefix that, together withend, fits inntokens.endlonger thannraisesTemplateRuntimeError.pack(budget, attribute, by, reverse, reserve, stop)keeps items in their original order.stopends the packing.bysorts with the code behindsort, which is extracted asSortedOrderByPaths/IsLessKey;Sort's instruction counts are unchanged.listdoes, which appliesMaxSequenceSizeand never holds a lent item past the statement.UserCallableException. For a std exception,GetException()is set.bench/cases/prompt_budget: 200 chunks, thenpack+neutralize|fencewith a word-counting tokenizer.--dump-dirfails if one render exceedsmax_token_calls.benchmark.ymlandpreflight.shcounts the base's own cases when the base driver predates the new settings keys.truncate_tokensshrink loop against a non-monotonic tokenizer).Validation
-Werror. The full ctest passes 8/8 on this head, rebased onto 3660cfd.max_token_callsis lowered to 10.scripts/preflight.sh --perfagainst 3660cfd passes every check. No existing case moves by more than about +0.4%.prompt_budgetis new: Render 1.31M instructions and 76 allocations.Limits
a b...comes out asa b ...with the test's word tokenizer, whose prefix keeps the trailing space. That is a property of the test fixture, not of the filter.wchar_tis exercised only by CI.Process
C++26 clang-20 Debugfailed while apt installed clang-20, before any build; the one re-run passed.truncate_tokensdid not checkmaxSequenceSizeon long host text; now it does, with a narrow and wide test). The security review, asked for again here to cover Add PromptEscaper and the neutralize and fence filters (0358, PR 1) #777 and Prompt autoescape mode (0358, PR 2) #784, did not run.Generated by Claude Code