Repository navigation
fix(runtime): preserve canonical tool argument ownership - #884
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
No blocking code findings on the current head.
GitHub currently reports merge conflicts. Please rebase onto the latest main and preserve the existing separation between permission, execution, persisted, and event arguments while resolving them. The resolved diff may need another look.
f763ec4 to
08b0a10
Compare
English@Astro-Han I rebased this branch onto the latest The resolved implementation preserves the separation you called out:
I also corrected the PR description so it no longer implies that persisted/event arguments are raw canonical data. Local build, root typecheck, and the complete Runtime suite pass on the rebased head; GitHub typecheck, test, and e2e CI also pass. 简体中文@Astro-Han 我已将该分支 rebase 到最新 冲突解决后的实现保留了你指出的分层边界:
我也修正了 PR 描述,不再暗示持久化或事件参数是未经 projection 的原始 canonical 数据。Rebase 后的本地 build、根级 typecheck 与完整 Runtime 测试均已通过,GitHub typecheck、test 与 e2e CI 也已通过。 |
English
Follow-up to #856.
Summary
permission_requestortool_startframe authoritative for atoolUseId, and fail closed if a later frame changes the tool name or arguments.tool_startframe before awaiting assistant persistence, so transport-owned mutation cannot rewrite or conceal frame drift.Why
Tool arguments currently cross several independently owned and potentially asynchronous consumers. Sharing one mutable object lets an event listener, permission consumer, sandbox resolver, storage callback, or tool implementation change what another consumer observes or what eventually executes.
Pi has a related transport boundary: permission and start frames can describe the same call at different times. Without one canonical value per
toolUseId, history, authorization, events, and execution can diverge even though they appear to refer to one invocation.Key decisions
tool_startframe before the first asynchronous persistence boundary.Scope
Included:
Not included:
WriteStdininspection, turn-memory, or runtime-resource contract changesVerification
npm run buildandnpm run typecheckpassed.git diff --check upstream/main...HEADpassed.No visual evidence is applicable because this change has no intended UI or interaction change.
Impact
Tool providers and Runtime consumers receive ordinary mutable values, but mutations are now local to that owner. Existing redaction and approval-summary projections are unchanged; persisted history, permission facts, renderer events, sandbox decisions, and execution can no longer rewrite one another through shared references.
There is no schema migration, compatibility layer, dependency change, documentation requirement, or release-note impact.
Reviewer notes
The highest-value review boundaries are:
tool-runtime.ts: where the private snapshot is created and where ownership is transferred.pi-agent-backend.ts: first-frame authority, suppressed calls, and persistence ordering.ai-sdk-flow.ts: transferring projected session-event arguments into independently owned Runtime events.Ready for review
简体中文
#856 的后续改进。
摘要
toolUseId首个被接受的permission_request或tool_start帧成为权威值;后续帧若改变工具名或参数则 fail closed。tool_start帧,避免 transport 持有的对象被修改后改写首帧或掩盖帧漂移。原因
工具参数会跨越多个彼此独立、且可能异步运行的消费者。共享同一个可写对象后,event listener、权限消费者、sandbox resolver、存储回调或工具实现都可能改变其它消费者看到的值,甚至改变最终执行内容。
Pi 还有一层对应的 transport 边界:permission 与 start 帧可能在不同时间描述同一调用。如果没有按
toolUseId唯一确定的 canonical 值,历史、授权、事件与执行可能发生漂移,尽管它们表面上都指向同一次调用。关键决策
tool_start帧。范围
包含:
不包含:
WriteStdin检查、turn memory 或 runtime-resource 契约变更验证
npm run build与npm run typecheck通过。git diff --check upstream/main...HEAD通过。本次没有预期的 UI 或交互变化,因此不适用视觉证据。
影响
工具 provider 与 Runtime 消费者仍会收到普通可写值,但任何修改只影响该所有者。既有脱敏与 approval-summary projection 保持不变;持久化历史、权限事实、renderer event、sandbox 决策和执行不再能通过共享引用相互改写。
本次没有 schema migration、兼容层、依赖变更、文档要求或 release-note 影响。
审查重点
最值得审查的边界是:
tool-runtime.ts:私有快照的建立位置和所有权转移位置。pi-agent-backend.ts:首帧权威、suppressed call 与持久化顺序。ai-sdk-flow.ts:把经过 projection 的 session-event 参数转移给独立所有的 Runtime event。可供审查