Repository navigation
[P2] serialized_budget.enforced is false on 0.27.4 explain packs; packs ship 2× over their declared budget - #402
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughImplements budget enforcement for explain-task context packs by adding a ChangesBudget-Enforced Answer-Ready Packs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/infrastructure/context-pack-command.ts (1)
561-659:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRun all
matched_nodes/relationshipstrimming through the diagnostics-aware culler.Lines 590-638 still hard-cap
matched_nodesandrelationshipsbefore Line 658 callsenforceAnswerReadyBudget(). Those removals bypass the workflow-anchor preservation logic and never surface inpack_culled_to_budget, so an anchor can be dropped silently before the ranking-based culler sees it.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/infrastructure/context-pack-command.ts` around lines 561 - 659, The code currently hard-caps pack.matched_nodes, pack.relationships and pack.community_context via trimArrayField (in buildAnswerReadyPackSchema) which bypasses the diagnostics-aware culler and can drop workflow anchors silently; remove those pack-specific trimArrayField calls and instead let the diagnostics-aware culler run (i.e., ensure these fields are culled by enforceAnswerReadyBudget with selectionDiagnostics) — either by not trimming pack.matched_nodes/relationships/community_context here or by invoking the culler that enforces answer-ready budget (enforceAnswerReadyBudget) on the payload/pack so that pack_culled_to_budget records these removals in trimmedFields and preserves anchors per selectionDiagnostics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/infrastructure/context-pack-command.ts`:
- Around line 425-481: The final path in enforceAnswerReadyBudget can leave
payload over-budget without marking the budget enforced or downgrading when the
remaining surface is the workflow spine; before the final
upsertPackCulledWarning/attachSerializedBudget call, add a detection for the
irreducible workflow-spine case (e.g. if estimatedJsonTokens(payload) >
maxTokens and the remaining pack represents only the workflow spine) and in that
branch call downgradeWorkflowSpineConfidence(payload, trimmedFields) and ensure
the serialized budget is marked enforced (set payload.serialized_budget.enforced
= true or make attachSerializedBudget record enforcement) so the `"budget too
tight for workflow spine"` downgrade and enforced flag are applied.
In `@src/runtime/stdio/tools.ts`:
- Around line 1366-1368: The explain-path currently uses plannerBudget (which is
clamped to >=3) when building the answer pack, violating caller's explicit
budget; change the call that builds the explain payload so it passes
resolvedBudget instead of plannerBudget (i.e., replace plannerBudget with
resolvedBudget in the buildAnswerReadyPackSchema call used to set
responsePayload when task === 'explain' && !includeSelectionDiagnostics) and
ensure any related reporting/logging for the serialized pack also references
resolvedBudget so enforcement and reporting use the caller's budget, not the
planner floor.
- Around line 171-174: The current check lets any array through for
followUp.focus_ranges which allows malformed entries to reach context_expand and
crash when accessing range.source_file; update the condition to not only ensure
followUp.focus_ranges is an array but also that every element matches the same
shape/validation used by isContextPackExpandableFollowUp (i.e. validate each
focus range object has the required properties like source_file and proper
line/offset types). Concretely, change the boolean expression to use
Array.isArray(followUp.focus_ranges) && followUp.focus_ranges.every(/* reuse or
call the element validator from isContextPackExpandableFollowUp or an equivalent
helper predicate */) so only well-formed focus range entries are accepted before
context_expand reads range.source_file.
In `@tests/unit/context-pack-command.test.ts`:
- Around line 826-833: The test currently only asserts that 'helper-low-2' was
dropped, which can pass even if other low-density nodes were also culled;
strengthen it by asserting that 'helper-low-1' is retained: add positive checks
using payload.pack?.matched_nodes (e.g., map to node_id) to include
'helper-low-1' and ensure payload.pack?.relationships (map to to_id/from_id as
appropriate) does not drop relations for 'helper-low-1', and update the
routing.warnings expectation (pack_culled_to_budget.detail.dropped_node_ids) to
specifically contain 'helper-low-2' but not 'helper-low-1' so the test verifies
lowest-density-first behavior while still checking the existing dropped-node
assertion.
---
Outside diff comments:
In `@src/infrastructure/context-pack-command.ts`:
- Around line 561-659: The code currently hard-caps pack.matched_nodes,
pack.relationships and pack.community_context via trimArrayField (in
buildAnswerReadyPackSchema) which bypasses the diagnostics-aware culler and can
drop workflow anchors silently; remove those pack-specific trimArrayField calls
and instead let the diagnostics-aware culler run (i.e., ensure these fields are
culled by enforceAnswerReadyBudget with selectionDiagnostics) — either by not
trimming pack.matched_nodes/relationships/community_context here or by invoking
the culler that enforces answer-ready budget (enforceAnswerReadyBudget) on the
payload/pack so that pack_culled_to_budget records these removals in
trimmedFields and preserves anchors per selectionDiagnostics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8654cb47-617b-4260-963f-91533917cff4
📒 Files selected for processing (9)
src/contracts/context-pack-diagnostics.tssrc/infrastructure/context-pack-command.tssrc/runtime/stdio/tools.tstests/unit/compare.test.tstests/unit/context-pack-command.test.tstests/unit/helpers/pack-quality.tstests/unit/pack-quality-fixtures.test.tstests/unit/stdio-server.test.tstests/unit/stdio-slice-surface.test.ts
| function enforceAnswerReadyBudget( | ||
| payload: JsonRecord, | ||
| maxTokens: number, | ||
| trimmedFields: string[], | ||
| diagnostics?: ContextPackSelectionDiagnostics, | ||
| ): void { | ||
| const summary: AnswerReadyCullSummary = { | ||
| droppedNodeIds: [], | ||
| droppedWorkflowSpine: false, | ||
| } | ||
| const pack = asJsonRecord(payload.pack) | ||
|
|
||
| if (stripExpandableFocusRanges(payload, trimmedFields)) { | ||
| attachSerializedBudget(payload, maxTokens, trimmedFields) | ||
| if (estimatedJsonTokens(payload) <= maxTokens) { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| if (!pack) { | ||
| attachSerializedBudget(payload, maxTokens, trimmedFields) | ||
| return | ||
| } | ||
|
|
||
| const candidates = buildAnswerReadyCullCandidates(payload, pack, diagnostics) | ||
| for (const candidate of candidates) { | ||
| upsertPackCulledWarning(payload, summary.droppedNodeIds) | ||
| if (summary.droppedWorkflowSpine) { | ||
| downgradeWorkflowSpineConfidence(payload, trimmedFields) | ||
| } | ||
| attachSerializedBudget(payload, maxTokens, trimmedFields) | ||
| if (estimatedJsonTokens(payload) <= maxTokens) { | ||
| return | ||
| } | ||
|
|
||
| const removed = removeMatchedNode(pack, candidate.key, trimmedFields) | ||
| if (!removed) { | ||
| continue | ||
| } | ||
| filterRelationshipsToRemainingNodes(pack, trimmedFields) | ||
| const removedId = typeof removed.node_id === 'string' | ||
| ? removed.node_id | ||
| : candidate.nodeId | ||
| if (removedId) { | ||
| summary.droppedNodeIds.push(removedId) | ||
| } | ||
| if (candidate.preserved) { | ||
| summary.droppedWorkflowSpine = true | ||
| } | ||
| } | ||
|
|
||
| upsertPackCulledWarning(payload, summary.droppedNodeIds) | ||
| if (summary.droppedWorkflowSpine) { | ||
| downgradeWorkflowSpineConfidence(payload, trimmedFields) | ||
| } | ||
| attachSerializedBudget(payload, maxTokens, trimmedFields) | ||
| } |
There was a problem hiding this comment.
Handle the irreducible workflow-spine case before the final budget report.
On Lines 476-480, if the payload is still over budget after stripping focus ranges and exhausting cull candidates, this path just reattaches serialized_budget. That leaves serialized_budget.enforced false and skips the "budget too tight for workflow spine" downgrade when the remaining surface is the workflow spine itself, which is the explicit fallback contract for this PR.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/infrastructure/context-pack-command.ts` around lines 425 - 481, The final
path in enforceAnswerReadyBudget can leave payload over-budget without marking
the budget enforced or downgrading when the remaining surface is the workflow
spine; before the final upsertPackCulledWarning/attachSerializedBudget call, add
a detection for the irreducible workflow-spine case (e.g. if
estimatedJsonTokens(payload) > maxTokens and the remaining pack represents only
the workflow spine) and in that branch call
downgradeWorkflowSpineConfidence(payload, trimmedFields) and ensure the
serialized budget is marked enforced (set payload.serialized_budget.enforced =
true or make attachSerializedBudget record enforcement) so the `"budget too
tight for workflow spine"` downgrade and enforced flag are applied.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolve the context-pack serializer conflict by keeping main's runtime primary-path preview preservation alongside the issue #400 answer-ready budget enforcement. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Closes #400
Summary
Verification
Summary by CodeRabbit
New Features
Bug Fixes
Tests