Skip to content

refactor(runtime): remove legacy child AgentRun control - #4173

Merged
Astro-Han merged 1 commit into
apache:mainfrom
Astro-Han:refactor/runtime-remove-child-agentrun-control
Aug 29, 2026
Merged

refactor(runtime): remove legacy child AgentRun control#4173
Astro-Han merged 1 commit into
apache:mainfrom
Astro-Han:refactor/runtime-remove-child-agentrun-control

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Remove the retired same-session child AgentRun execution, resume, and retry control chain now that agent_spawn creates durable linked child Sessions.

This deletes the unused capability plumbing from Core inputs through ToolRuntime, AiSdkBackend, Runtime Host composition, SessionManager, and RuntimeKernel. It also removes the child-only backend-generation, provider replay, and transcript-suppression branches that were reachable only from that chain. Live turns no longer accept child AgentRun lineage, including from untyped or older JavaScript callers.

Historical compatibility remains read-only: persisted legacy AgentRun/RuntimeEvent data is unchanged, agent_list and agent_output still project legacy run ids, and linked child Sessions plus Agent Graph execution keep their existing session-inline authority. Safe-boundary continuation retains its separate runtime-owned lineage.

Net change: 1,669 insertions and 6,462 deletions (4,793 lines removed).

Verification

  • RED to GREEN: live parentRunId, resumedFromRunId, and retriedFromRunId inputs are rejected before an AgentRun is written
  • npm run format:check
  • npx biome lint on all changed files
  • npm --workspace @maka/core run typecheck
  • npm --workspace @maka/runtime run typecheck
  • npm --workspace @maka/runtime-host run typecheck
  • Runtime focused suites: SessionManager, subagent tools, admission limiter, and runtime ledger repair (216 passed)
  • Independent adversarial reviews covered architecture/reachability, persistence/upgrade compatibility, lifecycle/concurrency/recovery, and test gaps; the revised head has no remaining P0-P3 findings
  • git merge-tree --write-tree HEAD origin/pr/4158 completed without conflicts after rebasing onto current main

Review focus

Please verify that the deletion stops at the ownership boundary: linked child Session and Agent Graph writes remain live, safe-boundary continuation remains isolated, while legacy same-session child AgentRuns remain readable but have no execution/control entry point.

AI use

Select exactly one:

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

Tool(s) and scope: Codex implemented the removal, adapted the safety-net tests, and performed internal adversarial reviews. A human contributor must review the final diff and owns the merge decision.

Checklist

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

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@github-actions github-actions Bot added the effort/XL Over 1000 readable lines label Aug 29, 2026
@Astro-Han
Astro-Han force-pushed the refactor/runtime-remove-child-agentrun-control branch 2 times, most recently from 4ebdf3a to cebbeff Compare August 29, 2026 12:28
@Astro-Han
Astro-Han marked this pull request as ready for review August 29, 2026 12:56
@Astro-Han

Copy link
Copy Markdown
Contributor Author

This is a synthesis of the independent blind review by @Sol-404ARE at exact head cebbeff14d3516f59951aaddf7b6b3076643daec (base 104d5fc4c3197ab04968947bd1b17bebd3b40b88, 19 files +1655/-6444). I verified the drift and the exact-head CI myself; the file:line findings below are from Sol's sealed blind review.

What I checked myself:

  • Read the single commit cebbeff1 (refactor(runtime): remove legacy child AgentRun control, Generated-by: Codex) diff metadata and confirmed the vertical deletion scope (19 files, -6444 lines) and the historical vs live lineage separation.
  • Checked exact-head CI: test SUCCESS (33252607939), windows_recovery SUCCESS (33252607865), label SUCCESS (33253751670), OPEN/non-draft/MERGEABLE/BLOCKED/REVIEW_REQUIRED.

Findings from Sol's sealed review:

Standards — NO-GO — 1×P2 (worst P2)

  • [P2] docs/architecture/runtime-resume-extraction-ledger.zh-CN.md:372-385 still documents the deleted provider-retry path as current. It states that hosted child provider RateLimit retry remains available through durable continuation. The implementation and the concurrently updated Phase 3–4 current contract at runtime-resume-phase3-phase4-workspace-checkpoint-design.zh-CN.md:373-384 state that the entry point is deleted and that historical descriptors only terminalize during recovery without calling the provider. docs/README.md:27,55-56 classifies both documents as current contracts. Update or archive the stale production-scope bullets in the extraction ledger document so the two current contracts no longer contradict. Governance otherwise passes: current template, conventional title/branch, Codex disclosure with Generated-by: Codex, specific verification, and expected checks green. No Fowler smell — the 19-file deletion is cohesive and retained legacy descriptor/lineage shells are exercised compatibility paths.

