fix(core): avoid empty transcript history pages - #7582
Conversation
E2E test reportValidated against an authorized local persisted session that reproduced the issue without inspecting or exposing conversation content.
|
|
Thanks for the PR! Template looks good ✓ Problem: Observed bug with clear evidence — backward pagination reports Direction: Aligned. Transcript pagination correctness is core session management — clients should never see a phantom "more history" signal followed by an empty page. Size: 38 production lines (+26 −12) in Approach: The scope feels right — one focused fix in Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ 问题:已观测到的 bug,有明确证据——向后分页报告 方向:对齐。Transcript 分页正确性属于核心会话管理——客户端不应看到"还有历史"的信号后紧接着收到空页面。 规模: 方案:范围合理—— 进入代码审查 🔍 — Qwen Code · qwen3.8-max-preview Reviewed at |
Code ReviewIndependent proposal: After aligning to the first replay turn boundary in PR's approach: Matches exactly. When No correctness bugs, no security concerns, no regressions. The byte-budget enforcement is preserved correctly — the check that was previously inside the The new unit test covers the exact scenario: Real-Scenario TestingExercised the Before (main branch)The After (this PR)All records included in the first page, Unit tests47 existing tests + 1 new test, all passing. 中文说明代码审查独立方案: 在 PR 方案: 完全一致。当 无正确性 bug,无安全隐患,无回归。字节预算执行正确保留——之前在 新单元测试覆盖了精确场景: 实际场景测试直接使用 修复前: 单元测试:48 个测试全部通过(47 个已有 + 1 个新增)。 — Qwen Code · qwen3.8-max-preview Reviewed at |
|
Confidence: 5/5 — Clean fix for a real pagination bug; reproduced before/after, minimal diff, all tests pass. This is a textbook small bugfix. The problem is concrete and observable: backward transcript pagination leaves a leading The diff is 26 production lines + 26 test lines, touches exactly one function and its test file, and carries no unrelated changes. The before/after reproduction confirms the fix works as described. 48 unit tests pass (47 existing + 1 new). Nothing to second-guess here. Ships it. ✅ 中文说明置信度:5/5 — 对真实分页 bug 的干净修复;已复现 before/after,最小 diff,所有测试通过。 这是一个教科书式的小型 bugfix。问题具体且可观测:向后 transcript 分页遗留了前置 Diff 为 26 行生产代码 + 26 行测试代码,仅触及一个函数及其测试文件,无无关改动。Before/after 复现确认修复如描述所述。48 个单元测试全部通过(47 个已有 + 1 个新增)。 无需犹豫。可以合并。✅ — Qwen Code · qwen3.8-max-preview Reviewed at |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
— qwen3.7-max via Qwen Code /review
| maxBytes, | ||
| ); | ||
| } | ||
| expandedSelection = true; |
There was a problem hiding this comment.
[Suggestion] expandedSelection = true is set unconditionally here, even when the while loop didn't move selectedStart (already aligned to a turn boundary). Functionally equivalent to prior behavior, but the name implies expansion occurred. Consider renaming to needsByteCheck or adding a comment: // always check bytes in the unaligned path, matching prior behavior.
— qwen3.8-max-preview via Qwen Code /review
yiliang114
left a comment
There was a problem hiding this comment.
LGTM. Correct fix — leading session metadata now folds into the first conversation page instead of producing an empty metadata-only continuation. maxBytes check covers both expansion paths. One inline nit on expandedSelection naming.
— qwen3.8-max-preview via Qwen Code /review
What this PR does
Backward transcript pagination now includes leading session metadata with the first conversation page when no earlier user turn exists. This prevents an otherwise empty metadata-only continuation page from being advertised as additional history.
Why it's needed
A persisted session can begin with an internal session-source record before its first user turn. Turn-aligned backward pagination previously left that record behind and reported more history, even though replaying the follow-up page produced no visible events. Clients consequently issued a redundant transcript request and observed
historyHasMore: truefollowed byevents: [].Reviewer Test Plan
How to verify
Create a transcript whose active chain is
session_source -> user -> assistant, then request a backward page with a limit larger than the transcript. Confirm the initial page includes the complete chain, reportshasMore: false, and has no continuation cursor. Also confirm ordinary multi-turn backward pages remain aligned to user turns.Evidence (Before & After)
Before: the initial page omitted the leading session-source record and reported
hasMore: true; the continuation page returnedevents: []andhasMore: false.After: the initial page consumes all 21 records in the reproduced session, reports
hasMore: false, and returns no continuation cursor.Tested on
Environment (optional)
Node.js 22; targeted unit tests plus repository lint, build, and typecheck.
Risk & Scope
Linked Issues
N/A
中文说明
本 PR 做了什么
当第一个用户轮次之前不存在更早的用户轮次时,向后加载 transcript 会把会话前置元数据并入第一个对话页。这样不会再把一个只能产生空结果的纯元数据续页标记为“还有历史”。
为什么需要
持久化会话可能在第一个用户轮次之前包含内部的 session-source 记录。此前按轮次对齐的向后分页会把该记录单独留在前一页,并报告还有历史,但续页 replay 后没有任何可展示事件。客户端因此会发出一次多余的 transcript 请求,并观察到
historyHasMore: true后紧接着events: []。Reviewer 测试计划
如何验证
创建 active chain 为
session_source -> user -> assistant的 transcript,并使用大于 transcript 长度的 limit 请求向后分页。确认第一页包含完整链、返回hasMore: false且没有 continuation cursor;同时确认普通多轮会话的向后分页仍按用户轮次对齐。修复前后证据
修复前:第一页遗漏前置 session-source 记录并返回
hasMore: true;续页返回events: []和hasMore: false。修复后:复现会话的第一页一次消费全部 21 条记录,返回
hasMore: false,且没有 continuation cursor。测试平台
环境
Node.js 22;运行了定点单元测试以及仓库 lint、build 和 typecheck。
风险与范围
关联 Issue
N/A