Address PR review feedback for CountTokensTask introduction - #218
Merged
Conversation
Co-authored-by: sroussey <127349+sroussey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for token counting in AI tasks
Address PR review feedback for CountTokensTask introduction
Feb 20, 2026
sroussey
marked this pull request as ready for review
February 20, 2026 06:24
sroussey
requested changes
Feb 20, 2026
| import { TypeModel } from "./base/AiTaskSchemas"; | ||
|
|
||
| const modelSchema = TypeModel("model"); | ||
| const modelSchema = TypeModel("model:CountTokensTask"); |
Collaborator
There was a problem hiding this comment.
revert, there are no models that register that way.
Contributor
Author
There was a problem hiding this comment.
Reverted in 8d7687c — CountTokensTask is back to TypeModel("model").
Co-authored-by: sroussey <127349+sroussey@users.noreply.github.com>
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.
Fixes correctness issues, silent failures, and missing test coverage flagged in the review of the CountTokensTask PR.
Bug fixes
HierarchicalChunkerTask): Upfront validation now throws ifreservedTokens >= maxTokensPerChunkoroverlapTokens >= effectiveMaxTokens; the chunking loop also clampsendOffset = Math.max(boundary, startOffset + 1)to guarantee forward progress even when a single character exceeds the token budgetHierarchicalChunkerTask): Wrapped provider calls in try/catch to fall back toestimateTokensinstead of propagating errors from unsupported providersOpenAI_JobRunFns): Replaced per-call create/free with a module-level_encoderCachemap keyed by model name; unknown models share the cachedcl100k_baseencoderSchema corrections
HierarchicalChunkerTask: Addeddoc_idtorequired(was runtime-validated but invisible to schema consumers)ContextBuilderTask:totalTokensdescription corrected to "Estimated token count"; docstring purged of references to non-existentcountTokensModel/buildCountTokensFnHierarchicalChunkerTask: Docstring updated to referenceCountTokensTaskandestimateTokensaccuratelyTest coverage
Added focused unit tests for the three new provider run functions:
OpenAI_CountTokens— verifies known-model encoder selection andcl100k_basefallback pathAnthropic_CountTokens— assertsmessages.countTokenscall shape andinput_tokens → countmappingGemini_CountTokens— assertscountTokenscall andtotalTokens → countmappingTest regression fix
Restored the rate-limiter assertion to
>= 12(was loosened to>= 10in the original PR).💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.