Skip to content

Improve runtime spine branch selection - #381

Merged
mohanagy merged 2 commits into
mainfrom
issue-377-runtime-spine
May 28, 2026
Merged

mohanagy merged 2 commits into
mainfrom
issue-377-runtime-spine

Conversation

@mohanagy

@mohanagy mohanagy commented May 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • make runtime-generation execution-slice ranking prompt-aware for failure/quality-gate branches
  • keep normal report-generation prompts on the success persistence spine while demoting failure handlers
  • extend the pack-quality fixture with a realistic quality-gate failure branch and prompt override regression coverage

Closes #377

Verification

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

Summary by CodeRabbit

  • New Features

    • Improved detection of failure-handling prompts to adjust execution priorities.
    • Added quality validation for generated reports and a fallback that captures/stores failures when validation fails.
  • Tests

    • Expanded test coverage for failure-handling and quality validation.
    • Test helpers now support overriding fixture inputs to run varied prompt/budget/task scenarios.

Review Change Stack

Closes #377

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

coderabbitai Bot commented May 28, 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: ef7827f8-10cf-4c2c-ba8c-1c39b7a960cb

📥 Commits

Reviewing files that changed from the base of the PR and between 7f0fbc0 and ff376d4.

📒 Files selected for processing (3)
  • src/runtime/retrieve.ts
  • tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/reports/quality-gate.service.ts
  • tests/unit/pack-quality-fixtures.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/reports/quality-gate.service.ts
  • src/runtime/retrieve.ts

📝 Walkthrough

Walkthrough

Detects failure-handling intent in prompts, classifies failure-related execution steps, adjusts execution-slice scoring to prefer or penalize those steps, adds a fixture quality-gate + failure-storage flow wired into the orchestrator, and updates tests to assert primary-path changes for normal vs failure-focused prompts.

Changes

Failure-handling intent-driven execution-slice prioritization

Layer / File(s) Summary
Intent detection for failure-handling queries
src/runtime/retrieve.ts
Introduces promptWantsFailureHandling() to detect failure/error/exception and quality-gate/fallback/dead-letter phrasing, and failureHandlingLikeExecutionStep() to classify steps via regex on labels/content.
Step priority scoring based on failure-handling intent
src/runtime/retrieve.ts
Adjusts executionSliceStepPriority to apply a large positive boost for failure-handling-like or quality-gate-like steps when the prompt requests failure handling, and a large negative penalty for failure-handling-like steps when it does not.
Quality-gate validation and failure-persistence flow in fixture
tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/reports/quality-gate.service.ts, tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/pipeline/workers/failure-storage.service.ts, tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/pipeline/workers/orchestrator.worker.ts
Adds validateIdeaReportQuality(report) and handleQualityGateFailure(ideaId, quality), a writeRawFailureReport(ideaId, reason) persistence helper, and integrates quality validation into OrchestratorWorker.process to route failed reports to failure handling before save.
Test fixture parameterization for prompt overrides
tests/unit/helpers/pack-quality.ts
Updates runPackQualityFixture to accept optional overrides for prompt, budget, and task, merges them into the runtime fixture, and returns the merged fixture in results.
Execution-slice assertions for normal and failure paths
tests/unit/pack-quality-fixtures.test.ts
Extends explain-pack payload typing to include pack.execution_slice.primary_path.steps, asserts normal-case primary path excludes handleQualityGateFailure() and includes saveStructuredReport(), and adds a test that re-runs the fixture with a failure-focused prompt to assert the primary-path now includes handleQualityGateFailure() and excludes saveStructuredReport().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • mohanagy/madar#271: Both PRs modify src/runtime/retrieve.ts to change prompt-aware execution-slice classification/scoring—especially around step prioritization/penalties—so the main PR’s failure-handling priority/penalty logic is directly tied to the retrieved PR’s execution-slice taxonomy and scoring updates.
  • mohanagy/madar#319: Main PR #318 is related to PR #319 because it extends the newly added runtime-generation-explain-report-flow explain fixture—specifically updating workspace/src/modules/pipeline/workers/orchestrator.worker.ts to validate a quality gate and route failures to handleQualityGateFailure, whereas PR #319 only introduced the base orchestrator flow without that quality-gate failure branch.
  • mohanagy/madar#252: Both PRs change src/runtime/retrieve.ts’s execution-slice inference/scoring logic based on question intent; the main PR adds failure-handling-driven priority/penalty via executionSliceStepPriority, while PR #252 revamps phase/primary-path/branch modeling and intent-based phase/path scoring.

