Skip to content

fix(session): 修复 /session 标题长期为 New Session,并统一单行展示#534

Merged
pionxe merged 3 commits into1024XEngineer:mainfrom
creatang:codex/tui-scrollbar-thumb-only
May 1, 2026
Merged

fix(session): 修复 /session 标题长期为 New Session,并统一单行展示#534
pionxe merged 3 commits into1024XEngineer:mainfrom
creatang:codex/tui-scrollbar-thumb-only

Conversation

@creatang
Copy link
Copy Markdown
Collaborator

背景

/session 列表中大量会话标题显示为 New Session,且部分会话标题会出现多行显示,影响会话识别与选择效率。

根因

  1. 会话在部分链路下会先以默认标题 New Session 建档,但后续缺少稳定的“标题回填”机制。
  2. 标题规范化仅做了 TrimSpace,未折叠换行/制表符,导致列表出现多行标题。

变更内容

  1. 新增默认标题回填机制。
  • 当会话标题仍为 New Session 且存在有效用户输入时,自动将标题提升为首条有效用户文本摘要。
  • 在会话列表读取路径增加历史会话兜底回填,避免旧数据长期停留在默认标题。
  1. 新增最小粒度标题更新能力。
  • 在 session 存储层补充“仅更新标题”的更新路径,避免使用全量会话头更新带来的覆盖风险。
  1. 标题统一单行化。
  • 在标题规范化阶段将所有空白(含换行、Tab)折叠为单个空格。
  • /session picker 渲染层做二次兜底,确保历史脏数据也只展示单行。

影响范围

  • internal/session
  • internal/runtime
  • internal/tui/core/app

测试

已补充并通过相关单测:

  • 默认标题回填逻辑测试
  • 非默认标题不覆盖测试
  • 多行标题规范化为单行测试
  • session picker 单行渲染测试

本地验证:

  • go test ./internal/session
  • go test ./internal/tui/core/app -run ...
  • go build ./cmd/neocode

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed in 4 passes (code quality, performance, security, docs). One noteworthy issue found after deduplication.

summaries, err := s.sessionStore.ListSummaries(ctx)
if err != nil {
return nil, err
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListSessions now conditionally calls LoadSession per default-titled summary, which introduces an N+1 read pattern (ListSummaries + up to N LoadSession calls). On larger history sets this can noticeably increase latency for opening the session picker. Consider deriving a promotable title at write time only (already done in InputPreparer) or adding a batched store API for title backfill instead of per-row loads in list path.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

@phantom5099
Copy link
Copy Markdown
Collaborator

还有没有要改的

@pionxe
Copy link
Copy Markdown
Collaborator

pionxe commented May 1, 2026

@xgopilot 请你帮我分析当前pr的修改会不会导致出现TUI绕过Gateway直连Runtime的风险?以及是否存在冗杂函数或没有复用已有函数的情况?

@fennoai
Copy link
Copy Markdown

fennoai Bot commented May 1, 2026

结论

  1. 未发现本 PR 引入 TUI 绕过 Gateway 直连 Runtime 实现层 的新风险。当前 tui 仍只依赖 tuiservices.Runtime 抽象,调用点依旧是 a.runtime.ListSessions/LoadSessioninternal/tui/core/app/update.go:2504, internal/tui/core/app/update.go:2543),而远端实现继续通过 gateway RPC 转发(internal/tui/services/remote_runtime_adapter.go:323-378,方法为 gateway.listSessions / gateway.loadSession)。
  2. 存在可优化的“函数复用/冗余”点,主要是标题提升与单行化规则在多个层重复实现,后续维护时容易漂移。

发现的问题(按严重度)

  1. 中等:标题提升规则在 runtimesession 双处重复定义,存在语义漂移风险

    • internal/runtime/runtime.go:413shouldPromoteSessionTitleinternal/session/input_preparer.go:499 同名同职责,且都依赖“New Session -> 用户文本”规则。未来若调整规则,很容易只改一处导致行为不一致(例如列表回填与输入阶段提升冲突)。
    • 建议:将“标题提升判定”下沉到 internal/session 的共享导出函数(或统一 policy helper),runtimeinput_preparer 复用同一实现。
  2. 低:标题单行化逻辑跨层重复,规范来源不够集中

    • 存储层已在 sanitizeTitle 做空白折叠(internal/session/store.go:230),TUI 又新增 normalizeSessionTitleSingleLineinternal/tui/core/app/command_menu.go:221)进行二次折叠。
    • 当前二次兜底有现实价值(历史脏数据展示),但建议显式标注“展示兜底”语义,或复用共享 helper,避免未来两处规则细节不一致。

关于你关心的“绕过 Gateway”

  • 本次改动没有新增 tui -> internal/runtime/service 的直接依赖,也没有在 TUI 引入 internal/gateway 之外的旁路调用。边界仍是:TUI -> tuiservices.Runtime -> (RemoteRuntimeAdapter) -> Gateway
  • 需要注意的是:runtime.ListSessions 新增了回填写入逻辑(internal/runtime/runtime.go:288-327),这是 Runtime -> SessionStore 的行为变化,不属于 TUI 绕过 Gateway,但会带来列表路径写放大/读放大(已有历史 review 提到 N+1)。

View job run

@creatang
Copy link
Copy Markdown
Collaborator Author

creatang commented May 1, 2026

/code 请提高测试覆盖率到百分之百,并提交pr到对应的fork分支

@fennoai
Copy link
Copy Markdown

fennoai Bot commented May 1, 2026

处理结果

已按本次 PR 变更点补充覆盖测试并完成提交,新增覆盖主要针对:

  • runtime.ListSessions 默认标题回填分支(含无效标题与加载失败分支)
  • session 标题提升判定分支
  • SQLiteStore.UpdateSessionTitle 的取消上下文/非法 ID/标题规范化落库分支
  • tui update pasted-load 新增逻辑分支(重调度、deferred send、paste session helper)

已执行验证

  • go test ./internal/runtime ./internal/session ./internal/tui/core/app
  • gofmt -w(仅本次修改的测试文件)

提交信息

  • Commit: 44922ac
  • 已推送到分支:origin/fork-pr-534-1777610466

未完成项说明

尝试将提交直接推送到你指定的 fork 分支 creatang:codex/tui-scrollbar-thumb-only 时失败(认证错误:Invalid username or token),当前环境无法对该 fork 仓库写入。

View job run

xgopilot and others added 2 commits May 1, 2026 05:04
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: creatang <165447160+creatang@users.noreply.github.com>
test(pr-534): improve coverage for session title backfill branches
@pionxe pionxe merged commit 007f706 into 1024XEngineer:main May 1, 2026
3 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.

4 participants