Skip to content

fix: surface runtime primary path nodes in answer-ready packs - #401

Merged
mohanagy merged 2 commits into
mainfrom
issue-399-slice-path-workflow-centers
May 28, 2026
Merged

mohanagy merged 2 commits into
mainfrom
issue-399-slice-path-workflow-centers

Conversation

@mohanagy

@mohanagy mohanagy commented May 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • promote runtime-generation explain slice nodes into slice-v1 candidates so primary-path steps survive pack assembly
  • treat expandable preview nodes as promoted in slice_path_nodes_not_promoted diagnostics
  • preserve trimmed runtime primary-path steps in answer-ready output via expandable previews and add regressions

Testing

  • npm run typecheck
  • npm run build
  • CI=1 npm run test:run

Closes #399

Summary by CodeRabbit

  • New Features

    • Enhanced context pack organization with improved runtime path preview node management
  • Bug Fixes

    • Improved diagnostic accuracy for detecting included information sources and nodes
    • Optimized candidate selection in explain flow for better relevance
  • Tests

    • Added coverage for preview node promotion and diagnostic validation

Review Change Stack

Closes #399

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@mohanagy, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 9 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 40d76204-ce9e-45f4-8d5b-9e6d3f391228

📥 Commits

Reviewing files that changed from the base of the PR and between b94e322 and 6141e5b.

📒 Files selected for processing (2)
  • src/infrastructure/context-pack-command.ts
  • tests/unit/pack-quality-fixtures.test.ts
📝 Walkthrough

Walkthrough

This PR implements end-to-end promotion of runtime primary-path nodes in explain-mode context packs. Retrieval discovers nodes via execution-slice scope, compaction preserves them as expandable previews with explain follow-ups, diagnostics recognizes expandable previews as valid promotion evidence, and tests validate the behavior across fixtures and diagnostic assertions.

Changes

Runtime primary-path promotion in explain mode

Layer / File(s) Summary
Runtime-explain candidate expansion in slice-v1 retrieval
src/runtime/retrieve.ts
Two new helpers gate runtime-explain promotion on sliceMetadata.mode === 'explain' combined with retrievalGate.intent === 'explain' and backend signals. When enabled, candidates are expanded by resolving anchor node ids (exact id first, then label fallback), collecting execution-slice scope, and appending newly discovered ids while preserving ordering. Integration inserts this expansion before debug augmentation.
Runtime primary-path preview preservation in pack compaction
src/infrastructure/context-pack-command.ts
Two new helpers derive runtime primary-path preview entries from execution_slice.primary_path.steps labels and matched_nodes, limiting previews to 3 items and attaching explain follow-ups. preserveTrimmedRuntimePrimaryPathPreview is called before trimming matched_nodes, and preserveFinalRuntimePrimaryPathPreview extends the logic for the final stage by excluding labels already in payload.expandable. Also promotes pack.expandable into payload.expandable when payload.expandable is empty.
Diagnostics updated to recognize expandable previews
src/runtime/context-pack-diagnostics.ts
slicePathTargetsNotPromoted now expands the "included" nodes/labels set from only pack.nodes to also include pack.expandable preview nodes by node_id and label, changing which targets are treated as omitted and eligible for the slice_path_nodes_not_promoted warning.
Test coverage validating promotion behavior
tests/unit/context-pack-diagnostics.test.ts, tests/unit/pack-quality-fixtures.test.ts
Adds test asserting slice_path_nodes_not_promoted does not fire when the runtime-path node is in expandable preview. Adds tests validating that all primary-path step labels surface either via matched_nodes or expandable.preview, and that workflow-center labels are not flagged as omitted in routing warnings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • mohanagy/madar#255: Determines when retrievalStrategy: 'slice-v1' and retrievalGate.intent === 'explain' are selected, directly controlling when this PR's runtime-explain candidate expansion logic in retrieve.ts is exercised.
  • mohanagy/madar#381: Modifies runtime-explain execution-slice behavior for failure-handling steps; this PR then promotes those runtime primary-path nodes into expandable, creating a direct coupling via the same retrieval pipeline.
  • mohanagy/madar#380: Introduces the compact "answer-ready" buildAnswerReadyPackSchema behavior; this PR extends it to preserve runtime primary-path previews via expandable and updates diagnostics to account for them.

Poem

🐰 A rabbit's ode to explain-mode clarity

When paths run deep and nodes align,
The retrieval dance finds them just in time.
Expandable previews glow with care,
No runtime answer left to spare.
Diagnostics smile, the warnings cease—
A pack promoted brings the peace. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: surfacing runtime primary path nodes in answer-ready packs by promoting them via expandable previews.
Description check ✅ Passed The description covers key changes, testing approach, and links to issue #399, though it could be more detailed about the specific implementation approach.
Linked Issues check ✅ Passed The PR addresses all primary coding requirements from issue #399: promoting runtime primary-path nodes into final packs via expandable previews, updating diagnostics to treat expandable nodes as promoted, and adding regression tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #399 objectives: context-pack-command.ts handles expandable preview promotion, retrieve.ts adds runtime explain candidate expansion, diagnostics.ts updates node inclusion logic, and tests verify the fixes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-399-slice-path-workflow-centers

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/unit/pack-quality-fixtures.test.ts (1)

202-210: ⚡ Quick win

Prevent a vacuous pass when primary path labels are empty.

On Line 202, this assertion always passes if primaryLabels is []. Add a guard that primaryLabels is non-empty so this regression test actually verifies promotion behavior.

Proposed test hardening
 const primaryLabels = (payload.pack?.execution_slice?.primary_path?.steps ?? [])
   .flatMap((entry) => (typeof entry.label === 'string' && entry.label.length > 0 ? [entry.label] : []))
+expect(primaryLabels.length).toBeGreaterThan(0)
 const surfacedLabels = new Set([
🤖 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 `@tests/unit/pack-quality-fixtures.test.ts` around lines 202 - 210, The test
currently allows a vacuous pass when primaryLabels is empty; add a guard
assertion before the existing equality check to ensure primaryLabels is
non-empty (e.g., assert primaryLabels.length > 0 using
expect(primaryLabels.length).toBeGreaterThan(0) or similar) so the comparison
between primaryLabels and surfacedLabels (the existing
expect([...surfacedLabels]).toEqual(expect.arrayContaining(primaryLabels)))
actually verifies promotion behavior; update the test around the primaryLabels
and surfacedLabels variables to include that non-empty check.
🤖 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 222-259: The preview selection currently deduplicates and
preserves nodes using only record.label (variables/functions: primaryLabels,
keptLabels, matchedByLabel, preview, asJsonRecord, matchedNodes,
ANSWER_READY_MATCHED_NODE_CAP), which drops distinct runtime-path steps that
share labels across files; change the identity to a composite key (e.g., label +
source_file + line_number or node_id when available) everywhere you build and
check keys: compute a stable compositeKey for each record after asJsonRecord,
use that compositeKey in keptLabels (Set) and matchedByLabel (Map) instead of
record.label, and update the preview filter to lookup by compositeKey and
include source_file/line_number in the preview. Apply the same composite-key
logic to the other matching block mentioned (lines ~298-344).

In `@tests/unit/pack-quality-fixtures.test.ts`:
- Around line 227-239: The test builds workflowCenters from
workflowCenterEntries by reading only entry.label which is often missing, making
the check vacuous; update the logic that builds the set (workflowCenters) to use
entry.path or node id (e.g., entry.path or entry.id) when label is absent and
compare against warning.detail?.ids (not detail?.labels), and add an assertion
that the workflowCenters set is non-empty before asserting its intersection with
omittedLabels/ids is empty; adjust references to workflowCenterEntries,
workflowCenters, omittedLabels and payload.pack.routing.warnings accordingly.

---

Nitpick comments:
In `@tests/unit/pack-quality-fixtures.test.ts`:
- Around line 202-210: The test currently allows a vacuous pass when
primaryLabels is empty; add a guard assertion before the existing equality check
to ensure primaryLabels is non-empty (e.g., assert primaryLabels.length > 0
using expect(primaryLabels.length).toBeGreaterThan(0) or similar) so the
comparison between primaryLabels and surfacedLabels (the existing
expect([...surfacedLabels]).toEqual(expect.arrayContaining(primaryLabels)))
actually verifies promotion behavior; update the test around the primaryLabels
and surfacedLabels variables to include that non-empty check.
🪄 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: f7d582c1-a4f8-4641-a93d-c493b910a47a

📥 Commits

Reviewing files that changed from the base of the PR and between b22a612 and b94e322.

📒 Files selected for processing (5)
  • src/infrastructure/context-pack-command.ts
  • src/runtime/context-pack-diagnostics.ts
  • src/runtime/retrieve.ts
  • tests/unit/context-pack-diagnostics.test.ts
  • tests/unit/pack-quality-fixtures.test.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mohanagy
mohanagy merged commit 2851613 into main May 28, 2026
7 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

1 participant