Poem

🐰 I nibble traces of errors late at night,
I sniff intent and sort the noisy light.
When prompts ask "what fails?" I lead the way,
Else normal spines get front-row play.
Tiny paws write tests to make it 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 'Improve runtime spine branch selection' directly describes the main objective of the PR: making execution-slice ranking prompt-aware to improve selection of the normal execution spine over failure-handling branches.
Description check ✅ Passed The description covers the three key aspects (prompt-aware ranking, success spine prioritization, fixture extension), includes verification steps, and references the linked issue #377. It aligns well with the template sections.
Linked Issues check ✅ Passed The PR successfully implements all key coding requirements from issue #377: prompt-aware execution-slice ranking via promptWantsFailureHandling() helper, demotion of failure handlers unless explicitly requested, quality-gate validation integration, and fixture-backed regression testing with prompt override coverage.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #377 objectives: runtime-spine retrieval improvements, failure handler demotion logic, quality-gate integration, and fixture regression testing. No extraneous modifications detected.

✏️ 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-377-runtime-spine

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: 3

🤖 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/runtime/retrieve.ts`:
- Around line 2308-2314: In failureHandlingLikeExecutionStep, the first regex
omits the bare "fail"/"fails" variants; update the pattern used in that function
(the regex built from
node.label/node.source_file/node.node_kind/node.framework_role) to include the
"s" option like promptWantsFailureHandling (e.g., change
fail(?:ed|ure|ures|ing)? to fail(?:s|ed|ure|ures|ing)? or equivalent) so that
"fail" and "fails" are matched consistently with promptWantsFailureHandling;
ensure you keep the surrounding word-boundary logic and the rest of the function
(including the second regex) intact.

In
`@tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/reports/quality-gate.service.ts`:
- Around line 3-7: The function validateIdeaReportQuality currently always sets
reason to "empty report" even when passed is true; update
validateIdeaReportQuality to compute passed as report.content.length > 0 and
only populate the reason when passed is false (e.g., an empty string or
undefined when passed is true, and "empty report" when false) so callers only
receive a failure reason on failing checks.

In `@tests/unit/pack-quality-fixtures.test.ts`:
- Around line 131-136: The negative assertion currently checks both forbidden
labels together so it only fails if both are present; update the test that
inspects payload.pack?.execution_slice?.primary_path?.steps?.map((entry) =>
entry.label) to assert each forbidden label separately (e.g. assert the labels
array does not contain 'handleQualityGateFailure()' and separately does not
contain 'writeRawFailureReport()') so a regression adding either label will
fail; locate the expectation using not.toEqual(expect.arrayContaining([...]))
and replace it with two per-label negative checks against the mapped labels
array.
🪄 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: e8e61378-b94c-4b97-97d6-828e174a0dcd

📥 Commits

Reviewing files that changed from the base of the PR and between c78f07e and 7f0fbc0.

📒 Files selected for processing (6)
  • src/runtime/retrieve.ts
  • tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/pipeline/workers/failure-storage.service.ts
  • tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/pipeline/workers/orchestrator.worker.ts
  • tests/fixtures/pack-quality/runtime-generation-explain-report-flow/workspace/src/modules/reports/quality-gate.service.ts
  • tests/unit/helpers/pack-quality.ts
  • tests/unit/pack-quality-fixtures.test.ts

Comment thread src/runtime/retrieve.ts Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Actionable comments posted: 0

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.

P1: Improve runtime-generation workflow-spine retrieval so normal pipeline paths outrank noisy branches

1 participant