Skip to content

feat(runtime-host): establish hosted root execution foundation - #1551

Merged
Astro-Han merged 4 commits into
apache:mainfrom
M4n5ter:feat/runtime-host-root-execution-foundation
Jul 28, 2026
Merged

Astro-Han merged 4 commits into
apache:mainfrom
M4n5ter:feat/runtime-host-root-execution-foundation

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Jul 28, 2026 •

Copy link
Copy Markdown
Member
English

Context

This PR establishes the hosted root execution foundation for the Runtime Host M3 migration tracked by #1167.

It closes the admission, execution ownership, cancellation, recovery, and terminal handoff boundaries shared by linked child roots and durably claimed agent-graph roots. Runtime Host remains non-serving in production; this PR does not switch Desktop, TUI, CLI, or Headless entrypoints.

What changes

Canonical execution identity and admission

  • Extend the canonical root execution descriptor to distinguish external messages, linked child creation, linked child resume, provider retry, and claimed agent-graph execution.
  • Persist the exact execution descriptor with root-Turn admission, including trusted agent identity, lineage, claim identity, and whether the execution owns a user message.
  • Reuse the single Host-owned AgentGraphControlStore for graph coordination and trusted claim reads; this PR does not introduce a second claim writer.
  • Bind each durable claim to the complete runnable intent and prompt, then recompute that fingerprint from the trusted claim before Runtime ownership or any execution side effect.
  • Require hosted graph execution to re-read claims and root admission identity through its trusted Host composition capability. A caller-provided Store reference is not authoritative.
  • Route an existing matching Run back through Host executeRoot, require its exact durable admission and unique UserMessage, and never synthesize or backfill missing authority.
  • Reuse an in-flight execution only when the durable claim and normalized request fingerprint are identical; conflicting reuse fails closed.

Runtime execution ownership and cancellation

  • Introduce a per-Session RuntimeExecutionClaim that reserves the execution slot before asynchronous backend activation and exposes one stop signal for the complete startup and execution path.
  • Propagate stop through queued graph execution, backend construction, run.begin(), the first iterator step, and active execution.
  • Preserve per-Session graph ordering while allowing a truly queued, stopped claim to release without durable admission or backend activation.
  • Transfer execution ownership when linked child work moves from the parent Session to the child Session, without leaving overlapping claims.
  • Register a backend that arrives after cancellation as a real generation and quarantine it through the existing disposal path. A disposal failure permanently blocks replacement instead of allowing an untracked backend to escape.
  • Finalize Run, Message, and Interaction ownership through one execution scope. Authority cleanup failures retain an explicit typed identity across cleanup and stop aggregation.

Host terminal and recovery boundary

  • Recover each root according to its execution contract: external roots may replay queue sources, while linked and claimed roots use their exact child recovery closure.
  • Audit the completed Run against the admitted Turn, trusted agent identity, and linked-child lineage on both normal completion and canonical-terminal failure paths.
  • Contain an ordinary backend failure once its canonical failed terminal fact has committed, so one failed Run does not drain an otherwise healthy Host.
  • Treat execution identity drift, Message or Interaction authority failure, and owner cleanup failure as Host-fatal conditions that request drain.
  • Stop graph producers before draining the RootTurn consumer during composition shutdown.
  • Keep terminal transition authoritative during stop and failure races. A stop may release queued work promptly, but an active admitted execution still completes its canonical cancellation boundary.

Design decisions

  • Durable identity is authoritative. Hosted graph execution trusts the persisted claim and root admission, not mutable caller input.
  • One graph authority owns the state. Coordination and claim reads share the Host-owned control Store instead of opening parallel writers.
  • Reservation precedes effects. A physical execution slot is held before backend construction so stop and shutdown cannot miss pending-start work.
  • Cancellation follows exact ownership. Stop is propagated by the execution claim rather than inferred from error names or unrelated aborts.
  • Provider failure is not automatically Host failure. A Run with a valid canonical failed terminal fact is contained; authority and ownership invariant failures remain fail-stop.
  • Late activation cannot escape ownership. A backend produced after cancellation must still enter the generation lifecycle and be disposed or quarantined.
  • The Host remains non-serving. These contracts are established before production activation, without dual writers or compatibility machinery.

