Skip to content

fix(aireport): bound AI payload to stay under opencode token limit - #299

Merged
jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:opsx/fix-payload-budget-overflow
Oct 2, 2026
Merged

jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:opsx/fix-payload-budget-overflow

Conversation

@jflowers

@jflowers jflowers commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

The gaze report --ai=opencode CI 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, bound quality_reports to the 50 most actionable entries, preserve worst_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 ./...
  • Manual: run ./gaze report ./... --ai=opencode --coverprofile=coverage.out and confirm the Payload: N bytes (compact) stderr line is well under 300KB

How to Demo

Run the Gaze quality report step (or the equivalent gaze report --ai=opencode command) against this repo. Before the fix it fails with prompt 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 — inverted CompactForAI projection (drop scores/results, bound quality_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 test
  • internal/aireport/payload.go — GoDoc comment only
  • openspec/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 state

This PR was generated by /uf.finale (AI-assisted).

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 jflowers left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@jflowers
jflowers merged commit f287c19 into unbound-force:main Oct 2, 2026
5 of 6 checks passed
@jflowers
jflowers deleted the opsx/fix-payload-budget-overflow branch November 15, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant