Skip to content

fix: restore explain pack guidance compatibility - #351

Merged
mohanagy merged 2 commits into
nextfrom
issue-350-pack-regression
May 27, 2026
Merged

mohanagy merged 2 commits into
nextfrom
issue-350-pack-regression

Conversation

@mohanagy

@mohanagy mohanagy commented May 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • restore nested explain-pack guidance fields inside pack for runtime consumers that still read that shape
  • reuse the same explain payload core in madar pack and madar compare so they stay aligned
  • add regression coverage for the runtime-generation explain fixture

Closes #350

Summary by CodeRabbit

  • Chores
    • Improved explain-task payload generation to include guidance compatibility fields (workflow centers, recommended first read, confidence score) and adjusted internal packing to keep non-explain outputs unchanged.
  • Tests
    • Updated unit fixtures and schema tests to validate the new guidance fields, their values, and their expected placement in emitted payloads.

Review Change Stack

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

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6b250bed-508d-4327-a313-f875ddec2449

📥 Commits

Reviewing files that changed from the base of the PR and between 06c207d and e4fc845.

📒 Files selected for processing (3)
  • src/infrastructure/context-pack-command.ts
  • tests/unit/context-pack-command.test.ts
  • tests/unit/pack-quality-fixtures.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unit/pack-quality-fixtures.test.ts
  • src/infrastructure/context-pack-command.ts

📝 Walkthrough

Walkthrough

This PR fixes a regression where explain pack outputs stopped populating confidence_score, recommended_first_read, and workflow_centers. It introduces buildExplainPackPayloadCore, widens the pack type to allow compatibility fields, updates schema construction to conditionally embed those fields for explain tasks, updates call sites to use the new builder, and adjusts tests/fixtures accordingly.

Changes

Guidance fields regression fix

Layer / File(s) Summary
Type and schema updates for guidance fields
src/infrastructure/context-pack-command.ts
ExplainPackPayload.pack is widened to include optional PackGuidanceCompatibilityFields (workflow_centers, recommended_first_read, confidence_score). Helper functions packWithCompatibilityFields and packForSchema are added to conditionally merge these fields into the pack only for task === 'explain'.
Core explain payload builder
src/infrastructure/context-pack-command.ts
New exported function buildExplainPackPayloadCore derives an explain task context plan from retrieval inputs, computes workflow centers and recommended first-read guidance, calculates a confidence score, and returns an ExplainPackPayload with the retrieval pack augmented with compatibility fields.
Pack schema integration
src/infrastructure/context-pack-command.ts
buildPackSchemaV1 is updated to compute guidance compatibility fields and set the resulting schema's pack via packForSchema(...), enabling explain-specific pack augmentation without changing other tasks.
Dispatch point updates
src/infrastructure/compare.ts, src/infrastructure/context-pack-command.ts
Import and call sites are switched from buildExplainPackPayload to buildExplainPackPayloadCore in compare.ts and runContextPackCommand to use the new core builder for explain task output generation.
Test fixture and assertions for guidance fields
tests/unit/pack-quality-fixtures.test.ts, tests/unit/context-pack-command.test.ts
The runtime-generation-explain-report-flow fixture's payload type is extended to include optional confidence_score, workflow_centers, and recommended_first_read both at the top level and nested in pack. New assertions verify confidence_score is a number in [0,1], that nested pack values match top-level fields for explain fixtures, and that implement-pack schema tests assert these fields are not duplicated under payload.pack.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • mohanagy/madar#302: Touches context-pack-command.ts pack schema output construction; related at the pack/schema layer.
  • mohanagy/madar#279: Related changes to explain/implement payload building and wiring in the same module.
  • mohanagy/madar#319: Updates explain-pack tests/fixtures and validation for workflow/first-read fields; closely related to the test changes here.

Poem

🐰 The fields went missing, a pack felt thin,
I hopped to the core and stitched them in,
Confidence, centers, and first-read light,
Restored in the pack to guide the night,
Hop, code, and cheer — the output's right!

🚥 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 clearly and concisely summarizes the main change: restoring explain pack guidance compatibility fields.
Description check ✅ Passed The description covers the main objectives, clearly explains what was changed and why, but lacks specific testing commands and does not include all checklist items.
Linked Issues check ✅ Passed The PR successfully restores the three missing pack fields (confidence_score, recommended_first_read, workflow_centers) and adds regression test coverage, directly addressing all acceptance criteria from issue #350.
Out of Scope Changes check ✅ Passed All changes are focused on restoring the missing guidance fields and ensuring consistency between madar pack and madar compare, with no extraneous modifications.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-350-pack-regression

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

🤖 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 1088-1091: The call to buildExplainPackPayloadCore(...) is added
unconditionally into the object passed to buildPackSchemaV1, causing non-explain
tasks to receive explain-only fields; change the object construction in
renderContextPackOutput / buildPackSchemaV1 call so that you only spread
...buildExplainPackPayloadCore(...) when resolvedTask.task_kind indicates an
explain request (e.g., resolvedTask.task_kind === 'explain'), otherwise omit
that spread (use a conditional spread or build via packForSchema to gate
explain-specific fields); keep the rest of the properties (baseResponse(...),
dependencies.compactRetrieveResult(retrieval), retrieval, implementation)
untouched.

In `@tests/unit/pack-quality-fixtures.test.ts`:
- Around line 103-107: The test currently only compares
payload.pack?.confidence_score with payload.confidence_score which can both be
undefined and hide regressions; update the assertions to explicitly assert the
top-level and nested confidence_score are present and in the expected numeric
range (e.g., defined, not null, and between 0 and 1 or whatever domain your app
expects) before comparing them—locate the assertions referencing
payload.pack?.confidence_score and payload.confidence_score and add explicit
existence and range checks (e.g., expect(...).toBeDefined()/not.toBeNull() and
expect(...).toBeGreaterThanOrEqual(...)/toBeLessThanOrEqual(...)) prior to the
equality assertion.
🪄 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: 96ac42ae-1af3-4e8b-94bc-499e68f3f1ed

📥 Commits

Reviewing files that changed from the base of the PR and between e7b46ab and 06c207d.

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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