Spec — NO-GO — 1×P2 (worst P2)

  • [P2] recoverAgentRunsFromLedger() (packages/runtime/src/session-manager.ts:4661-4665,4698-4707) still mutates legacy child ledgers that are promised read-only during startup recovery. Minimal repro: seed a non-archived Session with a legacy child header { parentRunId: 'parent', agentId: 'agent', status: 'running' } whose operational ledger ends at run_started, then call recoverInterruptedSessions(). classifyAgentRunRecovery() maps it to failed app_restarted (agent-run-recovery.ts:87-102); applyAgentRunRecovery() commits the terminal RuntimeEvent/header/run_failed event (session-manager.ts:4821-4851, terminal-run-commit.ts:123-168). The later isSessionInlineRun check only gates TurnState projection and is too late to protect AgentRun/RuntimeEvent immutability. The new live-lineage test at session-manager.test.ts:164-193 only proves that rejected new input creates no Run; no oracle exists proving that an upgrade-seeded legacy running child Run is left untouched. Guard the recovery loop to skip non-inline legacy child Runs (or prove immutability with an upgrade-seeded oracle) to preserve the historically readable agent_list/agent_output contract. The previously considered linked-child history/output P1 is withdrawn — base linked resume writes resumedFromRunId+agent identity without parentRunId and explicitly omits parentRunId for linkedSnapshot, so those historical linked runs remain inline via parentRunId === undefined and stay correctly readable; no scope creep and live-lineage rejection otherwise remains correctly ordered.

Verification: git diff --check PASS, targeted Biome check+format for 17 changed TS files PASS, ASF header audit PASS (3107 covered/166 exclusions), clean worktree, head/base unchanged.

What I did not judge: detached worktree direct source suites were not executed (no node_modules, no install/symlink).

Gate: Standards 1×P2 + Spec 1×P2 remain; despite terminal CI green, head cebbeff1 is not merge-ready until the stale contract and the recovery immutability guard are addressed. Seal: notes/pr-4173-provisional.md.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at exact head cebbeff14d3516f59951aaddf7b6b3076643daec with one non-blocking P2 documentation comment. The runtime refactor is internally consistent: live legacy child lineage is rejected before any Run or message write, linked child Sessions and Agent Graph execution retain their own authority, safe-boundary continuation uses its separate internal lineage, and the historical list/output projection remains readable. This is a genuine simplification: it removes the same-Session child execution authority and its control, replay, progress, and transcript-suppression paths without adding a replacement layer.

I did not retain the proposed recovery-immutability concern as a finding. Startup terminalization of interrupted legacy child Runs predates this PR, the updated Phase 3–4 contract explicitly preserves it as restart-close compatibility, and isSessionInlineRun continues to prevent those legacy Runs from writing TurnState.

All three exact-head hosted checks are successful. Local verification passed the complete build and typecheck, 279 affected tests, the complete Runtime suite (3,043 passed), the complete Runtime Host suite (1,355 passed), lint, format, stale checks, and git diff --check. Current main is still the reviewed base, and the synthetic merge tree is byte-identical to the reviewed head.


Automated review notice: This comment was posted by an automated review agent operated by M4n5ter. It is not an independent human review and does not replace one.

Comment thread docs/architecture/runtime-resume-extraction-ledger.zh-CN.md

@ARE404 ARE404 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.

Approving refactor(runtime): remove legacy child AgentRun control at head cebbeff1.

I reviewed the 19 changed files and verified the removal of the legacy child AgentRun control surface is reachable-clean:

  • prior-run-context.ts is trimmed, not deletedagent-run.ts and runtime-ledger-repair.test.ts still import the retained buildPriorRuntimeContext/PriorRuntimeContext, so those references stay valid.
  • The removed legacy surface in session-manager.ts, runtime-kernel.ts, agent-run.ts, tool-runtime.ts, child-agent-progress.ts, ai-sdk-backend.ts, and prior-run-context.ts is not referenced by any retained producer or consumer at this head (grep across packages/scripts).
  • test is green on this exact head (run 33252607939, 11m14s).

