Skip to content

TestFilterLargeDiffs_Boundary fails because exactNTokens fixture is not token-exact #1012

Description

@dongyikuan919

Problem

TestFilterLargeDiffs_Boundary currently fails on the latest main branch because its exactNTokens helper assumes that repeating "a " n times produces exactly n cl100k_base tokens. The tokenizer can merge that repeated pattern, so the assumption does not hold.

Reproduction

At commit 9c5e90d0b1b64f84119754b8517b6d9b0978d15f:

go test ./internal/agent -run '^TestFilterLargeDiffs_Boundary$' -count=1

Output on macOS arm64 with the repository's Go 1.25.5 toolchain:

--- FAIL: TestFilterLargeDiffs_Boundary (0.40s)
    agent_test.go:630: fixture drift: llm.CountTokens(<80-token string>) = 39, want 80
FAIL

The same failure also appears during go test ./....

Cause

The helper constructs its fixture with:

s := strings.TrimSpace(strings.Repeat("a ", n))

BPE tokenization is content-dependent, so repeated source words are not guaranteed to map one-to-one to tokens.

Expected behavior

The boundary test should construct text based on the actual tokenizer result (or use a verified non-merging fixture) so a clean checkout's tests pass while still testing exactly 80 versus 81 tokens.

One robust option is to append text incrementally and stop when llm.CountTokens reaches the requested count, failing only if it skips past it.

Activity

  1. dongyikuan919 commented on Aug 20, 2026

    @dongyikuan919
    ContributorAuthor

    The full suite also exposes the same fixture bug in internal/scan: TestFilterLargeScans_Boundary fails with llm.CountTokens(<80-token string>) = 39, want 80. The helper/pattern therefore affects both review-diff and full-scan boundary coverage.

  2. wu21-web commented on Aug 20, 2026

    @wu21-web
    Contributor

    Cannot reproduce on:

    macOS 15.7.7 24G720 arm64
    Xcode 26.3 17C529
    

    with go 1.27

  3. Qiyuanqiii commented on Aug 20, 2026

    @Qiyuanqiii
    Contributor

    Confirmed — I reproduced the exact 39, want 80 failure at commit 9c5e90d in both TestFilterLargeDiffs_Boundary and TestFilterLargeScans_Boundary. The failure appears to involve the tokenizer initialization/fallback path, and I am working on a fix. I will follow up with the implementation and verification results.

  4. added a commit that references this issue on Sep 14, 2026
    813d589
  5. added a commit that references this issue on Sep 17, 2026
    fb73f2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions