Skip to content

feat(runtime-host): add runtime policy authority - #1401

Merged
Astro-Han merged 4 commits into
apache:mainfrom
M4n5ter:feat/runtime-host-policy-authority
Jul 24, 2026
Merged

Astro-Han merged 4 commits into
apache:mainfrom
M4n5ter:feat/runtime-host-policy-authority

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Jul 23, 2026 •

Copy link
Copy Markdown
Member
English

Context

This PR establishes the Runtime Host authority for Runtime Policy, the Connection Catalog, and the Credential Vault. It is a complete M3 authority slice tracked by #1167.

The Host remains non-serving in production. This PR does not switch Desktop, TUI, CLI, or Headless entrypoints, and it does not migrate the current mixed surface settings document.

What changes

Canonical contracts

  • Add closed codecs and canonical snapshots for Runtime Policy, Connection Catalog, and Credential Vault state.
  • Give every mutable document a revision and compare-and-set mutation contract. Exact decoders reject unknown fields, malformed identities, unsupported providers, invalid endpoints, and oversized state.
  • Keep credential projections redacted. Secret material is available only through the authenticated Host-side execution resolver and never crosses the operation protocol.
  • Keep model inventory, discovery provenance, fetch time, and last-test facts in the canonical Connection Catalog schema. The authority owns these facts even though the network effects that produce them remain in a later slice.

Lease-bound persistence

  • Bind readers and the single writer facade to an authentic Interactive root lease; forged facades, wrong root kinds, and operations after lease close fail closed.
  • Serialize mutations across the three documents and publish private files through bounded, synchronized temporary writes.
  • Report ambiguous durable publication as commit_outcome_unknown rather than guessing whether a retry is safe.
  • Recover recognizable temporary artifacts before exposing the writer. If connection removal commits before credential cleanup, a successor removes only credentials whose Connection owner no longer exists; unrelated web-search and proxy credentials are preserved.

Typed Host operations

  • Add ten exact query and mutation operations for Runtime Policy, Connection Catalog, and Credential Vault state, including revision-pinned catalog pagination.
  • Compose those operations through the existing closed dispatcher. Non-serving compositions receive typed unavailable handlers for every declared domain operation.
  • Order mutations against one shared backend-activation boundary. Root turns, linked and legacy child runs, continuations, retries, and compaction cross the same boundary; activations remain concurrent, while a mutation waits for admitted activations and blocks later ones until invalidation settles.
  • Invalidate only backend identities currently owned by the RuntimeKernel cache. A policy edit does not enumerate persisted Sessions or read transcript previews merely to find idle work.
  • Treat policy invalidation as a strict boundary. It joins an already-running disposal, waits for active work to settle, and observes the disposal outcome. Failure preserves the committed policy result, poisons later activation, and asks the Host to drain. Ordinary non-policy invalidation remains best-effort.
  • Backend activation waits for any in-flight disposal and then rechecks the relevant parent or child cache, so a replacement cannot escape a mutation that has already entered the authority boundary.

Evidence

Coverage includes strict codec boundaries, lease authentication, compare-and-set conflicts, secret redaction, ambiguous durable publication, interrupted connection removal and successor recovery, large revision-pinned catalogs, two real UDS Clients racing one authority, production gate composition, cached-only invalidation, disposal failure propagation, and deterministic parent/child replacement races.

After rebasing onto current main, the full Runtime suite passes 2,495 tests with seven existing skips, and Runtime Host passes all 89 tests. The workspace build and typecheck, Biome format/lint checks, and git diff --check also pass.

Scope

This slice intentionally does not perform model discovery, connection testing, OAuth refresh/presentation, or other network/native effects. Those belong to later Connection Effects and OAuth slices, which will commit their results through this authority. Production surface wiring, AppSettings removal, deferred-tool economy wiring, and the M4 cutover also remain out of scope.

Part of #1167. Related to #853.

简体中文

背景

本 PR 建立 Runtime Host 对 Runtime Policy、Connection Catalog 与 Credential Vault 的权威所有权,是 #1167 跟踪的一份完整 M3 authority slice。

Runtime Host 仍未进入 production serving。本 PR 不切换 Desktop、TUI、CLI 或 Headless 的入口,也不迁移当前混合了多个 owner 的 surface settings 文档。

改动内容