Evidence

Coverage exercises the real SQLite graph control Store, complete claim-input fingerprinting, missing or conflicting existing-Run authority, exact claim retry behavior, linked child creation/resume/provider retry, claimed graph ordering, queued and pending-start cancellation, backend activation races, late-generation quarantine, terminal identity drift, owner cleanup failure, recovery, and ordinary backend failure containment.

  • Runtime: 2,768 passed, 9 existing skips.
  • Runtime Host: 220 passed.
  • Post-rebase targeted Runtime/Host authority and lifecycle coverage: 313 passed.
  • Runtime Host dependency-boundary coverage: 5 passed.
  • Root production build, workspace typecheck, Biome checks, and git diff --check pass.
  • Independent correctness and maintainability reviews report no remaining P0-P3 findings.

Scope

This slice intentionally does not add a real hosted model Backend, Prompt/Tool convergence, production surface wiring, Automation or Goal ownership, Native Provider, Runtime Resources, or the M4/M5 cutover.

Part of #1167. Related to #853.

简体中文

背景

本 PR 为 #1167 跟踪的 Runtime Host M3 迁移建立 hosted root execution foundation。

它关闭 linked child root 与 durable claimed agent-graph root 共同依赖的 admission、execution ownership、cancellation、recovery 和 terminal handoff 边界。Runtime Host 仍未进入 production serving;本 PR 不切换 Desktop、TUI、CLI 或 Headless 的任何入口。

改动内容

Canonical execution identity 与 admission

  • 扩展 canonical root execution descriptor,明确区分 external message、linked child creation、linked child resume、provider retry 与 claimed agent-graph execution。
  • 将精确 execution descriptor 与 root-Turn admission 一同持久化,其中包括 trusted agent identity、lineage、claim identity,以及该 execution 是否拥有 user message。
  • Graph coordination 与 trusted claim read 复用单一 Host-owned AgentGraphControlStore;本 PR 不引入第二个 claim writer。
  • 将完整 runnable intent 与 prompt 一同绑定到 durable claim,并在 Runtime ownership 或任何 execution effect 之前通过 trusted claim 重算 fingerprint。
  • Hosted graph execution 必须通过 Host composition 提供的 trusted capability 重新读取 claim 与 root admission identity;调用者传入的 Store reference 不构成权威事实。
  • Existing matching Run 也必须重新进入 Host executeRoot,具备精确 durable admission 与唯一 UserMessage;缺失的 authority 不会被合成或回填。
  • 只有 durable claim 与 normalized request fingerprint 完全一致时才复用 in-flight execution;冲突复用会 fail closed。

Runtime execution ownership 与 cancellation

  • 引入 per-Session RuntimeExecutionClaim,在异步 backend activation 前预留 execution slot,并为完整启动和执行路径提供统一 stop signal。
  • Stop 会传播到 queued graph execution、backend construction、run.begin()、首个 iterator step 与 active execution。
  • 保持同一 Session 内 graph execution 的顺序,同时允许真正仍在队列中的 stopped claim 在没有 durable admission 或 backend activation 的情况下及时释放。
  • Linked child work 从 parent Session 转移到 child Session 时同步转移 execution ownership,不留下重叠 claim。
  • Cancellation 后才返回的 backend 会先登记为真实 generation,再进入既有 disposal/quarantine 路径。Disposal 失败会永久阻止 replacement,避免未受跟踪的 backend 逃逸。
  • Run、Message 与 Interaction ownership 通过同一个 execution scope 收束。Authority cleanup failure 在 cleanup 与 stop 聚合后仍保留明确 typed identity。

Host terminal 与 recovery boundary

  • 根据 execution contract 恢复 root:external root 可以重放 queue source;linked 与 claimed root 则使用各自精确的 child recovery closure。
  • 在正常完成和 canonical-terminal failure 两条路径中,都校验 completed Run 与 admitted Turn、trusted agent identity 和 linked-child lineage 一致。
  • 普通 backend failure 在 canonical failed terminal fact 已提交后会被 containment,避免单个失败 Run 导致健康 Host drain。
  • Execution identity drift、Message/Interaction authority failure 与 owner cleanup failure 仍属于 Host-fatal condition,会请求 drain。
  • Composition shutdown 会先停止 graph producer,再 drain RootTurn consumer。
  • Stop 与 failure 竞态中仍以 terminal transition 为权威边界。Stop 可以及时释放 queued work,但已经 active 且 admitted 的 execution 仍会完成 canonical cancellation。

