← Back to Pull requests

feat(hybrid): keep more chat history under scrollback_bytes #348

Closed
unknown closed this pull request without merging on Nov 06, 2026 08:21 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 05:56 UTC
Author

概述

聊天事件日志与终端缓冲共用 scrollback_bytes(默认 2 MiB),但日志按 JSON 估算计量,每个流式块都带事件包装,tool 原始输出又与对话争抢同一份预算。本 PR 在不改变线上协议的前提下提高日志的内容密度。规划见 openspec/changes/compact-chat-event-log/。

改动

  • 旧 tool 输出降级:日志超出预算时,先把较旧事件的 tool 文本 / diff 缩到每块至多 2 KiB 并标 truncated,仍超出才丢弃最早的事件。标题、状态、位置、序号不变;未超预算时不改任何内容。

  • - 保护窗口按累计大小定义:日志尾部不超过预算四分之一的事件不缩短。单个事件本身就超过窗口时不在窗口内,同样可以缩短,这样优先保留对话(见 52fbd05 与规格中的"单个事件超过保护窗口")。
  • 相邻同消息块合并存储:已结束的同一条 agent / thought 消息(无附件)的连续 message.append 合并为一条存储事件,序号取最后一块。续接起点改为按序号二分查找;断线恰好落在被合并的消息中间时,只补发尚未收到的文字,不重复、不触发重置。流式中的消息和实时帧仍逐块发送。

  • 线上 JSON 字段不变(internal/contract、internal/wire、web/src/schemas.ts 与 wire 快照均无改动)。

  • 文档:docs/protocol/http-hybrid.md 说明序号可能不连续与组内补发;更新 US-Q05。
  • 评审中修复的问题

  • b1b50ed:mergeLocked 合并一段块后没有调整降级扫描位置,位置可能超出日志长度,之后追加的 tool 输出会被整条驱逐而不是缩短。已修复并加回归测试。

  • 52fbd05:撤掉我先前加的"最新事件始终完整",它在边界情况下会为保住一个巨大输出而驱逐更早的对话。
  • 影响的用户故事

    US-Q05(阅读聊天时间线):断线重连只补发缺失事件,以及超出 scrollback_bytes 时的行为。没有新增或退役的故事。

    验证

    CI 在当前提交 52fbd05 上全部通过:Go race、E2E(4 个分片)、E2E runtime、Vitest unit and browser、Storybook、CLS and 4x CPU、Format, check and build(含 golangci-lint)、Linux packages、Windows installer smoke。

    本地另外运行过:

  • go test -race ./internal/hybrid ./internal/hub ./internal/wire ./internal/archtest ./internal/docguard,以及 ChatLog 用例的重复运行。

  • 新增用例覆盖:合并与不合并的边界、组首 / 组中 / 组尾 / 组外一格的续接、UTF-8 边界、降级的保护窗口与幂等、订阅者持有对象不被修改、扫描位置在合并后保持有效、整条合并事件被丢弃时的 From、并发追加与订阅(-race)。

  • TestChatLogOutputDoesNotCrowdOutConversation:400 轮、每轮含 8 KiB 工具输出的合成会话,在 512 KiB 预算内保留 141 轮,只丢弃最早事件的日志保留 43 轮。这是工具输出偏重的合成场景,不代表一般会话的收益。

  • 前端:vitest 的 chat-model 用例、svelte-check(含测试配置)、oxlint、oxfmt --check、check:arch、pnpm --dir web build;make docs-check。
  • 未运行:

  • openspec validate(本地没有 CLI),请在有 CLI 的环境里执行 openspec validate compact-chat-event-log --strict --no-interactive。

  • compact-chat-event-log/tasks.md 中 1.3、5.3 与第 6 节的验证项未勾选:1.3 的度量未在仓库内逐项复现,6.5 的人工长会话验证未做。

  • 本地 TestWireSnapshots/workspace 在基线上同样失败(git 提交时间格式 +00:00),与本变更无关;CI 上通过。
  • 没有可见 UI 变更,因此无截图。ToolRow 对降级内容仍显示"(内容过长,已截断)",是否改文案见规划的开放问题。

    ---
    _Generated by Claude Code_

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Ab6Q7K2144vTYotgJeXqYA

    Diff: 281 lines (+210 / -71) across 3 files Reviewer: mzdluo123 Review duration: 145m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 281 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.338
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #348"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.7% (MEDIUM) · Higher = larger blast radius
    39.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.2% · Safe to merge
    17.2%