Skip to content

subagents: 聚合 snapshot 缺少统一 byte 上限 #180

Open

Description

@tt-a1i

问题

Direct Subagent snapshot 对单字段/单结果已有投影限制,但聚合 snapshot(多个 agent 的 transcript、usage、状态和结果投影)缺少统一总 byte 上限。大量 settled/running agents 或长 transcript 组合后,session entry、restore parsing 和 model/UI projection 可持续膨胀。

期望

  • snapshot 在写入前按 UTF-8 bytes 施加聚合硬上限;
  • 先保留 canonical lifecycle identity、terminal state、watermark 和恢复所需事实,再公平裁剪可重建展示数据;
  • 不把截断 snapshot 标记成完整;
  • 单个大 agent 与多个中等 agent 都覆盖边界测试;
  • restore 对旧版超大 snapshot 有有界读取/失败策略;
  • exact result artifacts 保持可恢复,snapshot 只承担有界投影;
  • persisted state、model-visible context、operator UI 分开测试。

Activity

  1. 627150795 commented on Aug 28, 2026

    @627150795
    Contributor

    Hi! I am working on this issue. I will add a bounded aggregate snapshot projection for Direct Subagents, preserving lifecycle identity and exact result artifacts while testing single-large and multi-agent boundaries before opening a PR.

  2. 627150795 commented on Aug 28, 2026

    @627150795
    Contributor

    Follow-up: I audited the current implementation and did not find a distinct aggregate-snapshot persistence seam. The real paths are the per-agent manager snapshot, bounded aggregate result projection, process-local pending delivery map, and UI transcript projection, each with separate semantics. I am not opening a speculative PR that would blur those contracts; the issue remains open for a future design that names the canonical aggregate boundary and its recovery requirements.

  3. tt-a1i commented on Sep 8, 2026

    @tt-a1i
    CollaboratorAuthor

    本轮核对建议把 #180 收窄到一个已经找到、可以无模型调用复现的边界:Direct Subagent 的待投递结果没有总数量或字节上限。

    核对日期:2026-09-08;源码:ed9dbc1018f890fd54375f5371990ddfee8af5df。下面区分源码事实、确定性探针与建议,不把探针当成实际 Session 的内存 Benchmark。

    原文“聚合 snapshot 持久化/restore”没有对应到当前独立的持久化 seam,之前的评论也已指出这一点。这里补充真实的 pending completion 路径,保留原讨论历史。

    当前路径与触发条件

    因此,父一直执行当前 turn、持续补充已经完成的 child 时,待投递数量可以超过 64;manager 的保留上限不能约束这个集合。

    可重现探针

    在上述 revision 的仓库根目录运行下面命令。本轮使用 Node v26.3.0,不安装依赖、不启动 child、不请求模型。

    node --input-type=module <<'JS'
    import { createSubagentResultDelivery } from './extensions/subagents/src/result-delivery.ts';
    let deliveredCount = 0;
    let deliveredBytes = 0;
    const q = createSubagentResultDelivery({
      isIdle: () => false,
      deliver: batch => {
        deliveredCount += batch.length;
        deliveredBytes += batch.reduce((n, x) => n + Buffer.byteLength(x.finalText), 0);
      },
    });
    for (let i = 0; i < 256; i++) {
      q.defer({ id: `sa-${i}`, finalText: `result ${i}:` + 'x'.repeat(64 * 1024) });
    }
    console.log({ pendingBeforeParentSettled: q.size() });
    q.parentSettled();
    console.log({ pendingAfter: q.size(), deliveredCount, deliveredBytes });
    JS

    观测结果:pendingBeforeParentSettled=256;settle 后 pendingAfter=0、deliveredCount=256、deliveredBytes=16779922。这证明当前队列接受并保存了约 16 MiB 的结果文本,且一次向 dispatcher 交付全部 256 项;不代表测得真实 Session 的 RSS,也不证明已有用户触发 OOM。

    已有保护与建议范围

    模型可见文本已有 48 KiB 整批截断及公平分配,所以这里不是“模型上下文无界”。本轮也不重新主张存在一个独立的 persisted snapshot/restore 边界。

    Background Terminal 已有可参考的 running + pending + reserved 准入限制。Direct Subagent 可以选择总量反压,或在投递前保存完整结果、让 inbox 只保留有界投影和恢复引用;具体方案需要同时保持 wait 消费与发送失败重试语义。

    建议最小验收:

    • 用 fake backend 让父持续 busy,顺序完成并补充 1,000 个 child,覆盖真实 manager → settlement → inbox 路径。
    • 待投递集合满足明确的 count/byte 硬上限,完整结果仍可恢复;超过预算时给出可操作反馈,不静默丢结果。
    • manager prune、wait 消费、发送失败重试、父 settle 与 Session shutdown 的边界不会漏投或错误消费。
    • 单个大结果与大量中等结果都覆盖 UTF-8 字节边界;模型文本、operator 展示、待投递内存分别验证。

    这是一项待实施的范围建议,不代表已修复或已采用新的架构约束。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions