Skip to content

Refactor runtime scenario execution into explicit stage modules#127

Open
danielbdyer wants to merge 1 commit into
mainfrom
codex/create-scenario-modules-for-runtime-stages
Open

Refactor runtime scenario execution into explicit stage modules#127
danielbdyer wants to merge 1 commit into
mainfrom
codex/create-scenario-modules-for-runtime-stages

Conversation

@danielbdyer
Copy link
Copy Markdown
Owner

Motivation

  • Improve separation of concerns in runtime scenario execution by splitting handshake, interpretation, route selection, step execution, recovery, and receipt-finalization into dedicated modules.
  • Make route-selection pure and deterministic to protect precedence behavior and make scoring easier to test.
  • Restrict ephemeral run-local mutation to a single coordinator to reduce surface area for side effects and make stage contracts explicit.

Description

  • Added lib/runtime/scenario/types.ts to define stage input/output contracts, stage envelopes, lane metadata, and a small ScenarioContextRef type using readonly records where applicable.
  • Extracted route-selection logic (normalization, variantStateMatchScore, routeVariantsForScreen, and selectRouteForNavigate) into lib/runtime/scenario/route-selection.ts as pure functions.
  • Implemented stage modules: handshake.ts, interpretation.ts, step-execution.ts, recovery.ts, and receipt-finalization.ts under lib/runtime/scenario/ and delegated implementation to them.
  • Kept a thin runScenarioStep coordinator in lib/runtime/scenario.ts which composes the stages in order, is the sole place mutating run-local ScenarioRunState, and preserves public exports (runScenarioStep, runScenarioHandshake, createScenarioRunState, stepHandshakeFromPlan).
  • Added stage-level tests tests/runtime-scenario-stages.spec.ts to lock deterministic route-choice and recovery transition ordering using fixed fixtures.

Testing

  • Ran npx playwright test tests/runtime-scenario-stages.spec.ts and the two stage-level tests passed.
  • Ran npm run types which failed due to existing type issues outside the refactor surface (e.g. lib/playwright/state-topology.ts).
  • Ran npx playwright test tests/runtime-agent-pipeline.spec.ts which surfaced 3 existing pipeline-level failures (precedence/fixture and DOM-mock shape issues) that are not introduced by this refactor.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant