Repository navigation
Description
概述
在通过 Liii STEM / Mogan 的无头模式(liiistem -headless)进行文档加载、会话求值(Goldfish session evaluation)、排版刷新(update-document)以及自动化测试时,总结发现了以下 4 个关键问题。其中包含 2 个可直接稳定复现的 SIGSEGV Crash 以及 2 个逻辑行为异常。
问题一(Crash / SIGSEGV):对原子节点(atomic tree)调用 (tree-children t) 引发段错误崩溃
严重级别
高(直接 Core Dump 崩溃退出)
复现步骤(命令行一行复现)
/opt/liii-stem/bin/liiistem -headless -x '(begin (display (tree-children (stree->tree "hello"))) (quit-TeXmacs))' -q实际行为
进程立即收到 SIGSEGV (segmentation fault) (11) 并核心转储退出:
Process terminated by signal: SIGSEGV (segmentation fault) (11)
Backtrace of C++ stack:
/opt/liii-stem/bin/liiistem(+0x376b83) [0x56494178ab83]
/lib/x86_64-linux-gnu/libc.so.6(+0x3fd70) [0x7fa3e3c4bd70]
/opt/liii-stem/bin/liiistem(+0x12be85a) [0x5649426d285a]
根本原因定位
在 C++ 端,tree_rep 区分复合节点(compound tree)与原子叶子节点(atomic tree / string tree)。对原子节点调用 tree-children 时,底层缺少 is_atomic 前置防御检查,直接访问未初始化的 children 容器或空指针解引用,导致非法内存访问崩溃。
期望行为
对原子节点调用 (tree-children t) 时,应当安全返回 '()(空列表),或者抛出可被 Scheme catch 捕获的异常,绝不应导致 C++ 宿主进程崩溃。
问题二(Crash / SIGSEGV):headless 模式下调用 (connection-eval ...) / (plugin-eval ...) 同步求值触发段错误
严重级别
高
复现步骤(命令行一行复现)
/opt/liii-stem/bin/liiistem -headless -x '(begin (use-modules (utils library tree)) (use-modules (utils plugins plugin-eval)) (plugin-eval "goldfish" "default" (stree->tree (list (string->symbol "document") "(+ 1 2)"))) (quit-TeXmacs))' -q实际行为
Process terminated by signal: SIGSEGV (segmentation fault) (11)
根本原因定位
plugin-eval 底层调用 connection_eval,其实现会直接调用 con->read(LINK_ERR) 和 con->read(LINK_OUT)。在 headless 模式下(使用 QTMCoreApplication 且缺少独立 Qt 消息循环驱动),跨进程 pipe 读写同步阻塞时,若连接未完全就绪或缺少有效缓冲保护,会导致空指针/内存越界解引用崩溃。
期望行为
connection_eval 在 headless 模式下应具备连接就绪判断与超时异常处理机制,通信失败时抛出错误或返回空结果,而非段错误。
问题三(Bug / 行为不一致):headless 模式下会话 Cell 的 Prompt 错误回退为 "Goldfish] "
表现现象
在 headless 模式下加载 buffer 并执行 (session-evaluate) 求值时,生成的会话 Cell 的 Prompt(输入左侧的提示符)会被改写为字符串 "Goldfish] ";而在 GUI 界面下交互按回车求值时,Prompt 标准格式为 (document "> ")。
原因定位
TeXmacs/progs/utils/plugins/plugin-eval.scm:287 中的 plugin-prompt 函数:
(tm-define (plugin-prompt lan ses)
(with p
(ahash-ref plugin-prompts (list lan ses))
(if p (tree-copy p) (string-append (upcase-first lan) "] "))
) ;with
) ;tm-define在 headless 异步模式下,Goldfish 子进程握手阶段的 prompt 通知可能尚未同步到 plugin-prompts 哈希表中,导致 plugin-prompt 错误触发了 fallback:(string-append (upcase-first lan) "] "),生成了 "Goldfish] " 并被写回文档节点 (tree-set out :up 0 ...)。
期望行为
应当允许插件注册静态默认 prompt(例如 Goldfish 默认应为 (document "> ")),或者在 fallback 分支中按插件配置匹配,避免批处理或 headless 执行时污染文档结构。
问题四(Bug):headless 模式下执行 (update-document "all") 报错 unbound variable: set-cursor-style
复现步骤(命令行一行复现)
/opt/liii-stem/bin/liiistem -headless -x '(begin (use-modules (generic document-edit)) (update-document "all") (quit-TeXmacs))' -q实际行为
抛出未捕获的 Scheme 错误,导致批处理执行中断:
Error: unbound-variable in (set-cursor-style "wait")
原因定位
TeXmacs/progs/generic/document-edit.scm:606 中:
(tm-define (update-document what)
(set-cursor-style "wait")
...
(delayed (:idle 1) (set-cursor-style "normal")))set-cursor-style 是纯 GUI 的鼠标指针样式修改函数,在 headless 模式下未定义或未导出。
期望行为
在 headless 模式下为 set-cursor-style 自动提供 noop 空实现,或者在 document-edit.scm 中增加 (when (defined? 'set-cursor-style) ...) 守卫。
环境信息
- 版本:Liii STEM 2.1.4 (build 2026-09-29)
- 内核:S7 Scheme + Qt6
- 平台:Linux x86_64
Activity