Skip to content

Refactor/runtime kernel split - #1675

Merged
likun666661 merged 4 commits into
apache:mainfrom
chinawch007:refactor/runtime-kernel-split
Aug 1, 2026
Merged

likun666661 merged 4 commits into
apache:mainfrom
chinawch007:refactor/runtime-kernel-split

Conversation

@chinawch007

Copy link
Copy Markdown
Contributor

Summary

  • move the private AsyncEventQueue family out of the kernel into delivery-ack-queue.ts, renaming it to DeliveryAckQueue; document its backpressure contract (push(): Promise<void> awaits ack) against the fire-and-forget public async-queue.ts
  • extract checkpoint load / record / scheduleCleanup coordination (4 concurrency maps + 3 private methods) into a self-contained HistoryCompactCheckpointCoordinator that depends only on injected stores, never touching this.active / this.childActive; move HistoryCompactCleanupRequest with it and keep public imports stable via a type-only re-export, while session-manager.ts now imports the type directly from the coordinator
  • collapse the 8 structurally identical recorder hooks shared by ensureActive and ensureChildActive into a shared buildBackendRecorderHooks helper, parameterizing the only divergence (parent resolves from this.active, child from this.childActive) via a resolveActive callback; keep the intentionally divergent fields (allowMidTurnHistoryCompaction, shellRunContextSummary, system prompt/tools source) at their call sites
  • drop the session-manager.test.ts source-regex contract test (forbidden by test: replace source-regex extraction contracts with behavioral assertions #1403) that pinned runAgentTurn's structure by slicing source text; its invariant — a backend-forged queue_update is dropped at the AiSdkFlow ingress, never reaching observers or the ledger — is already covered more robustly by the behavioral test "a backend-forged queue_update never reaches the ledger or observers" (session-manager.test.ts:17641), which passes under AiSdkFlow and would crash the turn if the code regressed to the inline mapSessionEventToRuntimeEvent path

Refs #1406 .

Verification

  • npm run format:check
  • npm run lint
  • npm run typecheck
  • npm --workspace @maka/runtime run typecheck — passed
  • npm --workspace @maka/runtime test (2823 passed, 9 skipped)

@likun666661

Copy link
Copy Markdown
Member

Excellent work. This is a clean, carefully scoped refactor that materially improves the RuntimeKernel boundaries without changing behavior. Extracting DeliveryAckQueue and HistoryCompactCheckpointCoordinator, preserving the intentional parent/child differences in the shared recorder-hook builder, and relying on behavioral coverage instead of a brittle source-regex test are all exactly the right choices. This is important foundational work for the runtime—thank you for doing it so thoughtfully.

…1406)

Remove the test that pinned runAgentTurn's structure by slicing
runtime-kernel.ts source text and asserting on string matches
('new AiSdkFlow' present, 'mapSessionEventToRuntimeEvent'/
'createSessionEventMapMemory' absent). This is exactly the source-regex
contract pattern apache#1403 forbids.

The invariant it protected — a backend-forged queue_update is dropped at
the AiSdkFlow ingress, never reaching observers or the ledger — is
already covered more robustly by the behavioral test 'a backend-forged
queue_update never reaches the ledger or observers', which drives a real
forging backend through runAgentTurn and asserts on the observed event
stream and persisted ledger. The behavioral test is strictly stronger:
it fails on actual regressions (forged events leaking through) and does
not false-positive on an equivalent reimplementation.

Also drops the now-unused readFile import.
@likun666661
likun666661 force-pushed the refactor/runtime-kernel-split branch from b6a320a to f1aea8d Compare August 1, 2026 08:25
@likun666661
likun666661 merged commit f63a6ef into apache:main Aug 1, 2026
3 of 4 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.

2 participants