Skip to content

fix(runtime): tighten WriteStdin delivery semantics and ref validation - #965

Merged
Astro-Han merged 3 commits into
apache:mainfrom
M4n5ter:fix/856-write-stdin-contract
Jul 14, 2026
Merged

Astro-Han merged 3 commits into
apache:mainfrom
M4n5ter:fix/856-write-stdin-contract

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Jul 14, 2026

Copy link
Copy Markdown
Member
English

Part of #856.

Summary

  • Rename PTY input operation results from applied to queued, matching the guarantee exposed by node-pty.write().
  • Validate WriteStdin.ref with the canonical ShellRun resource parser and expose a schema length bound derived from the canonical format.
  • Keep the human-facing ref projection independently bounded without duplicating URI parsing rules.

Why

A non-throwing node-pty.write() only establishes that the driver accepted the input into its asynchronous path. It cannot prove that the child process received or consumed every byte, so applied overstated the observable guarantee.

Runtime already owns the canonical ShellRun resource format, but the public WriteStdin schema previously accepted any unbounded string. This allowed malformed refs to reach authorization and left human-facing projections unbounded.

Design

Decision Rationale
Set queued: true only after driver.write() returns without throwing. The result describes the exact driver handoff point without claiming end-to-end delivery.
Remove the old input applied shape instead of supporting both names. Maka has no compatibility requirement for this unreleased contract, so one precise result shape is clearer.
Require parser input to round-trip through the canonical ref factory. URL normalization aliases such as dot segments cannot silently resolve to another task.
Derive schema maxLength from the fixed prefix and ShellRun ID bound. The public boundary follows the canonical format instead of maintaining a second magic number.
Bound activity projection separately and stop scanning after its preview limit. Human-facing payloads remain bounded even when malformed data bypasses schema validation, without moving URI knowledge into Core.

Resize keeps its existing applied and changed semantics because it has a separate observable driver contract.

Scope

This PR changes only the WriteStdin runtime result, canonical ref validation, and their CLI/UI projections. The permission-boundary work remains a separate PR under #856.

It does not add compatibility aliases, expectedRevision, permission changes, PTY lifecycle changes, dependencies, CI, or documentation changes.

Verification

The integrated branch passes the root typecheck, full test suite, and production build. Tests cover the public result parser, provider-facing schema bound, malformed and oversized refs, bounded projection, and the existing real PTY write/resize/FIFO/exit paths. The final correctness and maintainability reviews reported no remaining findings.

简体中文

#856 的一部分。

摘要

  • 将 PTY 输入操作结果从 applied 重命名为 queued,使其与 node-pty.write() 能提供的保证一致。
  • 使用 canonical ShellRun resource parser 校验 WriteStdin.ref,并在 schema 中暴露由 canonical 格式推导的长度上限。
  • 让人类可见的 ref 投影独立保持有界,同时不复制 URI 解析规则。

原因

node-pty.write() 未抛异常只能证明 driver 已将输入接入异步路径,不能证明子进程已经收到或消费每个字节,因此 applied 超出了实际可观察保证。

Runtime 已经拥有 canonical ShellRun resource 格式,但公开的 WriteStdin schema 之前会接受任意无界字符串。这会让畸形 ref 进入授权流程,也会使人类可见投影失去边界。

设计

决策 理由
仅在 driver.write() 无异常返回后设置 queued: true。 结果精确描述 driver handoff,不声称已经端到端送达。
删除旧 input applied shape,不同时支持两个名称。 Maka 尚未发布,不存在兼容要求;保留一个精确 shape 更清晰。
要求 parser 输入能够通过 canonical ref factory 原样 round-trip。 Dot segment 等 URL normalization alias 不能静默解析为另一个任务。
由固定 prefix 和 ShellRun ID 上限推导 schema maxLength。 公开边界跟随 canonical 格式,不维护第二个 magic number。
独立限制 activity 投影,并在达到预览上限后停止扫描。 即使畸形数据绕过 schema,人类可见 payload 仍保持有界,同时 Core 不需要了解 URI 规则。

Resize 保留既有的 applied 与 changed 语义,因为它具有独立的可观察 driver 契约。

范围

本 PR 只修改 WriteStdin runtime 结果、canonical ref 校验及其 CLI/UI 投影。Permission boundary 仍作为 #856 下的另一个独立 PR。

本 PR 不增加兼容别名、expectedRevision、权限改动、PTY 生命周期改动、依赖、CI 或文档修改。

验证

集成分支已通过根级 typecheck、完整测试与生产 build。测试覆盖公开结果 parser、provider-facing schema 上限、畸形与超长 ref、有界投影,以及既有的真实 PTY write/resize/FIFO/exit 路径。最终正确性与可维护性复审均无遗留 finding。

@Astro-Han
Astro-Han merged commit 9250ca4 into apache:main Jul 14, 2026
3 checks passed
@M4n5ter
M4n5ter deleted the fix/856-write-stdin-contract branch August 5, 2026 13:31
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