设计决策

  • Durable identity 是权威事实。 Hosted graph execution 信任持久化 claim 与 root admission,不信任可变的调用者输入。
  • Graph state 只有一个 authority。 Coordination 与 claim read 共享 Host-owned control Store,不打开并行 writer。
  • Reservation 先于 effect。 Backend construction 前已经持有 execution slot,使 stop 和 shutdown 不会漏掉 pending-start work。
  • Cancellation 跟随精确 ownership。 Stop 由 execution claim 传播,不根据错误名称或无关 abort 进行猜测。
  • Provider failure 不自动等于 Host failure。 具有合法 canonical failed terminal fact 的 Run 可以 containment;authority 与 ownership invariant failure 仍然 fail-stop。
  • 迟到 activation 不能逃逸 ownership。 Cancellation 后产生的 backend 仍必须进入 generation lifecycle,并被成功 dispose 或永久 quarantine。
  • Host 继续保持 non-serving。 这些契约会在 production activation 前建立,不引入 dual writer 或兼容机制。

验证证据

覆盖范围包括真实 SQLite graph control Store、完整 claim-input fingerprint、缺失或冲突的 existing-Run authority、精确 claim retry、linked child creation/resume/provider retry、claimed graph ordering、queued 与 pending-start cancellation、backend activation race、迟到 generation quarantine、terminal identity drift、owner cleanup failure、recovery,以及普通 backend failure containment。

  • Runtime:2,768 项通过,另有 9 项既有 skip。
  • Runtime Host:220 项全部通过。
  • Rebase 后 Runtime/Host authority 与 lifecycle 定向覆盖:313 项通过。
  • Runtime Host dependency-boundary:5 项通过。
  • 根级 production build、workspace typecheck、Biome 检查与 git diff --check 均通过。
  • 独立正确性与可维护性审查未发现剩余 P0-P3 finding。

范围

本 slice 明确不加入真实 hosted model Backend、Prompt/Tool convergence、production surface wiring、Automation 或 Goal ownership、Native Provider、Runtime Resources,或 M4/M5 cutover。

属于 #1167;关联 #853。

@Astro-Han

Copy link
Copy Markdown
Contributor

Reviewed at 582d490b81869b698eb9326f8de4733e0ad66298.

P1: The durable claim fingerprint does not constrain the prompt used for first execution.

claimAgentGraphRunnableIntent includes the intent and prompt in claim.intentFingerprint, but hosted execution only rereads the claim and checks that the caller prompt is non-empty. Reproduction: persist a claim for prompt A, then call the hosted manager with the same graph and intent IDs but prompt B. Prompt B is admitted and persisted under the claim for A instead of failing closed. Bind execution to the trusted claimed input, or recompute and verify the fingerprint before first admission. Add a negative test for prompt drift before any Run or UserMessage exists.

P2: The existing-Run path bypasses RootTurnAdmission authority.

If a matching terminal Run already exists, runClaimedAgentGraphIntentOnce returns it without reading the trusted RootTurnAdmission or entering Host executeRoot. assertClaimedAgentGraphPrompt also accepts zero UserMessages. A matching Run with no RootTurnAdmission and no UserMessage is therefore accepted as the result of the claim.

Require and validate the hosted admission identity on this path, including execution kind, run identity, user-message identity, and content. Add negative tests for missing admission and conflicting admission or message data.

@M4n5ter
M4n5ter force-pushed the feat/runtime-host-root-execution-foundation branch from 582d490 to aec7282 Compare July 28, 2026 15:39

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

Rechecked aec7282f. The durable claim now binds the prompt before any execution side effect, and existing hosted Runs require the exact RootTurnAdmission and UserMessage through executeRoot. No findings in the increment. The focused builds and tests pass.

@Astro-Han
Astro-Han merged commit acff725 into apache:main Jul 28, 2026
3 checks passed
@M4n5ter
M4n5ter deleted the feat/runtime-host-root-execution-foundation branch July 29, 2026 01:14
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