Skip to content

perf(chat): avoid off-page result reads during legacy history fallback - #8358

Merged
loopx-agent merged 1 commit into
mainfrom
codex/chat-history-cost-20261108
Nov 8, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/chat-history-cost-20261108

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

An unmatched legacy return can make a conversation history page scan every saved route. It currently deserializes complete answers and delivery sidecars even when their result IDs are absent from that page, adding repeated work as history grows.

This change selects immutable result keys before reading their payloads through the existing result-store IO owner. Route/source validation, exhaustive legacy fallback, full answer text, fresh status reads and malformed-state handling keep their existing behavior. Unfiltered Inbox callers retain their original contract. There is no new state, cache, timeout, consumer or UI setting.

Validation:

  • All 120 manager-context roundtrip tests passed. The two new fallback/production-HTTP regressions fail on immutable base c263f7c78353fcaa914f23475d4d99d07eab7c01 because it reads off-page results; they pass on this change.
  • The same real HTTP/SQLite/Core fixture (404 messages, 96 routes, 768 complete 20,000-character results) ran base/head/head/base with seven uninstrumented samples per arm. Result-file reads: 1,536 → 80. Per-run median: 0.17–0.26 s → 0.04–0.05 s. Complete history hashes and original source bytes match exactly. These are local synthetic measurements, not production p95 or proof that other contention is fixed.
  • Late verification changes, malformed delivery state, legacy/numbered keys, missing locators and wrong Session/source/request routes remain covered. The formal Chat bundle build passed.

The existing history-recovery documentation also corrects its body count from 19,000 to the actual 20,000 characters. This is a count correction; the original test already compared the full body.

This is a backend IO change with the existing conversation journey unchanged. The screenshots and earlier packaged-browser checkpoint in history recovery retain their explicitly stated revision/boundary; they are not new installed-App evidence. Production activation, installed latency and unanswered business requests remain separate acceptance.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer: model_agent; model=gpt-6.1-sol; provider=OpenAI; declaration_source=runtime_reported; reasoning_effort=max

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

打开已有长会话、阅读历史答复的用户。旧回执匹配失败后,旧实现读取所有离页答复;现在只读取当前页需要的结果,全文和状态保持一致。同一 404 条历史逐字一致,结果文件读取从 1,536 次降至 80 次;晚到验证和损坏状态仍准确可见。本次不修复所有原进程等待、原生 App 安装采用或未完成的业务补答。源码路径已验证;原服务安全激活、安装后的实际延迟和业务补答继续由原有责任者验收。

改动思路 / Approach

结果筛选属于现有 Chat 派生投影,状态读取仍复用现有 File IO owner;不需要新缓存、索引或状态 authority。本 PR 仅减少历史页的离页结果读取,保持完整回退、来源校验、正文、状态和无写入语义。旧流程先遍历 route,再读全部正文/状态,最后按页过滤;新流程保留原遍历与来源检查,只将身份匹配提前到读取内容之前。真正的状态校验仍在一个 reader 内,其他调用者不传选择器即保留原完整读语义。相比增加超时、永久缓存或新索引,这个方案直接减少已测重复工作,没有额外用户交互、失效规则或迁移成本。

具体改动 / Changes

基于修改前接受的 原会话合同,spec_ref 为 docs/architecture/rfcs/app-conversation-and-async-inbox-v0.md#acceptance-and-failure-matrix,spec_revision 为 c263f7c。Result、Scope、Authority 三行均由原来源检查、完整 HTTP/负例对照保持;Packaging 的实际安装采用继续留在原验收,不以本 PR 结清。

关键代码讲解

  • reply_status:541 只在 canonical 文件名匹配后读正文和 sidecar,原错误/状态分类与时间字段完全保留。没有 selector 的 Inbox、委托展示、native binding 和 issue-fix 消费者仍得到完整状态。
  • project_chat_return_deliveries:251 保留 Session、host、request 的核验和遗失 locator 回退,使用与原最终投影相同的完整 SHA 身份提前选择结果。未匹配旧行保持原正文,不会被当成送达成功。

四文件 +118/-3,其中生产修改 +16/-2,另有两项实质回归与文档。文档把原合成正文的误记 19,000 改为实测 20,000,原断言始终核对全文。结果文件布局、响应 schema、持久状态、权限、模型执行与消息发送均不改变。

对主干的风险 / Risks

最强反例是提前选择错 key 导致晚到状态或损坏结果被隐藏。实际 HTTP 先读第一页,再改变下一页状态、破坏 sidecar,并分别更换 route 的 Session、host、request;五类完整响应在不可变 base 与当前 head 的 hash 完全相同。遗失 locator 与一个无法匹配的旧消息仍触发完整 route 回退,没有将不完整来源当空。

PASS:全部 120 项 roundtrip 测试、同 fixture 四组各 7 次非插桩 HTTP 对照、完整 404 行读回及源字节不变、正式 Chat build,以及精确头标准预合并 6 direct/15 selected。两个新 IO oracle 在旧 base 失败、head 通过。首次预合并缺 root npm typescript 依赖的失败保留;补齐环境后完整门通过。标准 catalog 另保留 private_conversations.py ceiling 的非阻塞 advisory,并非全树无债务。未查询/等待远端 CI;未执行真实模型或 IM。

我的整体评价 / Verdict

未发现阻塞问题。本次是有实际收益、可独立回滚的读取优化;不需要为了这个 IO 问题重写 typed authority 或扩大架构。long_horizon 在重复页读成本上 improved;user_experience 在当前同一历史路径上 improved,零新增确认/配置步骤。visual_review 不适用:完整 diff 没有渲染展示改变,现有 Chat/history caller 的响应和全文相同。未核实范围:安装后的原生 App 延迟、其他慢路径或业务完成。

采用既有 result key/status 词汇,没有新的共享 vocabulary、authority、缓存或迁移。完整回退的 route 枚举仍可能耗时;本地合成的 0.17–0.26 秒到 0.04–0.05 秒不是生产 p95。原服务安全激活和实际消息补答沿既有验收继续。本结论是作者模型自审,COMMENTED 不等于 GitHub 正式自我批准,也不授予合并权限。

English verdict: APPROVE 75d012e. The existing result reader avoids off-page payload IO while identical production HTTP observations preserve full history, freshness and rejection behavior. Installed performance remains unverified.

@loopx-agent

Copy link
Copy Markdown
Collaborator Author

Exact-head author review 5817292751 is published and read back at 75d012e. All 120 roundtrip tests, same-fixture production HTTP/SQLite/full-history and five negative comparisons, formal Chat build, and standard premerge 6 direct / 15 selected passed. The catalog retains its nonblocking private_conversations.py ceiling advisory; initial missing npm dependencies and the old-base IO failures remain recorded. No CI was queried or awaited under the current no-wait policy. Approval closeout is clear, zero unresolved threads, unchanged head is MERGEABLE, and native readiness is ready=true with admin_bypass_required=true solely for the author-owned COMMENTED approval / branch policy. Existing maintainer authorization covers this repair self-merge. This decision does not certify installed latency, service activation or business completion.

@loopx-agent
loopx-agent merged commit 4e949f4 into main Nov 8, 2026
7 of 10 checks passed
@loopx-agent
loopx-agent deleted the codex/chat-history-cost-20261108 branch November 8, 2026 09:05
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.

1 participant