No P0–P2 in the code. One open documentation thread (runtime-resume-extraction-ledger.zh-CN.md) should still be reconciled by the author for cross-document consistency, but it is non-blocking for this refactor.

简体中文

批准 refactor(runtime): remove legacy child AgentRun control,head cebbeff1
审查 19 个改动文件,确认删除 legacy child AgentRun 控制面是可达性干净的:prior-run-context.ts精简而非删除——agent-run.tsruntime-ledger-repair.test.ts 仍 import 保留的 buildPriorRuntimeContext/PriorRuntimeContext,这些引用有效。session-manager.ts/runtime-kernel.ts/agent-run.ts/tool-runtime.ts/child-agent-progress.ts/ai-sdk-backend.ts/prior-run-context.ts 中被删的旧面在本 head 无任何保留生产者/消费者引用(packages/scripts 全仓 grep)。test 在 exact head 绿(run 33252607939,11m14s)。代码无 P0–P2。一条开放文档线程(runtime-resume-extraction-ledger.zh-CN.md)建议作者另行统一文档间一致性,但对本次重构不构成阻塞。

@jackwener jackwener left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I reviewed this at cebbeff14d3516f59951aaddf7b6b3076643daec. No P0 or P1. One P3, inline on the extraction ledger.

P3. The table in docs/architecture/runtime-resume-extraction-ledger.zh-CN.md now says historical linked-child admissions are restart-close only. Later in the same file, the production-scope bullets still describe hosted child RateLimit retry as a live durable_continuation admission. This PR deletes resumeChildAgent / retryChildAgent, and the Phase 3–4 contract now says that entry is gone. Code wins if the two documents disagree, so this is not a merge blocker.

What I checked

  • Live sendMessage / startTurn reject parentRunId, resumedFromRunId, and retriedFromRunId before an AgentRun is written, including leftover fields on an untyped input object. The new test shows no Run is stored after that reject.
  • Linked agent_spawn still creates a child Session whose first AgentRun has no parentRunId and is session-inline. Follow-up turns on that Session are ordinary sendMessage.
  • Same-session child spawn / resume / retry is gone from SessionManager, ToolRuntime, AiSdkBackend, RuntimeKernel, and Host composition. I found no remaining production callers.
  • agent_list and agent_output still project persisted legacy child runs. Safe-boundary continuation still sets runtime-owned runLineage.parentRunId and stays session-inline because the continuation header has continuationSource and no agentId.
  • Startup recovery still terminalizes interrupted non-terminal runs, including historical child AgentRuns. That is crash recovery, not a live control entry. Leaving those rows as running after restart would be worse.

Hosted test, windows_recovery, and label are green on this head. The merge tree against current main is clean. This is a refactor; I am not merging it.

简体中文

我审的是 cebbeff14d3516f59951aaddf7b6b3076643daec。没有 P0/P1。一条 P3,写在 extraction ledger 对应行上。

P3. 这份文档前面的表格已经改成「历史 linked-child admission 只做重启关闭」,后面 production scope 仍把 hosted child RateLimit retry 写成活的 durable_continuation 准入。本 PR 删掉了 resumeChildAgent / retryChildAgent,Phase 3–4 合同也写明入口没了。文档打架时以代码为准,所以不挡合并。

我核对过:live 输入在写 AgentRun 之前就会拒绝那三个 lineage 字段;linked spawn 的第一跳仍是没有 parentRunId 的 session-inline Run;同会话 child 控制链没有残留调用方;历史 agent_list / agent_output 仍可读;continuation 仍走运行时自己的 parentRunId。重启时把中断的非终态 Run 收成失败,包括历史 child Run,这是崩溃恢复,不是新的执行入口。

这是重构,我不合入。


Automated review notice: This comment was posted by an automated review agent operated by WAWQAQ. It is not an independent human review and does not replace one.

Comment thread docs/architecture/runtime-resume-extraction-ledger.zh-CN.md
Remove the obsolete same-session child execution and continuation capabilities now that agent_spawn uses durable linked child Sessions. Keep historical AgentRun projections readable through agent_list and agent_output, and leave linked Session and Agent Graph execution unchanged.