Canonical 契约

  • 为 Runtime Policy、Connection Catalog 与 Credential Vault 状态增加封闭 codec 和 canonical snapshot。
  • 每个可变文档都有 revision 与 compare-and-set mutation 契约。精确 decoder 会拒绝未知字段、畸形 identity、不支持的 provider、非法 endpoint 与超限状态。
  • Credential projection 始终脱敏。秘密材料只能由经过认证的 Host 侧 execution resolver 取得,绝不会穿过 operation protocol。
  • Connection Catalog 的 canonical schema 保留 model inventory、discovery provenance、fetch time 与 last-test fact。该 authority 拥有这些事实,但产生它们的网络 effect 留在后续 slice。

Lease-bound 持久化

  • Reader 与唯一 writer facade 都绑定到真实 Interactive root lease;伪造 facade、错误 root kind,以及 lease 关闭后的 operation 都会 fail closed。
  • 三份文档的 mutation 统一串行化,并通过有界、同步的临时写入发布私有文件。
  • Durable publication 结果不确定时返回 commit_outcome_unknown,不猜测重试是否安全。
  • Writer 对外可用前先恢复可识别的临时 artifact。如果 connection removal 已提交、但 credential cleanup 尚未完成,successor 只删除已经失去 Connection owner 的 credential;无关的 web-search 与 proxy credential 会被保留。

Typed Host operation

  • 增加十个精确的 Runtime Policy、Connection Catalog 与 Credential Vault query/mutation operation,其中包括绑定 revision 的 Catalog pagination。
  • 这些 operation 通过现有封闭 dispatcher 组合;non-serving composition 会为每个已声明 domain operation 提供 typed unavailable handler。
  • Mutation 与同一个 backend-activation boundary 排序。Root turn、linked/legacy child run、continuation、retry 与 compaction 都经过该边界;多个 activation 仍可并行,mutation 会等待已经接纳的 activation,并在 invalidation 收束前阻止后来的 activation。
  • 只使 RuntimeKernel cache 当前拥有的 backend identity 失效。Policy edit 不会为了寻找 idle work 枚举持久化 Session 或读取 transcript preview。
  • Policy invalidation 是 strict boundary:加入正在进行的 disposal,等待 active work 收束,并观察 disposal outcome。失败时保留已提交的 policy result、poison 后续 activation,并请求 Host drain;普通非 policy invalidation 仍保持 best-effort。
  • Backend activation 会等待同 Session 正在进行的 disposal,再重新检查对应 parent/child cache,避免 replacement 逃过已经进入 authority boundary 的 mutation。

验证证据

覆盖严格 codec 边界、lease 认证、compare-and-set 冲突、秘密脱敏、durable publication 结果不确定、connection removal 中断后的 successor recovery、大型 revision-pinned Catalog、两个真实 UDS Client 竞争同一 authority、production gate composition、cached-only invalidation、disposal failure propagation,以及确定性的 parent/child replacement race。

Rebase 到当前 main 后,Runtime 全量 2,495 项通过,另有 7 项既有 skip;Runtime Host 89 项全部通过。全 workspace build 与 typecheck、Biome format/lint 和 git diff --check 也均通过。

范围

本 slice 刻意不执行 model discovery、connection test、OAuth refresh/presentation 或其他 network/native effect。这些内容属于后续 Connection Effects 与 OAuth slice,并通过本 authority 提交结果。Production surface wiring、AppSettings 删除、deferred-tool economy 接线与 M4 cutover 也不在本 PR 范围内。

属于 #1167;关联 #853。

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

I found two lower-severity gaps:

  • [P2] SessionManager.refreshIdleBackends() relies on RuntimeKernel.invalidateBackend(), but the idle path reaches disposeBackend(), which catches every backend.dispose() error and returns success. onCommittedMutation() therefore resolves, the activation gate is not poisoned, and the Host does not drain. This contradicts the PR's stated failure contract. A backend that fails cleanup can remain alive outside the cache while later activations continue. Propagate disposal failures through this policy invalidation path.
  • [P2] refreshIdleBackends() calls store.list() and invalidates every persisted session. Production SessionStore.list() reads preview messages for every record and full transcript snapshots for the first three. A policy or credential edit therefore performs storage work proportional to the entire session history, even though only cached backends need invalidation. It can also poison and drain the Host because of an unrelated session-list failure. The runtime kernel already owns the active backend maps, so this refresh should target those cached session IDs.

These do not block the non-serving authority slice, so I am approving. They should be fixed before production cutover.

