Skip to content

fix: preflight compact v3 context before model calls#1297

Merged
clark-cant merged 1 commit into
nextlevelbuilder:devfrom
nguyenha935:fix/v3-context-budget-calibration
Jun 28, 2026
Merged

fix: preflight compact v3 context before model calls#1297
clark-cant merged 1 commit into
nextlevelbuilder:devfrom
nguyenha935:fix/v3-context-budget-calibration

Conversation

@nguyenha935

Copy link
Copy Markdown
Contributor

Summary

  • Run V3 pruning/compaction before ThinkStage so over-budget histories are compacted before provider calls.
  • Persist V3 last_prompt_tokens with the post-flush persisted message count, matching V2 calibration behavior.
  • Add regression coverage for preflight compaction and V3 metadata message count.

Tests

  • go test ./internal/pipeline -run "TestNewDefaultPipeline_PrunesBeforeThink|TestFinalizeStage_UpdateMetadataReceivesPersistedMessageCount" -count=1
  • go test ./internal/agent -run "^$" -count=1

Surface parity

  • Gateway runtime: affected, V3 pipeline order and metadata callback updated.
  • API contract: N/A, no request/response schema changes.
  • Web UI: N/A, no UI behavior or strings changed.
  • CLI/runtime package: N/A, no CLI flags or runtime packaging interfaces changed.

Run pruning before ThinkStage so oversized histories compact before the provider request is built.

Persist V3 last_prompt_tokens with the post-flush persisted message count so post-run compaction calibration has current usage data.

Tests: go test ./internal/pipeline -run "TestNewDefaultPipeline_PrunesBeforeThink|TestFinalizeStage_UpdateMetadataReceivesPersistedMessageCount" -count=1; go test ./internal/agent -run "^$" -count=1

@clark-cant clark-cant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Clean, focused fix. Pipeline reorder (Prune before Think) is correct — over-budget histories should be compacted before provider calls. UpdateMetadata msgCount addition matches V2 calibration behavior. Good regression coverage.

Verdict: Approve

  • Duplicate/prior work: clear — no prior implementation of preflight V3 compaction
  • Project standards: compliant
  • Strategic necessity: clear value — fixes context budget calibration for V3 pipeline
  • Risk: Low — 6 files, +123/-8, well-tested

Posted by github-maintain at $(date -u +%Y-%m-%dT%H:%M:%SZ)

@clark-cant clark-cant merged commit 64596bf into nextlevelbuilder:dev Jun 28, 2026
3 checks passed
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.

2 participants