Skip to content

refactor(runtime): collapse runner shell into kernel - #3718

Merged
Astro-Han merged 1 commit into
mainfrom
refactor/collapse-runtime-runner
Aug 24, 2026
Merged

Astro-Han merged 1 commit into
mainfrom
refactor/collapse-runtime-runner

Conversation

@likun666661

Copy link
Copy Markdown
Member

Summary

  • Remove the RuntimeRunner, AgentFlow, and InvocationContext shell so RuntimeKernel directly owns backend dispatch, stop/drain, terminal coalescing, and missing-terminal convergence.
  • Keep SessionEvent to RuntimeEvent conversion as a pure mapper and move initial user-event construction into AgentRun.
  • Preserve durable continuation admission, replay validation, no-duplicate-user semantics, and the existing Runtime ledger invariants while reducing the maintained call graph.

Refs #3618

Verification

  • npm run build
  • npm run typecheck
  • npm run lint
  • npm run format:check
  • Focused Runtime mapper, SessionManager, terminal-ledger, continuation, and SIGKILL crash coverage: 314 passed
  • Follow-up SessionManager and continuation regression run: 239 passed
  • Full @maka/runtime suite: 2,948 passed and 13 skipped; one unrelated existing macOS sandbox executable-root assertion failed in builtin-tools.test.ts

Review focus

This intentionally removes public Runtime subpaths for the retired Invocation/Flow shell. Please focus on direct RuntimeKernel stream ownership and the continuation proof-consumption boundary.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex traced the Runtime ownership graph, implemented the collapse, migrated tests and documentation, and ran verification. The commit includes the required Generated-by trailer.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

The change is a behavior-preserving ownership refactor, so its regression tests protect the existing invariants rather than intentionally failing against the previous shell structure.

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@xxhZs xxhZs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The direct-dispatch path drops the request-snapshot boundary that RuntimeRunner previously enforced.

AgentRun.begin() places the original mutable attachments and quotes arrays into both backendInput and the initial user RuntimeEvent. RuntimeKernel then forwards that input alongside the same event as headAnchorRuntimeEvent. Because these values are aliased, mutating the retained caller input or BackendSendInput after the user event is committed can also change the live provider input or in-memory head anchor, leaving them inconsistent with the durable ledger. This is particularly risky when mid-turn compaction relies on the head anchor as the persisted coverage boundary.

Please clone/freeze the mutable request content and head anchor before backend dispatch, preserving separate immutable snapshots, and add a regression test that mutates the original arrays/backend input while asserting that the stored user event, head anchor, and provider input remain stable.

Separately, this PR currently conflicts with main; please rebase and rerun the suite with the repository's declared Node 24.18.1 toolchain after addressing the snapshot regression.

@likun666661
likun666661 force-pushed the refactor/collapse-runtime-runner branch from 39cae10 to 46bed45 Compare August 24, 2026 14:47
@likun666661

Copy link
Copy Markdown
Member Author

Addressed the requested changes in 46bed45:

  • Rebased onto current main; the PR is now mergeable.
  • Restored clone/freeze ownership boundaries when AgentRun accepts turn input and at the unified backend dispatch path, covering normal turns and continuations.
  • Kept the stored user fact, provider payload, and head anchor as separate immutable snapshots.
  • Added a regression test that mutates the caller-owned attachments/quotes/inline references after the durable user-event append, then attempts backend-side mutation and verifies the stored event, provider input, and head anchor remain stable.

Verification used Node 24.18.1 and npm 11.19.0: runtime suite 3046 tests / 3033 passed / 13 skipped / 0 failed; full repository build and typecheck passed; lint, format check, ASF header check, and git diff check passed.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@Astro-Han
Astro-Han merged commit 3a9824a into main Aug 24, 2026
2 of 3 checks passed
@Astro-Han
Astro-Han deleted the refactor/collapse-runtime-runner branch August 24, 2026 19:02
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.

3 participants