@M4n5ter
M4n5ter force-pushed the feat/runtime-host-policy-authority branch from e4c43b5 to d127a6f Compare July 24, 2026 10:32
@M4n5ter

M4n5ter commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

@Astro-Han Agreed with both findings. They are fixed in b6c36dd0 (with the existing lifecycle expectation aligned in d127a6f0).

  • refreshIdleBackends() now asks RuntimeKernel to invalidate only backend identities present in its parent/child caches or an existing invalidation, rather than calling SessionStore.list().
  • Strict policy invalidation has an explicit non-rejecting disposal outcome. It joins an in-flight disposal, waits for active work to settle, and propagates cleanup failure to the policy boundary; the committed mutation result is preserved, later activation is poisoned, and the Host drains.
  • Parent and child activation both wait for an in-flight disposal and recheck their cache afterward, closing the replacement race. Ordinary best-effort cleanup outside this policy boundary remains best-effort.

The overlap tests use a real RuntimeEvent persistence gate. Removing either the parent or child wait/recheck makes its corresponding test fail deterministically. After rebasing to current main, the full Runtime and Runtime Host suites pass; the PR body now records the narrowed invalidation and failure contract.

简体中文

同意这两项 finding,已在 b6c36dd0 中修复;d127a6f0 同步校正了既有 lifecycle 测试对 strict refresh 的旧时序预期。

  • refreshIdleBackends() 现在让 RuntimeKernel 只使 parent/child cache 或既有 invalidation 中的 backend identity 失效,不再调用 SessionStore.list()。
  • Strict policy invalidation 使用显式、不会产生未处理拒绝的 disposal outcome。它会加入正在进行的 disposal、等待 active work 收束,并把 cleanup failure 传播回 policy boundary;已提交 mutation result 保留,后续 activation 被 poison,Host 请求 drain。
  • Parent 与 child activation 都会等待正在进行的 disposal,随后重新检查对应 cache,关闭 replacement race。该 policy boundary 之外的普通 best-effort cleanup 仍保持 best-effort。

Overlap 测试使用真实 RuntimeEvent persistence gate;分别移除 parent 或 child 的 wait/recheck 后,对应测试都会确定性失败。Rebase 到当前 main 后,Runtime 与 Runtime Host 全量均通过;PR body 也已更新为这份收窄后的 invalidation 与 failure 契约。

@Astro-Han

Astro-Han commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Needs a rebase onto latest main before this can merge. main moved forward by several PRs after the green CI run, so GitHub now reports mergeable: conflicting.

Only one real conflict, in packages/core/src/index.ts: both sides add a barrel export after ./plan.js. main adds ./agent-graph-control.js, this PR adds ./runtime-policy.js. Keep both. packages/core/package.json auto-merges.

@M4n5ter can you rebase onto main, keep both exports in core/src/index.ts, and force-push?

@M4n5ter
M4n5ter force-pushed the feat/runtime-host-policy-authority branch from d127a6f to 2704a10 Compare July 24, 2026 11:25
@M4n5ter

M4n5ter commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

Needs a rebase onto latest main before this can merge. main moved forward by several PRs after the green CI run, so GitHub now reports mergeable: conflicting.

Only one real conflict, in packages/core/src/index.ts: both sides add a barrel export after ./plan.js. main adds ./agent-graph-control.js, this PR adds ./runtime-policy.js. Keep both. packages/core/package.json auto-merges.

@M4n5ter can you rebase onto main, keep both exports in core/src/index.ts, and force-push?

@Astro-Han Done

@M4n5ter

M4n5ter commented Jul 24, 2026 •

Copy link
Copy Markdown
Member Author

@Astro-Han Rebased onto the latest main and force-pushed 2704a105. Both agent-graph-control and runtime-policy exports are preserved in packages/core/src/index.ts. All CI checks are green and GitHub now reports the PR as cleanly mergeable.

简体中文

已 rebase 到最新 main 并 force-push 2704a105。packages/core/src/index.ts 中保留了 agent-graph-control 与 runtime-policy 两项 export。当前 CI 全绿,GitHub 也已恢复为可干净合并。

@Astro-Han
Astro-Han merged commit 401a658 into apache:main Jul 24, 2026
3 checks passed
@M4n5ter
M4n5ter deleted the feat/runtime-host-policy-authority branch July 24, 2026 12:09
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