Skip to content

fix(host-runtime): accept official Item anchor cursors in External thread/items/list - #987

Merged
BytePioneer-AI merged 2 commits into
BytePioneer-AI:mainfrom
ump45nose:pr/external-history-item-anchor
Nov 21, 2026
Merged

BytePioneer-AI merged 2 commits into
BytePioneer-AI:mainfrom
ump45nose:pr/external-history-item-anchor

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Purpose

The official app-server protocol lets thread/items/list take either an opaque string cursor or an Item anchor, { "type": "item", "itemId": "…" }. The anchor is an exclusive position inside the requested turnId: ascending returns Items after it and descending returns Items before it. You can confirm this in the schema that codex app-server generate-json-schema --experimental emits (codex-cli 0.169.1), under ThreadItemsListParams.cursor → ThreadItemsListCursor / ThreadItemsListAnchor.

For External Threads, listExternalItems only accepts the Host's own string cursor. An Item anchor object is rejected with cursor must be text, so a client that pages Items by anchor gets an error. The fork found this while reopening paginated External Threads in Desktop.

Root cause

parseCursor in packages/host-runtime/src/external-thread-history.ts requires text and only understands {anchor, includeAnchor} JSON.

Change

listExternalItems resolves an Item anchor to the existing internal anchor [turnId, itemId] with includeAnchor: false, then pages as before. An anchor without turnId is rejected. So is a malformed anchor. An anchor that is not in the requested Turn gets the existing cursor anchor is no longer present. thread/turns/list is unchanged, because its official cursor is string-only.

Validation

  • npx tsc -b
  • npx vitest run -c tests/vitest.config.js packages/host-runtime/test/external-thread-history.test.ts: the 3 new cases fail on main and pass with this change (20/20).
  • eslint and prettier on the changed files.

Known baseline on main (unchanged by this PR)

  • lint errors in packages/adapters/antigravity/test/acp-transport.test.ts:457-458 and app-server-host.background-output.test.ts:146
  • failing tests: two Codex Usage projection tests, and "retires a running Subagent when the parent's output stream ends"

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 新功能
    • 外部项目历史分页现在支持使用项目游标,并可在升序或降序结果中从指定项目之后继续获取内容。
    • 使用此类游标时需提供有效的回合标识和项目标识;游标无效或项目不属于指定回合时会返回错误。

listExternalItems 现在接受官方 Item 游标对象。该游标需要有效的 itemId 和 turnId,并从锚点之后继续分页。新增测试覆盖升序、降序分页及游标校验错误。

Changes: Item 游标分页

Layer / File(s) Summary
游标解析与分页验证
packages/host-runtime/src/external-thread-history.ts, packages/host-runtime/test/external-thread-history.test.ts
listExternalItems 使用 parseItemsCursor 解析游标对象,并将锚点转换为不包含锚点的组合游标。测试覆盖升序和降序分页,以及无效游标、缺少 turnId 和锚点不属于指定 Turn 的错误。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: kongtou20070406, bytepioneer-ai

Merge Risk: Minimal · previous review 685e8

This change lets External thread item listing accept the official Item anchor cursor, with clear errors for invalid or turn-less cursors. The existing string cursor path is unchanged. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题准确描述了主要变更:外部线程的 thread/items/list 现在接受官方 Item 锚点游标。标题与 parseItemsCursor 的新增对象游标支持、以及新增测试直接对应,属于 PASS。
Description check Passed 描述说明了官方 Item 锚点游标的用途、根因(parseCursor 只接受文本游标)、具体修改(将锚点解析为 [turnId, itemId] 并设置 includeAnchor: false)、错误处理与验证步骤,与变更集直接相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…rsor

An object anchor on thread/items/list skipped the history refresh because any non-empty cursor counted as a continuation, so an unloaded Thread reported the anchor as missing.
@BytePioneer-AI
BytePioneer-AI merged commit 19fef8b into BytePioneer-AI:main Nov 21, 2026
6 of 8 checks passed
@BytePioneer-AI

Copy link
Copy Markdown
Owner

Merged, thanks @ump45nose! One follow-up commit (503f900): an object Item anchor on an unloaded Thread skipped the history refresh (any non-empty cursor counted as a continuation) and reported the anchor as missing; it now loads history first. String continuation cursors are unchanged. Regression test added in app-server-host.projection-2.test.ts.

ump45nose added a commit to ump45nose/codex-host that referenced this pull request Nov 27, 2026
Eleven manifest lines still carried fork copies of changes that upstream has
already released. Each one names a merged PR whose head commit is an ancestor
of v0.28.2, so the line only re-applies the pre-review copy of code that the
release tag already contains, and that duplication is what turns the manifest
replay into conflicts.

Removed lines and their merged PRs:

- thin/cursor-fast-selection (BytePioneer-AI#782)
- thin/delegation-inspect-fast-models (BytePioneer-AI#986)
- thin/delegation-catalog-parent (BytePioneer-AI#970)
- thin/settings-hide-desktop-envs (BytePioneer-AI#972)
- thin/settle-turns-after-session-fault (BytePioneer-AI#969)
- thin/external-thread-turn-recency (BytePioneer-AI#973)
- thin/claude-code-todo-tools (BytePioneer-AI#976)
- thin/reasoning-summary-parts (BytePioneer-AI#967)
- thin/shared-archived-thread-revival (BytePioneer-AI#988)
- fix/desktop-mcp-session-reap-v0.22 (BytePioneer-AI#981)
- fix/macos-descriptor-mode (BytePioneer-AI#1004)

For the two lines whose comments noted that the fork copy predated the PR's
review changes (BytePioneer-AI#969, BytePioneer-AI#976), the reviewed upstream version replaces it.

Checked with `scripts/vincent-release.sh audit` (ancestor and patch-cherry
checks) and by replaying the manifest onto v0.28.2 in a scratch worktree: these
eleven lines no longer merge, and the fifteen remaining lines are fork-only
changes that need re-cutting from the new tag.

Lines for fork-only additions are untouched: the extras documented for BytePioneer-AI#470,
BytePioneer-AI#987 and BytePioneer-AI#989 stay, and the lines for the closed PRs BytePioneer-AI#576, BytePioneer-AI#783, BytePioneer-AI#784, BytePioneer-AI#785 and
BytePioneer-AI#396 stay.
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.

2 participants