Skip to content

[Bug] ReadSessionContext 的 sessionId 仅接受 sess_*,无法读取新格式 session_* 会话 #1264

Open

Description

@hjyescut

提交前确认 · Pre-submission checklist

  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.

问题类别 · Category

工具调用 / MCP · Tool use / MCP

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

影响体验 · Major (功能可用但体验受损 / works but degraded)

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

内置工具 ReadSessionContext 的 sessionId 参数校验正则仍按旧会话 ID 体系,写死为 (?:current|sess_[A-Za-z0-9._-]+),而当前会话存储已使用新格式 session_<32位hex>。结果是新格式会话完全无法通过该工具读取:传真实 ID 被参数校验拒绝,把前缀改成 sess_ 则查不到记录。

本机 session 表实测三种 ID 并存:session_<hex> 12 条、sess_<uuid> 82 条、sess_subagent_<uuid> 263 条。历史调用记录中,旧 sess_ 会话 10 次全部成功,新 session_ 会话 0 次成功。

被读取的会话本身是正常的(377 条 message、1483 条 part,当天可正常 resume),因此不是会话损坏或 ID 拼写问题。

影响:跨会话接力/续作入口对当前主力会话失效;且错误文案会引导用户把 session_ 改成 sess_,得到误导性的「not found」,容易被误判为会话丢失。

建议修复:

  1. 校验放宽为 (?:current|sess_[A-Za-z0-9._-]+|session_[A-Za-z0-9]+);
  2. 查询时对 sess_ / session_ 前缀做归一化(或直接按 session 表主键精确匹配);
  3. 区分「ID 格式不合法」与「会话不存在」两类错误。

复现步骤 · Steps to reproduce

  1. 在 ZCode Desktop 中取得一个当前格式的会话 ID,形如 session_c74c27580763137d8fc5f486b934b4ce。
  2. 在另一会话中调用内置工具 ReadSessionContext,sessionId 填该 ID,strategy: "relevant"。
  3. 返回参数校验错误:Session id must be current or use the sess_* format.(validation: regex / code: invalid_string)。
  4. 仅将前缀替换,改为 sess_c74c27580763137d8fc5f486b934b4ce 后重试。
  5. 返回 Session sess_c74c27580763137d8fc5f486b934b4ce was not found.

期望表现 · Expected behavior

ReadSessionContext 能接受并使用当前存储层的真实 ID 格式 session_<hex>,正常返回该会话的上下文;若确实不存在该会话,应明确区分「ID 格式不支持」与「会话不存在」,而不是在两种情况下都失败。

实际表现 · Actual behavior

两种写法都读不到:

  • 传 session_<hex>:参数校验阶段即被正则拒绝,工具未执行查询。
  • 传 sess_<hex>:通过校验,但查询返回 not found(数据库主键是 session_<hex>)。

此外,错误文案 Session id must be current or use the sess_* format. 会引导用户改成 sess_,改了反而必然失败。

ZCode 版本 · ZCode version

3.16.3.8992(CLI core 0.17.0)

设备 / 系统 / 浏览器 · Device / OS / Browser

Windows 10.0.19045 x64 / ZCode Desktop 3.16.3.8992

截图 / 录屏 / 日志 · Screenshots / Recordings / Logs

本机 tool_usage / part 表记录的调用结果:

  • 2026-10-27 16:41:48 strategy=handoff → Session sess_c74c27580763137d8fc5f486b934b4ce was not found.
  • 2026-10-27 16:41:53 strategy=relevant → 同上
  • 2026-10-27 09:02:27 sess_ddd4d6659d7b1a24fb7de2e307e796ca → not found(真实 ID 为 session_ddd4d6659d7b1a24fb7de2e307e796ca)

参数校验原始返回:

[{"validation":"regex","code":"invalid_string","message":"Session id must be current or use the sess_* format.","path":["sessionId"]}]

参考:打包产物 resources/glm/zcode.cjs 中可检索到正则 (?:current|sess_[A-Za-z0-9._-]+),与上述报错文案对应。

Activity

  1. github-actions commented on Oct 27, 2026

    @github-actions

    👋 感谢你的反馈,我们已经收到。

    • 维护者看到后会尽快回复你。
    • 状态保持为 status: 待评估,你可以随时补充信息。
    • 信息不全时我们会打上 needs: 更多信息 标签并 @ 你。

    👋 Thanks — we've received your issue.

    • A maintainer will get back to you as soon as we can.
    • Status stays at status: 待评估 (Triage); feel free to add context.
    • If we need more details, we'll add needs: 更多信息 and ping you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions