Skip to content

feat(agent): enforce parent authority for delegated sessions - #6618

Merged
M4n5ter merged 3 commits into
rust-previewfrom
feat/session-parent-authority
Nov 4, 2026
Merged

M4n5ter merged 3 commits into
rust-previewfrom
feat/session-parent-authority

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Inherit sandbox policy and tool ceilings from the real creating Agent, not the workspace donor. Create/fork/import share the same caller-policy decision; temporary grants are not copied.
  • Preserve trusted SessionSend provenance through queued/steered messages, semantic history, persisted source recipes and model input. Display the sender's conversation title rather than its ID, with click-to-open-beside navigation. Mounted source-title subscriptions follow renames without token-driven full-projection scans.
  • Let parents inspect and answer their direct children's interactions. Decisions within the parent's effective authority proceed directly; broader approvals ask the human in the parent conversation, then settle the exact original child request. Escalation proposals use a closed allow-only type and show the proposed grant scope before the original request details.
  • Reject Agent permission changes through SessionUpdate. Agents may edit/retract/promote/reorder only their own queued messages, never human or other-session messages while retaining their attribution.
  • Hide children in the normal sidebar while keeping the child browser and an explicit Waiting for you inbox/count that includes parked children.

Review follow-up

Addressed in 3c92b6320:

  • Resolve caller policy across sibling Agent/WorkHub instances. Accepted coordinator work can recover after its original turn ends, using the caller's current canonical policy rather than installation defaults.
  • Restore typed Unavailable rejection for missing/wrong-session interaction IDs; retain actual infrastructure errors.
  • Preserve already committed human denial across a subsequent parent permission edit; retain Stop/liveness checks. Add deterministic denial/edit and child-settled prompt-withdrawal regressions.
  • Bound derived tool ceilings for every creation route and protect queued-message authorship at the mutation boundary.
  • Narrow escalation answers, remove impossible UI branches, expose pending children, follow sender-title changes, and align human provenance formatting between native and external executors.
  • Keep the existing persisted Postcard variant layout; add the missing attributed-row codec case rather than silently changing existing bytes.
  • Exercise real SessionCreate in the desktop workflow and remove fixed scroll deltas/coordinate-cutoff assertions.

This does not add a global session-management ACL: existing WorkHub selected-worker task controls and explicitly human-approved service calls retain their established semantics. Cross-PR integration with #6617 remains separate while that PR is unmerged.

Security / review focus

Parent identity comes from trusted execution/native dispatch scope, never model-supplied metadata. Creation takes a policy snapshot, not an ongoing inheritance link. Delegated approval checks effective filesystem/network/service/client authority and grant duration, revalidates the parent permission basis before allowing, and settles or withdraws obsolete prompts against the original child request. System permission remains OS-owned; persistent application approval retains the existing human-only route.

Verification

  • Native crate suite exercised: 264 tests ran. Its initial run exposed five failures; after the fixes, the focused 19-test authority/interaction/WorkHub/Graph rerun passed, including every failed case. The existing question/form regression cases passed in the full run.
  • Strengthened real Graph test with a distinct caller policy and cross-instance child-policy assertions: 1 passed.
  • Approval wire types, pending-child catalog visibility/count, attributed-row codec and production-wire provenance after reopen: 5 passed.
  • Final real desktop Host-fixture workflow and nested/archived child-browser tests: 2 passed.
  • SDK regenerated from Rust; SDK, bundle and strict affected-UI TypeScript checks passed.
  • Product build passed (24 ordinary plugin packages); product-composition tests: 5 passed.
  • Changed Rust formatting, Biome, ASF headers and diff checks passed.
  • Remote CI on 3c92b6320: run 41786827194 exposed two terminal workspace-pagination test failures. Both were reproduced locally, then fixed in 95f2d537e: complete the Browsing.needsYouCount fixture contract and click button centers rather than flooring top-left bounds to a cell outside the button (the collapse target starts at y=218, while the old click landed at y=216). No production pagination changes, relaxed assertions, retries or timeout increases.
  • After the CI fix, the full affected terminal::ui::tests module passed locally: 21/21, including both original failures. Rustfmt, Biome format, ASF headers and diff checks passed.
  • Per the owner's explicit instruction, merge after these local checks without waiting for a fresh complete remote CI run; remote CI for the new head is not claimed green.

