open-code-review/internal/scan
chethanuk 9ab06166d4
refactor(agent,scan): share one 80% token threshold (#421)
tokenWarningThreshold = 0.80 is defined in internal/llmloop, but it is
unexported, so the four call sites outside that package could not reach
it and each hardcoded '* 4 / 5' instead. The 80% policy therefore had two
encodings that could silently drift apart.

Add llmloop.PromptTokenLimit and route all six sites through it:

  internal/agent/agent.go:594, 790
  internal/scan/agent.go:321, 555
  internal/llmloop/compression.go:99
  internal/llmloop/loop.go:440

loop.go:439's softLimit stays inline; it uses the separate 60%
tokenSoftThreshold, which has a single consumer and stays unexported.

Behaviour is unchanged. 0.80 in float64 is strictly above exact 4/5, so
for positive x the product never rounds below the exact value and
truncation lands on the same integer; verified over
x in [-5_000_000, 5_000_000] with zero divergences. The float form is
also the more robust of the two: x*4 overflows int64 above MaxInt64/4,
where the old expression silently returned 0 (i.e. no limit).

The <= 0 guards stay at the call sites. filterLargeDiffs/filterLargeScans
treat a non-positive limit as keep-everything, while the pre-flight gates
treat it as a ceiling that rejects every prompt, so the helper does not
special-case it.

Tests: TestPromptTokenLimit pins the arithmetic with hand-computed
expectations, and new boundary tests pin the threshold itself - with
MaxTokens=100 an exactly-80-token input is kept and an 81-token one
dropped. The pre-existing filter tests survive mutating the constant to
both 0.75 and 0.85; the new ones fail on both.

Closes #417
2026-07-21 16:57:28 +08:00
..
agent.go refactor(agent,scan): share one 80% token threshold (#421) 2026-07-21 16:57:28 +08:00
agent_test.go refactor(agent,scan): share one 80% token threshold (#421) 2026-07-21 16:57:28 +08:00
batch.go feat: add ocr scan for full-file code review (#93) 2026-06-24 22:07:25 +08:00
batch_test.go feat: add tool_calls field to JSON output (#216) 2026-06-25 13:53:06 +08:00
budget_test.go feat: add tool_calls field to JSON output (#216) 2026-06-25 13:53:06 +08:00
coverage_test.go fix(scan): check user include patterns before the extension allowlist (#378) 2026-07-17 16:38:21 +08:00
dedup_test.go feat: add tool_calls field to JSON output (#216) 2026-06-25 13:53:06 +08:00
estimate.go feat: add ocr scan for full-file code review (#93) 2026-06-24 22:07:25 +08:00
estimate_test.go feat: add tool_calls field to JSON output (#216) 2026-06-25 13:53:06 +08:00
init_test.go fix(session): isolate test sessions to test-sessions subdirectory 2026-06-30 13:23:21 +08:00
preview.go feat: add ocr scan for full-file code review (#93) 2026-06-24 22:07:25 +08:00
provider.go feat: add ocr scan for full-file code review (#93) 2026-06-24 22:07:25 +08:00
provider_test.go feat: add ocr scan for full-file code review (#93) 2026-06-24 22:07:25 +08:00