open-code-review/internal
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 refactor(agent,scan): share one 80% token threshold (#421) 2026-07-21 16:57:28 +08:00
config feat: add pot code review rules (#406) 2026-07-20 16:09:08 +08:00
delegate feat(delegate): add delegation mode for host-agent driven code review (#383) 2026-07-16 13:10:54 +08:00
diff fix(diff): add --end-of-options guard and no-commit regression test for workspace diff (#376) 2026-07-17 20:29:51 +08:00
gitcmd test: expand unit test coverage for agent, llm, llmloop, and tool packages 2026-06-26 23:09:11 +08:00
llm fix(llmloop): guard nil tool-call arguments map to prevent panic (#393) 2026-07-21 13:24:50 +08:00
llmloop refactor(agent,scan): share one 80% token threshold (#421) 2026-07-21 16:57:28 +08:00
mcp test: fix golangci-lint errcheck/staticcheck issues in test code (#323) 2026-07-08 22:46:18 +08:00
model test: fix golangci-lint errcheck/staticcheck issues in test code (#323) 2026-07-08 22:46:18 +08:00
pathutil test: fix golangci-lint errcheck/staticcheck issues in test code (#323) 2026-07-08 22:46:18 +08:00
release fix(build): improve Windows support based on PR #13 review feedback 2026-06-02 22:37:27 +08:00
scan refactor(agent,scan): share one 80% token threshold (#421) 2026-07-21 16:57:28 +08:00
session feat(review): add resumable sessions and session inspection (#306) 2026-07-09 11:43:11 +08:00
stdout test: add unit tests for output_helpers, config, model, stdout, and telemetry packages 2026-06-26 23:26:49 +08:00
suggestdiff test: add unit tests for pure logic functions across 6 packages 2026-06-26 22:41:35 +08:00
telemetry docs(telemetry): explain why checkMetricErr intentionally ignores errors (#418) 2026-07-21 16:08:44 +08:00
tool fix(tool): reject traversal pathspecs in code_search (#303) 2026-07-09 13:45:24 +08:00
viewer fix: remove redundant font-family from .response-text .inline-code (#339) 2026-07-14 10:20:19 +08:00