Skip to content

[Bug]: non-string LLM session variables panic Starlark procedures #29154

Closed

Description

@Ariznawlll

Environment

  • MatrixOne commit: 56f7d1eae392b5f3de33e1ea43c916956c50b833
  • Topology: local distributed deployment, 1 LOG / 1 TN / 2 CN
  • Reproducibility: integer and NULL variants each reproduced 3/3 on CN1 and 3/3 on CN2

Problem

Starlark LLM helpers perform an unchecked Go type assertion when reading @llm_model and related session variables. A non-string value or NULL reaches the client as an internal recovered panic instead of a validated SQL/Starlark error.

Reproduction

The echo model is local and avoids any external model or network dependency.

create database if not exists starlark_llm_bug;
use starlark_llm_bug;

create procedure p_llm(in q varchar, out o varchar) language 'starlark'
$$
mo.llm_connect("", "", "", "")
reply, err = mo.llm_chat(q)
out_o = err if err != None else reply
$$;

-- Valid control
set @llm_model='echo';
call p_llm('[{"role":"user","content":"local-ok"}]', @o);
select @o;

-- Failure variants
set @llm_model=1;
call p_llm('x', @o);

set @llm_model=null;
call p_llm('x', @o);

Actual result

The string control returns local-ok. The two invalid values return internal errors containing recovered Go panics:

panic interface conversion: interface {} is int64, not string
panic interface conversion: interface {} is nil, not string

Both CN sessions remain usable after the errors, but internal implementation details and stack frames are exposed to the SQL client.

Expected result

The helper should validate or explicitly convert the session-variable value. Unsupported values should produce a stable argument/type error, never a Go panic.

Code evidence

pkg/frontend/starlark_interpreter.go function llmGetVar returns value.Value.(string) without checking the dynamic type. llmConnect calls this path for llm_server, llm_addr, llm_model, and llm_options, so all four variables share the same risk.

Regression-test placement

Add a small Starlark procedure test covering string, numeric, boolean, binary, and NULL session-variable values. This is deterministic MOTR/procedure coverage and does not require big-data, stability, or chaos.

Activity

  1. added this to the MO-202609 milestone on Sep 20, 2026
  2. added
    kind/bug
    on Sep 20, 2026
  3. added theissue type on Sep 20, 2026
  4. self-assigned this
    on Sep 20, 2026
  5. added 2 commits that reference this issue on Oct 11, 2026
    a208c72
    1f53fc8
  6. Ariznawlll commented on Oct 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main;commit:02a2823c2007d5e4fb4ada148e93743df337551a;日期:2026-10-12。
    • 部署:本地独立单 CN / 单 TN / 单 LogService;Starlark 存储过程使用本地 echo 模型,不访问外部 LLM 服务。

    原问题验证

    沿用原 issue 的 mo.llm_connect / mo.llm_chat 存储过程。将 @llm_model 设为整数 1 和 NULL,连续 3 轮分别返回明确的 must be a string, got int64、invalid model 消息;不再返回 Go panic interface conversion。每次异常后连接 SELECT 1 正常。

    Happy Path 覆盖

    @llm_model='echo' 且输入合法 JSON 时,3/3 返回 local-ok。对其余三个变量 @llm_server、@llm_addr、@llm_options 使用 NULL 时,本地 echo 仍可正常返回,均无 panic。

    Unhappy Path 覆盖

    四个 LLM session 变量分别设为整数和布尔值,3 轮 × 4 变量 × 2 类型均返回明确的类型错误,不暴露 panic;NULL 也逐变量覆盖。另测二进制字面量 x'0102':按当前会话变量的字符串解释路径处理,server / model 返回合法校验错误,addr / options 在 echo 模型下不影响结果;均无 panic。所有异常后连接仍可用。

    白盒验证

    验收重点是 session 变量的动态类型在 Starlark LLM helper 边界被安全处理,而非依赖外部模型服务的网络结果。未测试第三方 LLM 提供商或真实 API key。

    回归测试

    已加入 MOTR PR #229 的 Starlark 脚本回归;包含本地 echo、四变量整数/布尔/NULL、会话恢复,compare 3/3。二进制字面量在本次独立扩展测试覆盖。无需 big-data。

    测试证据

    • 本地原 SQL 与扩展矩阵均重复 3 轮,未再出现 panic;异常后 SELECT 1 正常。
    • MOTR 脚本和 golden:compare 3/3。

    测试结论

    测试通过。

  7. Ariznawlll commented on Oct 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    回归归档:本 issue 在 MatrixOne main 02a2823c2007d5e4fb4ada148e93743df337551a 上的原问题、正常与边界/异常路径已有上方详细验证记录,MOTR 对应用例本地 compare 3/3 通过。回归 PR https://github.com/matrixorigin/motr/pull/229 已合入(merge commit 0ed4301b164aa42d0affa0dc27e17f7435b7bf04)。据此关闭本 issue;本次关闭未增加先前评论未覆盖的验收范围。

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions