Skip to content

Add execution_slice phase and branch modeling - #252

Merged
mohanagy merged 3 commits into
mainfrom
issue-231-232-execution-slice
May 23, 2026
Merged

mohanagy merged 3 commits into
mainfrom
issue-231-232-execution-slice

Conversation

@mohanagy

@mohanagy mohanagy commented May 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #231

Summary

  • add runtime phase coverage and truthful partial/boundary reporting to execution_slice
  • distinguish the primary runtime path from bounded side-effect branches and terminal boundaries
  • extend retrieval tests for missing worker/persistence phases and primary-path selection

Testing

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

Implement truthful runtime phase coverage, partial status reporting, and primary-path versus side-effect modeling for execution_slice.

Closes #231
Closes #232

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

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7eef0e57-5001-4e29-a384-32b647702c01

📥 Commits

Reviewing files that changed from the base of the PR and between e523f38 and 43973cd.

📒 Files selected for processing (3)
  • src/runtime/retrieve.ts
  • tests/unit/context-pack-command.test.ts
  • tests/unit/retrieve-slice-v1.test.ts

📝 Walkthrough

Walkthrough

Adds phase-aware execution-slice contracts and runtime logic: classifies steps into phases, enumerates and scores candidate paths, selects a primary path, computes phase coverage with missing-phase reasons, classifies non-primary branches (side effects, terminal, omitted), and updates tests and compacting for new slice shape.

Changes

Execution Slicing with Phase Coverage

Layer / File(s) Summary
Execution-Slice Contract Types
src/contracts/context-pack.ts
New exported interfaces for ContextPackExecutionSliceBoundary, ContextPackExecutionSliceBranch, ContextPackExecutionSliceOmittedBranch, ContextPackExecutionSlicePrimaryPath, and ContextPackExecutionSlicePhaseCoverage; ContextPackExecutionSlice expands to include optional primary_path, side_effects, terminal_boundaries, omitted_branches, and phase_coverage fields.
Slice Retrieval Policy Configuration
src/runtime/retrieve/slicing.ts
effectivePolicy now applies broad runtime generation when broadRuntimeGeneration && pipelinePrompt (without hasMethodAnchor); merges base.forward_relations with RUNTIME_FLOW_RELATIONS, raises minimum forward_depth to 5, and removes runtime_flow_only to enable broader forward traversal.
Retrieve imports & prompt helpers
src/runtime/retrieve.ts
Adds execution-slice subtype imports and promptWantsControllerStep/promptWantsServiceStep helpers for question-intent inference.
Execution-Path Modeling Primitives
src/runtime/retrieve.ts
Introduces ExecutionPhase, ExecutionFlowEdge, and ExecutionPathCandidate types used for adjacency, enumeration, and scoring.
Phase Model and Execution-Path Selection Logic
src/runtime/retrieve.ts
Classifies steps into phases (controller/service/queue/worker/persistence), infers expected phases from prompt, builds adjacency over runtime-relevant edges, enumerates bounded paths, scores paths by phase evidence/ordering and intent cues, and derives missing-phase boundary reasons.
buildExecutionSlice & Compacting
src/runtime/retrieve.ts
Refactors buildExecutionSlice to select a primary path, compute phase_coverage, extract side_effects/terminal_boundaries/omitted_branches, and adds compacting helpers to shorten step representations for compact results; compactRetrieveResult applies compacting to result.execution_slice.
Context-Pack Command Test Updates
tests/unit/context-pack-command.test.ts
Runtime-generation fixture expanded with queue/worker/persistence nodes; test annotations and assertions updated to validate primary_path.boundaries (including enqueues_job) and phase_coverage.
Slice Retrieval Unit Tests
tests/unit/retrieve-slice-v1.test.ts
ExecutionSliceExpectation extended for primary-path, side-effects, terminal-boundaries, omitted-branches, and phase-coverage; fixture builder updated for worker/persistence options; tests strengthened to assert status, detailed boundaries, branch classifications, and partial/complete scenarios.
Realistic Integration Test with Compact Validation
tests/unit/spi-nest-di-runtime-calls-realistic.test.ts
New test validates retrieveContext execution-slice shape for a report prompt, asserting primary-path steps, enqueue→process boundary, side effects, terminal boundaries, phase coverage, omitted branches, and compacted size/token thresholds.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Poem

🐇 I stitched the map of phases fine,

from controller lanes to worker line;
Paths are scored and branches shown,
Boundaries marked, no step alone;
A rabbit's hop through code, divine.

🚥 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 summarizes the main change: adding phase and branch modeling to execution_slice structures.
Description check ✅ Passed The description covers the main objectives and includes testing commands, but is missing the docs update checkbox and related issues section from the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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-231-232-execution-slice

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 1666-1671: The current workerLikeExecutionStep too-broadly matches
"orchestrator" and bare "process"; update it to exclude "orchestrator" and only
treat "process" as worker-evidence when it has an attached qualifier (e.g.
process-*, process_*, process/*, etc.). Locate the workerLikeExecutionStep
function and replace the regex so it no longer includes "orchestrator" and
requires a suffix for "process" (for example:
/\b(?:worker|processor|process(?:[-_/]\w+))\b/), keeping the same lowercasing
behavior and return value.
- Around line 1701-1709: The function expectedExecutionPhases currently seeds
phases with ['controller','service'] which forces those phases to be required
for every question; change it to start with an empty phases array and only push
'controller' and/or 'service' when the question explicitly targets them (do this
by calling or adding small predicate helpers such as
promptWantsControllerStep(question) and promptWantsServiceStep(question) or
reusing existing heuristics), keep the existing checks that push
'queue'/'worker' via promptWantsRuntimePipeline(question) and 'persistence' via
promptExpectsPersistenceStep(question), and finally return the unique phases as
before.
- Around line 1878-1898: phaseCoverageForPath currently builds orderedObserved
by filtering only expected phases, dropping any extra observed phases; change
orderedObserved so it includes all observed phases (e.g., first keep expected
phases in order: expected.filter(p => observed.has(p)) then append any remaining
observed phases not in expected: Array.from(observed).filter(p =>
!expected.includes(p))), leaving the rest of the logic (expected, observed Set
construction, missing) intact; reference symbols: phaseCoverageForPath,
expected, observed (Set), orderedObserved, missing.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 831b59ca-4abe-42e3-8434-8cbcbc134d37

📥 Commits

Reviewing files that changed from the base of the PR and between 85cf642 and 0c078e5.

📒 Files selected for processing (6)
  • src/contracts/context-pack.ts
  • src/runtime/retrieve.ts
  • src/runtime/retrieve/slicing.ts
  • tests/unit/context-pack-command.test.ts
  • tests/unit/retrieve-slice-v1.test.ts
  • tests/unit/spi-nest-di-runtime-calls-realistic.test.ts

Comment thread src/runtime/retrieve.ts Resolved
Comment thread src/runtime/retrieve.ts Resolved
Comment thread src/runtime/retrieve.ts Resolved
Tighten worker detection, scope expected phases to the prompt, and report extra observed phases truthfully. Add focused regression tests and update the realistic runtime slice expectation to match the new truthful phase coverage.

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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/retrieve-slice-v1.test.ts (1)

109-114: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Keep worker edge source_file consistent with the workerSourceFile override.

Line 110 and Line 113 still hardcode '/src/auth/worker.ts', so overriding workerSourceFile only changes the node, not its outgoing edges. That can hide path-based classification regressions in this fixture.

Suggested fix
           ...(includePersistenceStep && includeWorkerStep
-            ? [{ source: 'auth_worker', target: 'session_store', relation: 'calls', confidence: 'EXTRACTED', source_file: '/src/auth/worker.ts' } as const]
+            ? [{ source: 'auth_worker', target: 'session_store', relation: 'calls', confidence: 'EXTRACTED', source_file: workerSourceFile } as const]
             : []),
           ...(includeWorkerStep
-            ? [{ source: 'auth_worker', target: 'session_notifier', relation: 'calls', confidence: 'EXTRACTED', source_file: '/src/auth/worker.ts' } as const]
+            ? [{ source: 'auth_worker', target: 'session_notifier', relation: 'calls', confidence: 'EXTRACTED', source_file: workerSourceFile } as const]
             : []),
🤖 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/retrieve-slice-v1.test.ts` around lines 109 - 114, The test
hardcodes the worker edge source_file string in the arrays created when
includePersistenceStep/includeWorkerStep are true, so the override variable
workerSourceFile isn't applied to outgoing edges; update the two edge objects
(the one targeting 'session_store' and the one targeting 'session_notifier'
created in the includePersistenceStep/includeWorkerStep spreads) to use the
workerSourceFile variable instead of the literal '/src/auth/worker.ts' so node
and edge source_file values stay consistent with the workerSourceFile override.
🤖 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 1253-1271: promptWantsControllerStep currently treats the token
"request(s)" as controller evidence unconditionally and promptWantsServiceStep
implicitly promotes any controller-detected prompt to a service, causing false
positives; change promptWantsControllerStep so "request" / "requests" are only
considered controller evidence when there is route/HTTP context (e.g.,
hasRoutePath, hasRouteKeyword or hasHttpVerbIntent) and remove the unconditional
early-return in promptWantsServiceStep (do not return true simply because
promptWantsControllerStep(question) is true); instead let promptWantsServiceStep
independently tokenize the question and check service-related tokens and the
regex for use-case/orchestrator so service detection stays independent of
controller hints.
- Around line 1922-1925: The observed phases list must be emitted in the
canonical runtime order: construct orderedObserved by iterating the canonical
order array (expected) and including any phase present in the observed Set
first, then append any remaining phases from the observed Set that are not in
expected while preserving their Set insertion order; update the logic around
orderedObserved (the variables expected and observed and where
phase_coverage.observed is produced) to use expected.filter(phase =>
observed.has(phase)) followed by [...observed].filter(phase =>
!expected.includes(phase)) so `queue` (and other expected phases) appear in
canonical runtime order.

---

Outside diff comments:
In `@tests/unit/retrieve-slice-v1.test.ts`:
- Around line 109-114: The test hardcodes the worker edge source_file string in
the arrays created when includePersistenceStep/includeWorkerStep are true, so
the override variable workerSourceFile isn't applied to outgoing edges; update
the two edge objects (the one targeting 'session_store' and the one targeting
'session_notifier' created in the includePersistenceStep/includeWorkerStep
spreads) to use the workerSourceFile variable instead of the literal
'/src/auth/worker.ts' so node and edge source_file values stay consistent with
the workerSourceFile override.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cf1f7adb-10e1-4b60-8e92-1ee0906fec8f

📥 Commits

Reviewing files that changed from the base of the PR and between 0c078e5 and e523f38.

📒 Files selected for processing (3)
  • src/runtime/retrieve.ts
  • tests/unit/retrieve-slice-v1.test.ts
  • tests/unit/spi-nest-di-runtime-calls-realistic.test.ts

Comment thread src/runtime/retrieve.ts Resolved
Comment thread src/runtime/retrieve.ts Resolved
Stop treating generic request wording as controller evidence, keep service detection independent of controller hints, and emit observed execution phases in canonical order. Update slice and command regressions to match the prompt-scoped phase coverage contract.

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

Development

Successfully merging this pull request may close these issues.

[P1] Add runtime phase coverage to execution_slice

1 participant