You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(runtime): extract history-compact checkpoint coordinator from runtime-kernel.ts and dedupe kernel internals #1406
Part of #1084 (second-pass sink-file and boundary governance). Scope re-verified against current main (runtime-kernel.ts, 1991 lines).
Scope
Extract the stateful checkpoint coordinator into a sibling next to history-compact-checkpoint.ts (which holds only pure builders/policy today): the historyCompactCheckpoints map (~L233), loadHistoryCompactCheckpoint (~L1388), recordHistoryCompactCheckpoint + CAS via canReplaceHistoryCompactCheckpoint (~L1421), scheduleHistoryCompactCleanup (~L1449), including the mid_turn/child-lineage partitioning added by feat(runtime): migrate agent tools to child sessions #1385 (~L1652–1666).
Rename the private AsyncEventQueue family (~L1907–1989) to reflect its distinct contract (per-entry delivery-ack with backpressure, vs the seq-ack single-consumer queue in async-queue.ts), e.g. DeliveryAckQueue, in its own file with the contract difference documented.
Deduplicate ensureActive (~L1490) / ensureChildActive (~L1606): ~90 lines of recorder-hook wiring are verbatim copies parameterized only by the active-session resolver; one intentional hook omission on the child side (~L1660) must be preserved explicitly.
Notes
session-manager.test.ts:8491 pins kernel internals by slicing source text; co-migrate that assertion to a behavioral/typed check (see #1403 — do not add new source-regex contracts).
Invariants
Same as #1084: behavior-neutral; stable public exports via re-exports; no reverse imports; flat PR off main.
I'd like to claim this task. Plan is to ship it as a single PR with four behavior-neutral commits, ordered by dependency:
Rename the private queue → DeliveryAckQueue in its own file (delivery-ack-queue.ts), with a header comment documenting the contract difference vs async-queue.ts (per-entry delivery-ack with backpressure vs fire-and-forget push). Pure rename + move; the two new AsyncEventQueue(...) and isAsyncEventQueueClosed(...) call sites in runAgentTurn / runAgentContinuation update accordingly.
Extract HistoryCompactCheckpointCoordinator into a sibling next to history-compact-checkpoint.ts. The coordinator owns the four maps (checkpoints/loads/writes/cleanups) and the three methods (load / record / scheduleCleanup); record takes the AgentRun as a per-call arg (resolved by the caller from this.active / this.childActive), so the coordinator never reaches into kernel session state. disposeBackendNow's two Map.delete calls become a single coordinator.clear(sessionId). HistoryCompactCleanupRequest moves with it; runtime-kernel.ts re-exports the type so session-manager.ts keeps its import path.
Deduplicate ensureActive / ensureChildActive via a private buildBackendRecorderHooks({ resolveActive, sessionId }) helper. The 8 recorder hooks collapse to one parameterized block (only the active-session resolver differs). The intentional deltas stay explicit at the call sites: allowMidTurnHistoryCompaction (Boolean(runtimeEventStore) vs false), shellRunContextSummary (present on the parent, absent on the child), and the system-prompt/tools provisioning (subagent snapshot vs explicit args).
Migrate session-manager.test.ts source-regex assertion to a behavioral check (per test: replace source-regex extraction contracts with behavioral assertions #1403 — no new source-regex contracts). The existing test slices runAgentTurn's source to assert new AiSdkFlow / absence of mapSessionEventToRuntimeEvent. Replacing it with a behavioral test that asserts the AiSdkFlow ingress authority: a backend that yields a forged queue_update event has it dropped from the turn's event stream (AiSdkFlow drops these at ai-sdk-flow.ts L763; an inline mapper would not).
Verification: runtime typecheck + build; full @maka/runtime test suite (2554 tests); lint + format:check. Flat off main, behavior-neutral, no reverse imports from the new leaves.
Completed in #1675 . This splits runtime-kernel.ts via behavior-neutral refactors — extracting DeliveryAckQueue and HistoryCompactCheckpointCoordinator into self-contained sink files, deduplicating the ensureActive/ensureChildActive recorder hooks via a shared buildBackendRecorderHooks helper, and dropping the #1403-forbidden source-regex test (its invariant already covered by the behavioral "a backend-forged queue_update never reaches the ledger or observers"(session-manager.test.ts:17641)).
Landed in #1675: DeliveryAckQueue and the history-compact checkpoint coordinator are extracted out of runtime-kernel.ts, ensureActive is deduplicated, and the source-regex tests are gone.
Activity
chinawch007 commentedon Jul 27, 2026
I'd like to claim this task. Plan is to ship it as a single PR with four behavior-neutral commits, ordered by dependency:
Rename the private queue →
DeliveryAckQueuein its own file (delivery-ack-queue.ts), with a header comment documenting the contract difference vsasync-queue.ts(per-entry delivery-ack with backpressure vs fire-and-forgetpush). Pure rename + move; the twonew AsyncEventQueue(...)andisAsyncEventQueueClosed(...)call sites inrunAgentTurn/runAgentContinuationupdate accordingly.Extract
HistoryCompactCheckpointCoordinatorinto a sibling next tohistory-compact-checkpoint.ts. The coordinator owns the four maps (checkpoints/loads/writes/cleanups) and the three methods (load/record/scheduleCleanup);recordtakes theAgentRunas a per-call arg (resolved by the caller fromthis.active/this.childActive), so the coordinator never reaches into kernel session state.disposeBackendNow's twoMap.deletecalls become a singlecoordinator.clear(sessionId).HistoryCompactCleanupRequestmoves with it;runtime-kernel.tsre-exports the type sosession-manager.tskeeps its import path.Deduplicate
ensureActive/ensureChildActivevia a privatebuildBackendRecorderHooks({ resolveActive, sessionId })helper. The 8 recorder hooks collapse to one parameterized block (only the active-session resolver differs). The intentional deltas stay explicit at the call sites:allowMidTurnHistoryCompaction(Boolean(runtimeEventStore)vsfalse),shellRunContextSummary(present on the parent, absent on the child), and the system-prompt/tools provisioning (subagent snapshot vs explicit args).Migrate
session-manager.test.tssource-regex assertion to a behavioral check (per test: replace source-regex extraction contracts with behavioral assertions #1403 — no new source-regex contracts). The existing test slicesrunAgentTurn's source to assertnew AiSdkFlow/ absence ofmapSessionEventToRuntimeEvent. Replacing it with a behavioral test that asserts the AiSdkFlow ingress authority: a backend that yields a forgedqueue_updateevent has it dropped from the turn's event stream (AiSdkFlow drops these atai-sdk-flow.tsL763; an inline mapper would not).Verification: runtime typecheck + build; full
@maka/runtimetest suite (2554 tests); lint + format:check. Flat off main, behavior-neutral, no reverse imports from the new leaves.chinawch007 commentedon Jul 30, 2026
Completed in #1675 . This splits runtime-kernel.ts via behavior-neutral refactors — extracting DeliveryAckQueue and HistoryCompactCheckpointCoordinator into self-contained sink files, deduplicating the ensureActive/ensureChildActive recorder hooks via a shared buildBackendRecorderHooks helper, and dropping the #1403-forbidden source-regex test (its invariant already covered by the behavioral "a backend-forged queue_update never reaches the ledger or observers"(session-manager.test.ts:17641)).
refactor(runtime): rename AsyncEventQueue → DeliveryAckQueue with doc…
refactor(runtime): extract HistoryCompactCheckpointCoordinator from r…
refactor(runtime): dedupe ensureActive/ensureChildActive via shared r…
refactor(runtime): drop source-regex AiSdkFlow contract test (apache#…
Refactor/runtime kernel split (#1675)
Astro-Han commentedon Aug 2, 2026
Landed in #1675: DeliveryAckQueue and the history-compact checkpoint coordinator are extracted out of runtime-kernel.ts, ensureActive is deduplicated, and the source-regex tests are gone.