Repository navigation
fix(aireport): bound AI payload to stay under opencode token limit - #299
Conversation
The CompactForAI projection kept the three unbounded arrays (crap scores, quality reports, classify results) while stripping the bounded worst-offender lists the reporter actually reads. As the codebase grew, the compact payload reached 3.2MB (~1.05M tokens), exceeding opencode's 1M-token limit and failing the Go 1.24 CI "gaze report --ai=opencode" step. - Drop unbounded compact arrays (crap.scores, classify.results) - Bound quality reports to the 50 most actionable entries - Preserve worst_crap/worst_gaze_crap/recommended_actions and worst_coverage_tests - Project gaps/discarded/ambiguous to self-contained side effects - Add OpenSpec change and canonical payload-compaction spec Assisted-by: deepseek-v4-pro Generated with AI assistance (deepseek-v4-pro)
The TestCompactForAI_QualityReportsBounded test used a single-value type assertion on the left side of an assignment, which golangci-lint's errcheck linter flags. Extract the contract_coverage map into a typed local variable and mutate it directly, removing the unchecked assertion. Assisted-by: deepseek-v4-pro Generated with AI assistance (deepseek-v4-pro)
jflowers
left a comment
There was a problem hiding this comment.
PR Review: #299 — fix(aireport): bound AI payload to stay under opencode token limit
Summary
Well-executed fix that inverts the compaction strategy — drops the three unbounded arrays (crap.scores, quality.quality_reports, classify.results) causing the 3.2MB payload overflow, preserves every bounded worst-offender list the reporter reads (worst_crap, worst_gaze_crap, recommended_actions, worst_coverage_tests), and projects gaps/ambiguous/discarded to self-contained side-effect objects. Classify becomes counts-only. Comprehensive test coverage includes a realistic scale-budget test (2000 functions / 1500 pairs / 5000 effects).
CI Status
All 5 checks PASS (MegaLinter, Unit+Integration Go 1.24/1.25, E2E Go 1.24/1.25).
Alignment
No issues found. Scope matches the openspec proposal; delta and canonical specs are in sync; all fields the gaze-reporter prompt references are preserved; qualityReportCap = 50 is a named, documented constant.
Security
No issues found. Pure JSON transformation, no new dependencies, no external input handling.
Constitution Compliance
No issues found. Accuracy (no scoring change), Minimal Assumptions (codebase-size-independent budget), Actionable Output (worst-offender lists preserved), Testability (all projection functions unit-tested) all PASS.
Verdict
APPROVE
Note: Could not post as APPROVE due to GitHub's self-review restriction. Posted as COMMENT instead. Original verdict: APPROVE.
This review was generated by /uf.review-pr (AI-assisted).
Summary
The
gaze report --ai=opencodeCI step fails on Go 1.24 because the compact AI payload (3.2MB ≈ 1.05M tokens) exceeds opencode's 1M-token context window. The prior compaction kept three unbounded arrays (crap.scores,quality.quality_reports,classify.results) that scale with the whole codebase while stripping the bounded worst-offender lists the reporter actually reads. This change inverts that: drop the unbounded arrays, boundquality_reportsto the 50 most actionable entries, preserveworst_crap/worst_gaze_crap/recommended_actions/worst_coverage_tests, and project gaps/ambiguous/discarded to self-contained side-effect objects. Classify output becomes counts-only.How to Test
go build ./...go test -race -count=1 -short ./..../gaze report ./... --ai=opencode --coverprofile=coverage.outand confirm thePayload: N bytes (compact)stderr line is well under 300KBHow to Demo
Run the
Gaze quality reportstep (or the equivalentgaze report --ai=opencodecommand) against this repo. Before the fix it fails withprompt is too long: 1057347 tokens > 1000000 maximum; after the fix the compact payload stays under 300KB and the report renders successfully.Key Files Changed
internal/aireport/compact.go— invertedCompactForAIprojection (dropscores/results, boundquality_reports, preserve worst-offender lists, self-contained gap objects, counts-only classify)internal/aireport/compact_test.go— inverted/updated assertions, rescaled size-budget test (2000/1500/5000), new bounded-cap testinternal/aireport/payload.go— GoDoc comment onlyopenspec/changes/fix-payload-budget-overflow/— proposal, design, delta spec, tasks (spec-review + code-review passed)openspec/specs/payload-compaction/spec.md— canonical spec synced to new inverted stateThis PR was generated by /uf.finale (AI-assisted).