You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by wy...@apache.org on 2026/10/20 05:38:22 UTC

(maka) branch rust-preview updated: fix(terminal): finish retained display streams once

This is an automated email from the ASF dual-hosted git repository.

M4n5ter pushed a commit to branch rust-preview
in repository https://gitbox.apache.org/repos/asf/maka.git


The following commit(s) were added to refs/heads/rust-preview by this push:
     new 2b6b171dbf fix(terminal): finish retained display streams once
2b6b171dbf is described below

commit 2b6b171dbff1178e7b31f89ff78b8814044a377d
Author: Wang <m4...@gmail.com>
AuthorDate: Tue Oct 20 13:38:14 2026 +0800

    fix(terminal): finish retained display streams once
    
    Return the display End only as the final subscription result, preserving
    Session, cancellation and drain checks before completion. Native Desktop
    already delivers non-null final results, so emitting End as well consumed
    the retained display assembly twice.
    
    Require the exact final End in the real retained-display regression and
    document the streamed-items/final-result boundary in both API guides.
    
    Generated-by: Codex
---
 plugins/agent/native/src/owner/tests/terminal.rs               | 10 ++++++----
 plugins/workspace/api/README.md                                |  2 +-
 plugins/workspace/api/README.zh-CN.md                          |  2 +-
 .../workspace-processes/native/src/terminal/display.rs         |  9 ++++++++-
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/plugins/agent/native/src/owner/tests/terminal.rs b/plugins/agent/native/src/owner/tests/terminal.rs
index f4e8818b53..8ef87eef29 100644
--- a/plugins/agent/native/src/owner/tests/terminal.rs
+++ b/plugins/agent/native/src/owner/tests/terminal.rs
@@ -657,7 +657,6 @@ async fn terminal_styled_display_survives_retirement_cancel_and_host_reopen_beyo
     async fn read_display(f: &Fixture, owner: &Caller, target: &Value) -> Display {
         let mut stream = subscribe(f, owner, "readDisplay", target.clone()).await;
         let mut assembly = None;
-        let mut display = None;
         while let Some(item) = stream.recv().await {
             assert!(
                 serde_json::to_vec(&item).unwrap().len()
@@ -677,13 +676,16 @@ async fn terminal_styled_display_survives_retirement_cancel_and_host_reopen_beyo
                     );
                 }
                 Part::Rows { parts } => assembly.as_mut().unwrap().rows(parts).unwrap(),
-                Part::End => display = Some(assembly.take().unwrap().finish().unwrap()),
+                Part::End => panic!("display End must be the final result, not a streamed item"),
             }
         }
         let done = stream.completion().await;
         done.cleanup.unwrap();