Generated-by: Codex
@Astro-Han
Astro-Han force-pushed the refactor/runtime-remove-child-agentrun-control branch from cebbeff to ce88181 Compare August 29, 2026 13:38
@Astro-Han

Copy link
Copy Markdown
Contributor Author

Follow-up to the exact-head reviews and the synthesis above:

  • Accepted the current-contract consistency finding. Fixed in ce88181e4: the extraction ledger and the two same-root Phase 3-4 references now state that historical linked-child descriptors only close to durable terminal facts during startup recovery, with zero provider calls and no live or fallback child retry admission.
  • Did not add the proposed recovery skip. recoverAgentRunsFromLedger terminalization predates this PR and is the recovery authority that keeps historical projections truthful after a crash. It does not dispatch the provider, while isSessionInlineRun still prevents legacy child Runs from writing TurnState. Skipping non-inline legacy Runs would leave interrupted rows permanently reporting running.
  • No other code changes were needed. The two duplicate inline threads were replied to and resolved.

Verification: rebased onto current main at 20f256cf1; npm run format:check, stale-contract search, and git diff --check pass. CI has been triggered for the new exact head.

Thanks for the reviews.

@zhiiw zhiiw 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.

Reviewed at exact head ce88181e (verified unchanged at review time). Note on head movement: I began on cebbeff1; the PR was rebased onto current main with a docs-only rewording (the phase-3/4 design doc now describes the historical linked-child admission closure instead of the removed retry path). git range-diff and a direct tree diff confirm the production code is identical between the two heads; the results below were re-run on ce88181e.

Removal of the retired child-AgentRun control chain, verified rather than assumed:

  • The deletion stops at the ownership boundary: spawnChildAgent / prepareChildAgentResume / resumeChildAgent / retryChildAgent / ChildAgentTurnInput / AgentSpec / startChildTurn / startChildRetry / recordSessionMessages have zero remaining references at this head. The surviving legacy_child_run execution kind appears only in listChildAgents / readChildAgentOutput — the retained read-only projection of historical runs — and linked_child_resume / linked_child_provider_retry survive only as read-side tags in hosted-execution recovery/projection/availability. No producer remains.
  • Live-turn rejection is a runtime gate, not just a type deletion: assertNoRemovedChildAgentRunLineage throws on parentRunId / resumedFromRunId / retriedFromRunId at startTurn, which catches untyped or older JavaScript callers too, and the new session-manager test pins the rejection before any AgentRun is written.
  • Runtime-owned continuation lineage survives correctly: the safe-boundary continuation path now carries parentRunId through the internal runLineage channel (never accepted from live input), and continuationTargetRunHeaderForExecution sets it from continuation.sourceRunId directly.
  • Simplification is real: the child backend-generation map, the route discriminator, the transcript-suppression flag, and the resumed-child replay machinery (cycle-walking, replay-safety diagnostics, environment-match checks) are all gone with their only callers.

Executed on a real Windows machine at this head: clean forced rebuild of core/runtime/runtime-host, then the PR's focused set — session-manager 176/176 (including the new rejection test), subagent-tools 27/27, admission-limiter 8/8, runtime-ledger-repair 3/5 — the two failures are the pre-existing Windows flake class (EBUSY unlinking temp SQLite fixtures during teardown; unrelated to this PR's one-line touch of that file). The hosted test job is still running on this rebased head at approval time; it passed on the pre-rebase head with identical production code.


Automated review notice: This comment was posted by an automated review agent operated by zhiiw. It is not an independent human review and does not replace one.

简体中文

删除链端到端核实:被删符号全树零残留;legacy_child_run 只剩 agent_list/agent_output 只读投影,linked_child_resume/retry 只剩恢复/投影侧的历史记录解读,无生产者。活体拒绝是运行时断言(非仅类型删除),覆盖了非类型化 JS 调用方,新测试钉住「AgentRun 落盘前拒绝」。safe-boundary continuation 的 lineage 改走内部 runLineage 通道,不受活体拒绝影响。本机真 Windows 干净重建后四个靶向套件 214/216——2 个失败是既有 Windows EBUSY 临时库清理噪音(CI 同 head 的 test 在批时仍在跑,rebase 前同内容 head 已绿;两个 head 的生产代码逐字节一致)。

@Astro-Han
Astro-Han merged commit d83a082 into apache:main Aug 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XL Over 1000 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants