Skip to content

fix(prompt): fold E400 literal-char pairs in the prompt transport decode (Refs #3038) - #3072

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3038-expand-prompt-e400-pair
Nov 8, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3038-expand-prompt-e400-pair

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

UNVERIFIED-BY-CAPTAIN — 车道自报,待队长复核。

现象(Refs #3038)

经公开 API Session::expand_prompt:pua=$'\uE314' 后 expand_prompt("<$pua>") 返回 "<\u{E400}\u{E314}>"——E400 字面对转义对漏进渲染后的提示串;GNU 渲染原始字符 "<\u{E314}>"。

根因

decode_prompt_transport(src/executor/prompt_expansion.rs)是提示通道的展开后传输解码,但它的存在性门只查原始字节标记族(U+E000 引导符)。展开结果只携带 E400 字面对(存储的注册区字符,如 $'\uE314',经 push_literal_char 以 E400+E314 承载)时,门不开、解码不跑,整对原样漏出。也就是说:E400 对折不折,取决于同一提示串里是否恰好有无关的原始字节对在场——$esc/$tab 等腿因同格其他内容或守卫消费者而通过,$pua 单独出现时漏。

解码器本体没有缺陷:decode_raw_byte_markers 本就无条件折叠 E400+c。缺的是门。

GNU 锚点

  • parse.y:6265 decode_prompt_string + parse.y:6689:展开通道以 expand_prompt_string(result, Q_DOUBLE_QUOTES, 0) 把存储值字节逐字插入提示串——GNU 在存储与渲染之间没有转义对层。
  • parse.y:5694-5706:CTLESC 保护纯属 token 内部机制;subst.c:4692 dequote_escapes 在任何边界之前去除。rubash 的 E400 对是同一内部传输,渲染边界必须同样折叠。
  • 探针(GNU bash 5.3.20,LC_ALL=C.UTF-8,脚本文件):pua=$'\uE314'; printf '<%s>\n' "$pua" 输出字节 3c ee 8c 94 3e 0a——原始字符逐字出。

修法(按机制,一处门 + 一个 markers 助手)

  • markers.rs 新增 contains_decodable_transport:同时覆盖解码器折叠的两个传输族(原始字节对 + E400 字面对)的存在性门——检查本身不做任何变换,命中才路由进 pair-aware 解码器。
  • decode_prompt_transport 改走该门,并更新其文档注释说明 E400 半边与本单来历。
  • E7 marker-lint 处置:新门先按原始写法落在 prompt_expansion.rs 时被 lint 判为未审 contains 站点,按 lint 指引改为经 markers.rs 助手路由(未加 allowlist 条目);旧门行对应的 allowlist 条目随之 stale,按 lint 要求删除一行(站点数 258 → 257)。
  • 影响面:decode_prompt_transport 的四个调用点全是终端向提示渲染通道(expand_prompt_string{,_mut}、PS4 的 xtrace_prefix、read -p 显示);脚本可见的 ${var@P} 变换不经此漏斗,不受影响。本 PR 不动解码器本体、不动其他调用面逻辑。

回归钉

tests/marker_leak_golden.rs 的 prompts_via_public_api_carry_no_markers 格:

  • $pua 腿原本是 inverted pin(断言错误输出 "<\u{E400}\u{E314}>"),现改回正确断言 "<\u{E314}>"。
  • 新增门独立性腿:同一值同时携带两种传输(E400 对 + ESC 原始字节对)时两者都渲染为原始字符,钉住「折叠不依赖无关内容在场」的不变式。
  • fail-first(基底 4984ce5c,仅改断言未修码):该格按预期翻红,left: "<\u{e400}\u{e314}>" vs right: "<\u{e314}>",与 issue 正文逐字一致。

车道自报验证(基底 4984ce5,构建走 build-slot + scrubbed_cargo)

本 PR 删除了什么

  • scripts/marker-lint-allowlist.txt 中旧门行的一行 stale 条目(contains:RAW_BYTE_MARKER_ESCAPE @ prompt_expansion.rs)——该站点已被 markers 助手取代,条目不再匹配任何代码。
  • golden 格中 inverted pin 的错误断言与 KNOWN BROKEN 注释(改为正确断言)。
  • 无其他删除;无产品行为面被移除。

净行数:+39 / −11(净 +28)。

队长复核项

  • 移植 fail-first:把钉提交 7b32ac82 的 tests 改动移到基底树,prompts_via_public_api_carry_no_markers 应以 left "<\u{e400}\u{e314}>" 翻红。
  • 头树重跑 golden 全茎 + PTY 茎 + lib,核对失败名集合与基底一致(为空集)。
  • 顺带核 PS4 / read -p 通道:同一漏斗同一门,$'\uE314' 值经 PS4 前缀与 read -p "$pua" 显示应同样渲染原始字符(车道未单独钉这两条通道,格覆盖在 golden 的 PS4 格与 PTY read_p 格的既有形状内)。

…red U+E314 value

The $pua leg of prompts_via_public_api_carry_no_markers was an
inverted pin asserting the broken rendering "<\u{E400}\u{E314}>"
(the E400 literal-char pair surviving into the rendered prompt).
GNU renders the stored char verbatim: parse.y:6265
decode_prompt_string + parse.y:6689 expand_prompt_string insert the
stored value bytes as-is; there is no escape-pair layer between
storage and render.

Correct the leg to assert "<\u{E314}>" and add a gate-independence
leg: a value carrying both transports (E400 pair for the typed char,
raw-byte pair for an ESC byte) must render both raw.

Fail-first on base 4984ce5: the corrected cell fails with
left "<\u{e400}\u{e314}>" vs right "<\u{e314}>". Refs #3038
…ode (Refs #3038)

decode_prompt_transport gated its decode on the raw-byte marker
(U+E000) alone, so an expansion result whose only transport was an
E400 literal-char pair — a stored registry-zone char such as
$'\uE314', carried as E400+E314 by push_literal_char — was returned
verbatim and the pair leaked into the rendered prompt. Whether the
pair folded depended on an unrelated raw-byte pair happening to be
present in the same prompt.

GNU has no escape-pair layer between storage and prompt render:
parse.y:6689 expand_prompt_string(result, Q_DOUBLE_QUOTES, 0) inserts
the stored value bytes verbatim, and the CTLESC protection of
parse.y:5694-5706 is token-internal, removed by subst.c:4692
dequote_escapes before any boundary.

Fix the gate, not the decoder: decode_raw_byte_markers already folds
E400+c to c; open the gate on either transport family. All four
callers of decode_prompt_transport are terminal-bound prompt render
channels (expand_prompt_string{,_mut}, xtrace_prefix for PS4,
read -p display); the script-visible ${var@P} transform does not
funnel through here and is unaffected.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 8, 2026 04:11
@caomengxuan666
caomengxuan666 merged commit 1d5be81 into master Nov 8, 2026
11 checks passed
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