-        assert_eq!(done.result.unwrap()["kind"], "completed");
-        display.unwrap()
+        assert_eq!(
+            done.result.unwrap(),
+            json!({"kind": "completed", "value": {"kind": "end"}})
+        );
+        assembly.unwrap().finish().unwrap()
     }
     tokio::time::timeout(Duration::from_secs(90), async {
         let (_, mut f, session) = processes::fixture().await;
diff --git a/plugins/workspace/api/README.md b/plugins/workspace/api/README.md
index 853135a71d..a3bf9b2d7c 100644
--- a/plugins/workspace/api/README.md
+++ b/plugins/workspace/api/README.md
@@ -28,7 +28,7 @@ Defines the shared contracts for workspace files, processes, terminals, protocol
 The Terminal contract exposes `readOutput` and `watchOutput` for complete ordered original PTY bytes (Base64) and native resize events retained by the original live resource. Adjacent Data records are combined within the 64 KiB encoded subscription Item budget (about 48 KiB of raw bytes, after envelope and Base64 overhead); there is no tail eviction. A Data sequence is the last consumed native record, so sequences can jump while every Resize stays separate. Keep `after` with its original [...]
 
 
-For a settled PTY, `readDisplay` is a finite subscription of one durable revision: `begin` carries geometry, cursor, palette and input-mode metadata; ordered `rows` carry styled physical cells; `end` completes the display. Stage parts privately and replace the visible display only at `end`; discard incomplete or canceled transfers. Desktop uses this after `watchOutput` reports `Unavailable`, preserving colors and styled blanks through retirement and Host restart. It never resumes a raw p [...]
+For a settled PTY, `readDisplay` is a finite subscription of one durable revision: `begin` carries geometry, cursor, palette and input-mode metadata; ordered `rows` carry styled physical cells; `end` completes the display. `begin` and `rows` are streamed items; the single `end` is the final successful subscription result. Stage parts privately and replace the visible display only at `end`; discard incomplete or canceled transfers. Desktop uses this after `watchOutput` reports `Unavailabl [...]
 
 Native history uses an 800,000-cell allowance (10,000 rows at 80 columns), adjusted before resize reflow. Geometry permits 2–1,024 columns and 1–1,024 rows, with at most 65,536 visible cells. The encoded display retains the current and last alternate viewports first, then newest whole history rows within 64 MiB; omitted history is marked truncated. These replace the old 500-row and 4 MiB whole-record limits. Existing text-only terminal records migrate once with their known text and defau [...]
 
diff --git a/plugins/workspace/api/README.zh-CN.md b/plugins/workspace/api/README.zh-CN.md
index 2e0fd3fc2a..5cba8f25fe 100644
--- a/plugins/workspace/api/README.zh-CN.md
+++ b/plugins/workspace/api/README.zh-CN.md
@@ -28,7 +28,7 @@
 Terminal 契约提供 `readOutput` 和 `watchOutput`,完整保留原 live resource 的有序 PTY 字节(Base64)及原生尺寸变化。相邻 Data 在 64 KiB 编码后订阅 Item 预算内合并(扣除封装及 Base64 开销后约 48 KiB 原始字节),资源持有期间保留全部事件。Data 的序号是最后一个已消费原始记录的游标,因此可跳号;每个 Resize 仍单独交付。`after` 必须与原始目标一起保留;已交付批次内部的原始游标也仍指向准确的后续字节。新 parser 直接订阅 `watchOutput(after: 0)`,按首个保留事件的 `initialSize` 初始化一次,再依序处理全部 Data/Resize;状态完整的 parser 可从已知序号继续。已取得的 reader 可在 worker 退休后排完数据,但退休或 Host 重启后的新接入返回 `Unavailable`;先前的 `readOutput` 不为后续请求保活。真实 replay I/O 错误使调用失败。保留的显示画面和纯文本屏幕都 [...]
 
 
-对于已结束的 PTY,`readDisplay` 是传输单个持久化 revision 的有限订阅:`begin` 提供尺寸、光标、调色板和输入模式元数据,按序的 `rows` 提供带样式的物理单元格,`end` 表示画面传输完成。接收方应暂存分片,仅在 `end` 后整体替换画面;未完成或已取消的传输直接丢弃。Desktop 在 `watchOutput` 返回 `Unavailable` 后使用它,保留退休及 Host 重启后的颜色和彩色空格,且不会从这些单元格继续原始 parser。`read`/`watch` 仍提供有界的纯文本模型预览,与显示保留量独立。
+对于已结束的 PTY,`readDisplay` 是传输单个持久化 revision 的有限订阅:`begin` 提供尺寸、光标、调色板和输入模式元数据,按序的 `rows` 提供带样式的物理单元格,`end` 表示画面传输完成。`begin` 和 `rows` 作为流条目发送,唯一的 `end` 作为订阅的最终成功结果返回。接收方应暂存分片,仅在 `end` 后整体替换画面;未完成或已取消的传输直接丢弃。Desktop 在 `watchOutput` 返回 `Unavailable` 后使用它,保留退休及 Host 重启后的颜色和彩色空格,且不会从这些单元格继续原始 parser。`read`/`watch` 仍提供有界的纯文本模型预览,与显示保留量独立。
 
 原生历史按 800,000 个单元格保留(80 列时为 10,000 行),在缩放重排前调整额度。尺寸允许 2–1,024 列、1–1,024 行,可见单元格总数不超过 65,536。编码后的显示数据优先保留当前和上次备用屏幕,再在 64 MiB 内保留最新的完整历史行;省略历史时标记 truncated。这替代了旧的 500 行及整条记录 4 MiB 限制。已有纯文本终端记录执行一次性迁移,保留已知文字并使用默认样式;过去已丢失的颜色无法恢复。资源策略见[显示类型](../../agent/facts/src/terminal/display.rs)和[原生尺寸](../../agent/facts/src/terminal.rs)。
 
diff --git a/plugins/workspace/workspace-processes/native/src/terminal/display.rs b/plugins/workspace/workspace-processes/native/src/terminal/display.rs
index 5d301835b5..b4791c524b 100644
--- a/plugins/workspace/workspace-processes/native/src/terminal/display.rs
+++ b/plugins/workspace/workspace-processes/native/src/terminal/display.rs
@@ -90,7 +90,14 @@ impl Processes {
             self.display_emit(&target, Part::Rows { parts }, context)
                 .await?;
         }
-        self.display_emit(&target, Part::End, context).await?;
+        // The non-null final result is the last part delivered to subscribers.
+        self.terminal_session(&target.session_id, false).await?;
+        if context.scope().cancellation.is_cancelled() {
+            return Err(failed("Terminal display cancelled"));
+        }
+        if self.drain.is_cancelled() {
+            return Err(failed("Process owner is draining"));
+        }
         completed(Part::End)
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org