Screenshots

Updated from the actual Workbench on the review-fix branch using the GPUI/WGPU offscreen desktop renderer and an isolated real Host fixture. The model is mocked; SessionCreate, SessionSend, human confirmation and source navigation use the production paths. The child access request is seeded into its active invocation. No private user conversations are used.

Exact proposed approval is visible before the original request

Parent review showing the proposed one-call child grant above the original request

Waiting children remain discoverable

The explicit Waiting for you inbox includes a pending child hidden from normal sidebar roots

Trusted sender opens beside the child

Sender conversation title opens the loaded parent beside the child

Child browser retains descendants

The parent child browser retains nested and archived descendants

AI use

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

Tool(s) and scope: Maka assisted with design, implementation, targeted tests, UI fixture verification, review follow-up and PR preparation. Material AI-authored commits include Generated-by: Maka.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and affected local checks pass after the fixes

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Inherit the real caller's sandbox policy, preserve trusted message provenance, and delegate direct-child approvals with explicit human escalation in the parent conversation. Keep child sessions out of sidebar roots while retaining child browsing and source navigation.

Generated-by: Maka

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Code & Test Review (English) — 4 blocking bugs / authority gaps (incl. CI failures), 5 cleanliness & UX issues, 2 test cleanups

Summary

The concurrency and provenance fundamentals in this PR are genuinely clean: the two-phase lock in Owner::respond_inner (plugins/agent/native/src/owner/interactions/delegation.rs:127-180) avoids holding runs.lock() across human waits while re-verifying permission_basis before commit, confirm_child_response (delegation.rs:364-374) uses tokio::select! to withdraw parent SessionApproval prompts cleanly if the child interaction settles first, temporal grant containment (Scope::Turn authorizing child Scope::Once only) is sound, and [Message source (Host-provided): ...] is projected at the model boundary without polluting persisted message text or digests.

However, 2 blocking regressions are currently failing 5 native CI shards, 2 authority/provenance gaps remain on sibling session Paths, and several type/projection choices leave unnecessary dead branches and hot-path overhead.


1. Blocking Bugs, CI Regressions & Authority Gaps

  1. Owner::creation_permissions breaks cross-instance WorkHub / Graph worker creation (fails 5 native CI shards)

    • Owner::creation_permissions (plugins/agent/native/src/owner.rs:713-725) inspects scope.identity.agent() and calls self.scoped_store(scope, &invocation.session_id).await?.
    • scoped_store (owner.rs:657) rejects !self.owns(id) with Err("agent_session_unavailable"). When a WorkHub or Graph coordinator (wh_..., owned by the WorkHub Owner instance) creates a worker session on the ordinary agent Owner instance (s_...), self.owns("wh_...") is false—causing every WorkHub/Graph worker dispatch to fail with agent_session_unavailable.
    • Fix: Resolve caller authority from shared SessionStore / maka_agent_authority when invocation.session_id belongs to a sibling coordinator instance in the same profile store rather than rejecting via self.owns(...).
  2. Owner::respond_inner regresses missing/wrong-session request_id from domain Rejected into untyped RPC Err (fails 2 interactions CI tests)

    • Previously, commit_response_unlocked (plugins/agent/native/src/owner/interactions.rs:116-140) returned Ok(InteractionResult::Rejected { reason: InteractionRejection::Unavailable }) when request_id did not belong to input.session_id.
    • respond_inner (plugins/agent/native/src/owner/interactions/delegation.rs:108-110) now calls self.interaction(&input.session_id, &input.request_id).await? up front, turning a missing or wrong-session request_id into Err("agent_interaction_unavailable") (breaking native_form_validates_original_fields_and_commits_before_resuming and native_question_roundtrip_is_bound_owned_and_first_wins). The same raw ? propagation exists in child_answered (delegation.rs:371, 423-427).
  3. Tool-ceiling inheritance (tools) still trusts the workspace donor instead of the calling agent (authority bypass)

    • Owner::create (plugins/agent/native/src/owner.rs:782-864), fork.rs:135-141, and imports.rs:352-369 fixed permissions to inherit from scope.identity.agent(), but left tools reading from WorkspaceSelection::Session (or defaulting to None—unrestricted—for Directory, Project, and IsolatedGit).
    • A tool-restricted non-Bot agent can spawn a Directory child session with tools: None and escalate out of its tool allowlist. Intersect or bound child tools by the real calling agent's live tool ceiling across create, fork, and import.
  4. SessionEditQueue (editQueue) lacks caller/ownership checks and mutates queued messages while preserving original MessageOrigin

    • products/maka/bundle/src/installation.ts:241-245 grants SessionEditQueue to all agents, plugins/agent/native/src/service.rs:1039-1046 and owner/queue/controls.rs:148 enforce no caller ownership guard, and platform/event-log/src/message_queue/edit.rs:94-112 rewrites queued message text in-place while retaining entry.source.message.origin (None for a human or another Session). A delegated child could rewrite a human's queued prompt in the parent session while keeping human provenance.
    • Audit sibling control endpoints consistently as well: SessionChange (archive/delete), SessionUpdate, SessionStop (may_control in notifications.rs:106 currently restricts only Bot), and SessionResume.

2. Cleanliness, Type Modeling & UX Polish

  • Merge origin directly into RowDirectory::User instead of adding a Postcard compatibility variant (plugins/agent/facts/src/history/semantic/directory.rs:65-68, 101-106): RowDirectory::AttributedUser was appended solely to preserve old Postcard layouts (// Append to preserve the Postcard layout of existing directory variants) and was also missed in every_row_kind_preserves_positions_measures_and_independent_flags (codec/tests.rs:78-141). Internal semantic cache layouts do not carry backwards-compatibility guarantees—fold origin into RowDirectory::User directly.
  • Model SessionApproval with a closed narrow approval enum instead of Box<InteractionAnswer> (plugins/agent/facts/src/interaction.rs:174-180): Only 4 allow decisions can ever be escalated (ServiceApproval(Allow), Permissions(Allow), ClientCapability(Allow), ComputerApp(Once|Session|Always)). Wrapping unrestricted Box<InteractionAnswer> permits impossible states (Question, Form, Deny, nested SessionApproval) in the schema and forced ~90 lines of unreachable UI branches and dead locale keys in SessionApprovalRequest.tsx:48-209 and InteractionComposer.tsx:272-283.
    • Also note delegation.rs:147, 174-178: when a human clicks Deny child decision, input.answer becomes Deny (requiring zero parent authority), yet a concurrent parent permission_basis edit still aborts with AuthorizationChanged and drops the human's denial.
  • rootsOnly: true hides parked child interactions from NeedsYou and needs_you_count (products/maka/workbench/app/browsing.ts:95, 154, platform/event-log/src/sessions/catalog.rs:173-177, 234-241): Because SessionSend is asynchronous, a child session can park on a question or approval after its parent turn has already completed or stopped; filtering NeedsYou strictly to parentSessionId IS NULL makes those waiting child prompts invisible.
  • Avoid per-token full-row scans and permanent title caching in createMessageSenders (Conversation.tsx:533-555, messageSenders.ts:43-67): Conversation.tsx subscribes to projection() (which ticks on every streaming model token / activity delta) and allocates Array.from(projection().rowsById.values()) on every tick even though origin only changes on user/queue rows; messageSenders.ts also caches the one-shot observe title forever even if a child's auto-generated title arrives later.
  • Surface Proposed child decision above the fold or gate approval on scroll (InteractionComposer.tsx:850, 904-938, 1109): Putting Requested access above Proposed child decision inside a maxHeight: 336 scroll container clips the proposed grant scope (e.g. For this session) below the fold while Approve child decision is immediately clickable without scrolling.
  • Consistent human provenance header in mixed-origin turns (plugins/agent/engine/src/executor.rs:171-175 vs user.rs:47-50): External executors format origin: None as [Message source (Host-provided): null] whereas native model turns omit the header for human messages.

3. Test Cleanliness

  • Backend tests (plugins/agent/native/src/owner/tests/session_parent_authority.rs, plugins/agent/engine/src/production_tests.rs): Clean, readable, behavioral, and 100% event-driven with zero sleeps. Please add coverage for: (a) cross-instance WorkHub (wh_...) caller session creation, (b) human Deny on SessionApproval (including across a concurrent parent permission change), and (c) ChildSettled prompt withdrawal.
  • Desktop GPUI test (products/maka/desktop/tests/desktop_new_session.rs:1753-1959): Deterministic (no sleeps), but packs 5 distinct behaviors into one 207-line test in the serialized (-j 1) GPUI suite, seeds the child via raw store.create_session instead of exercising SessionCreate, relies on hardcoded pixel scroll deltas (px(-500.0)) and coordinate assertions (bounds.left() >= px(768.0)), and unconditionally writes 4 PNG artifacts (desktop.artifact(...)) on every CI run.

4. Cross-PR Notes (with #6617)

  • Merging alongside #6617 has textual conflicts in products/maka/bundle/src/installation.ts and packages/plugin-sdk/src/contracts.ts (plus generated SDK contracts).
  • Two silent cross-PR hazards to watch when combining both branches:
    1. desktop_new_session.rs:1795-1819 in this PR passes "model": fixture.selection to send and SessionSend, which compiles cleanly against #6617 and fails at runtime ('model' was unexpected).
    2. #6617's plugins/agent/native/src/executor/oar/history.rs:71-133 formats prior turns without MessageOrigin, stripping this PR's sender provenance on OAR multi-turn handoff.
代码与测试评审(简体中文) — 4 项阻塞级 Bug / 权限缺口(含 CI 挂点根因)、5 项整洁度与交互细节问题、2 项测试建议

总体评价

这个 PR 的核心并发与溯源机制写得很漂亮:Owner::respond_inner(plugins/agent/native/src/owner/interactions/delegation.rs:127-180)采用两阶段锁,不在人工审批等待期间持锁,并在最终提交前重验 permission_basis 防住 TOCTOU;confirm_child_response(delegation.rs:364-374)利用 tokio::select! 在子会话交互提前结束时自动撤回父会话的 SessionApproval,不留孤儿审批框;时域授权包含关系(父 Scope::Turn 仅可批子 Scope::Once)清晰严谨;[Message source (Host-provided): ...] 仅在模型投影边界注入,不污染事件日志原文与摘要。

但目前存在 2 项直接导致远端 CI 5 个 native 分片挂掉的阻塞级回归、2 项同类路径未对齐的权限/溯源缺口,以及违反仓库无兼容分支 / 精确类型建模原则的冗余代码,建议一并收口。


1. 阻塞级 Bug、CI 挂点根因与权限缺口

  1. Owner::creation_permissions 误拒跨实例调用,打挂所有 WorkHub / Graph 子会话创建(CI 5 个 native 分片挂点)

    • Owner::creation_permissions(plugins/agent/native/src/owner.rs:713-725)读取 scope.identity.agent() 后调用了 self.scoped_store(scope, &invocation.session_id).await?。
    • 而 scoped_store(owner.rs:657)强校验 if !self.owns(id)(只认 s_ 前缀)。当 WorkHub 或 Graph 协调器(wh_...,由 WorkHub Owner 实例持有)向普通 agent Owner 创建 worker 会话时,self.owns("wh_...") 为 false,全部报 agent_session_unavailable 失败。
    • 建议:当调用方 invocation.session_id 属于同一存储下的跨实例协调器会话时,直接从共享 SessionStore 读取其实时 maka_agent_authority::permissions::live 权限,不要被单实例 self.owns 拦截。
  2. Owner::respond_inner 将不存在/跨会话的 request_id 从领域 Rejected 退化为未类型化 RPC 错误(CI interactions 2 个测试挂点)

    • 原先 commit_response_unlocked(plugins/agent/native/src/owner/interactions.rs:116-140)在 request_id 不属于当前 session_id 时返回 Ok(InteractionResult::Rejected { reason: InteractionRejection::Unavailable })。
    • 现在 respond_inner(plugins/agent/native/src/owner/interactions/delegation.rs:108-110)提前调用 self.interaction(&input.session_id, &input.request_id).await?,导致缺失或跨会话 request_id 直接抛 Err("agent_interaction_unavailable")(打挂 native_form_validates_original_fields_and_commits_before_resuming 与 native_question_roundtrip_is_bound_owned_and_first_wins)。同文件 child_answered(delegation.rs:371, 423-427)也存在同样的 ? 裸抛问题。
  3. 只约束了 permissions,漏了同类的工具上限(tools)继承(权限绕过)

    • Owner::create(plugins/agent/native/src/owner.rs:782-864)、fork.rs:135-141 与 imports.rs:352-369 将 permissions 改成了继承真实调用方 scope.identity.agent(),但 tools 仍然取自 WorkspaceSelection::Session(若选 Directory、Project 或 IsolatedGit 则直接是 tools: None 全放开)。
    • 工具受限的非 Bot 子会话只需新建一个 Directory 子会话,就能获得无限制的全量工具。应排查 create/fork/import 所有同类路径,用调用方的实时工具上限约束子会话 tools。
  4. SessionEditQueue(editQueue)缺少归属校验,可篡改排队消息并保留原 MessageOrigin

    • products/maka/bundle/src/installation.ts:241-245 对所有 Agent 开放了 SessionEditQueue,但 plugins/agent/native/src/service.rs:1039-1046 与 owner/queue/controls.rs:148 无调用方身份/归属检查,且 platform/event-log/src/message_queue/edit.rs:94-112 在原地修改排队消息文本时保留了原 entry.source.message.origin(人类 None 或其他会话身份)。子会话可借此改写父会话里人类排队的指令并冒充人类来源。
    • 建议同步排查同类控制接口对非 Bot 子会话的父/兄弟越权边界:SessionChange(归档/删除)、SessionUpdate、SessionStop(notifications.rs:106 的 may_control 目前只限制了 Bot)以及 SessionResume。

2. 代码整洁度、类型建模与交互细节

  • 去掉 Postcard 兼容变体 RowDirectory::AttributedUser,直接合入 RowDirectory::User(plugins/agent/facts/src/history/semantic/directory.rs:65-68, 101-106):专门追加变体保留旧 Postcard 布局既增加了双分支维护负担,还漏加进了 codec/tests.rs:78-141 的全变体往返测试。内部语义缓存格式无需保留兼容分支,直接将 origin 合入 RowDirectory::User 更干净。
  • 用闭合的窄枚举替代 SessionApproval { answer: Box<InteractionAnswer> }(plugins/agent/facts/src/interaction.rs:174-180):实际只有 4 种放行动作会升级为父会话审批,直接包裹完整的 Box<InteractionAnswer> 让 Question、Form、Deny、递归 SessionApproval 等非法状态在类型与 Schema 中均可表示,迫使 SessionApprovalRequest.tsx:48-209 和 InteractionComposer.tsx:272-283 多写了约 90 行永远走不到的防御分支与死翻译词条。
    • 另见 delegation.rs:147, 174-178:当人类点击 Deny child decision 后,input.answer 已变为无需父授权的 Deny,此时若父会话 permission_basis 恰好变动,仍会被误拒为 AuthorizationChanged 导致人类的拒绝被丢弃。
  • rootsOnly: true 会隐藏停靠待处理的子会话交互(products/maka/workbench/app/browsing.ts:95, 154、platform/event-log/src/sessions/catalog.rs:173-177, 234-241):由于 SessionSend 是异步的,子会话完全可能在父轮次结束后才停靠在提问或审批上;NeedsYou 和待处理计数一刀切过滤 parentSessionId IS NULL 会导致用户漏看等待人工介入的子会话。
  • 避免 createMessageSenders 在流式热路径上全量扫行并永久缓存初始标题(Conversation.tsx:533-555、messageSenders.ts:43-67):Conversation.tsx 直接订阅 projection()(模型流式输出每个 token 都会触发),每次都 Array.from(projection().rowsById.values()) 全表扫描;且 messageSenders.ts 一次性缓存首次 observe 结果后,子会话后续自动生成的标题不会更新。
  • 优化 SessionApproval 滚动折叠体验(InteractionComposer.tsx:850, 904-938, 1109):当前将 Requested access 放在上方,导致关键的 Proposed child decision(如子会话拟授予 For this session)在 336px 限高容器内被折叠在首屏下方,而“批准”按钮无需滚到底即可直接点击。
  • 对齐混合来源轮次中人类消息的溯源头格式(plugins/agent/engine/src/executor.rs:171-175 vs user.rs:47-50):外部执行器将人类消息(origin: None)格式化为 [Message source (Host-provided): null],而原生模型路径对人类消息不加头,建议统一。

3. 测试整洁度

  • 后端测试(plugins/agent/native/src/owner/tests/session_parent_authority.rs、plugins/agent/engine/src/production_tests.rs):非常整洁,纯行为驱动、零 sleep。建议补充 3 个关键回归场景:(a) 跨实例 WorkHub(wh_...)调用方创建子会话;(b) 人类在 SessionApproval 上点击 Deny(含停靠期间父权限并发变更);(c) 子交互提前结算触发 ChildSettled 自动撤回。
  • 桌面端 GPUI 测试(products/maka/desktop/tests/desktop_new_session.rs:1753-1959):虽然没有 sleep,但把 5 个独立行为塞进了串行(-j 1)套件的一个 207 行大测试里,用底层 store.create_session 绕过了真实 SessionCreate,依赖硬编码像素滚轮(px(-500.0))和坐标断言(bounds.left() >= px(768.0)),且每次 CI 运行都会无条件向磁盘写出 4 张 PNG(desktop.artifact(...))。

4. 与 #6617 合入联动的互踩提醒

  • 两边同时修改了 products/maka/bundle/src/installation.ts 和 packages/plugin-sdk/src/contracts.ts(含生成的 SDK 文件),存在合并冲突。
  • 两处编译不报错但运行时/语义互踩的地方:
    1. 本 PR 在 desktop_new_session.rs:1795-1819 新增的测试向 send / SessionSend 传了 "model": fixture.selection,与 #6617 合并后编译能过、运行时直接报 'model' was unexpected。
    2. #6617 的 plugins/agent/native/src/executor/oar/history.rs:71-133 跨后端拼接历史轮次时未携带 MessageOrigin,会导致本 PR 的跨会话发送者身份溯源在切换到 OAR 续跑时静默丢失。

Automated review generated by Antigravity.

Resolve real caller policy across Agent instances and durable coordinator dispatch, bound derived tool ceilings, and restrict queued message edits to their true author. Preserve typed interaction rejection and committed human denial, narrow escalation answers, and keep pending children discoverable without restoring them to normal sidebar roots.

Add targeted authority, settlement, persistence and real desktop workflow regressions; preserve existing WorkHub task controls and explicit service-approval semantics rather than introducing a global session ACL.

Generated-by: Maka
Complete the Browsing fixture with needsYouCount and resolve test clicks from button centers instead of flooring their top-left bounds outside the hit target.

Generated-by: Maka
@M4n5ter
M4n5ter merged commit 5986e21 into rust-preview Nov 4, 2026
13 checks passed
@M4n5ter
M4n5ter deleted the feat/session-parent-authority branch November 4, 2026 07:20
M4n5ter added a commit that referenced this pull request Nov 4, 2026
Resolve merge conflicts with #6566 and #6618 across installation tool
descriptions, generated SDK contracts and multi-platform notice digests,
and migrate newly merged delegation and queue authorship tests to
BackendPreference.

Generated-by: Antigravity
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.

1 participant