Skip to content

在进行code review双轨审查的时候主代理无法被后面完成的那个子代理唤醒 #47

Closed

Description

@miwaiwai

体感上就是有个子代理在review的时候发现了问题,有时候会到主代理自动修复问题,有时候就卡在那了,必须要用户发句话他才开始修复问题,然后回答用户刚才的问题。

会话详情如下: Standards 轴发现了一项 callback CSP 硬性问题:此前的 'self' 会授权任意同源脚本在携带 SMW 回调 Token 的文档内运行。

已修复并提交:

  • b030114 fix(identity): pin callback application integrity

修复措施:

  • callback application script 现在具有构建后自动注入的 SHA-256 integrity。
  • callback CSP 移除 script-src 'self',只允许:
    • 已哈希的内联 callback bootstrap;
    • 已哈希的 identity-app.js 构建产物。
  • Nginx 的两条 callback location 规则、Playwright 静态服务器和部署产物校验器共同验证这两个精确 hash。
  • callback 加载完成后通过仅一次性的 DOM event 将 accessToken 交给 mountIdentityApp(accessToken);没有 URL、Storage 或
    全局属性 handoff。
  • 保留构建时 fail-fast:缺少 integrity placeholder 会直接使构建失败。

已通过:

  • npm run lint
  • npm run test:browser(11 passed)
  • node scripts/verify-identity-artifacts.mjs
  • node scripts/verify-ci-workflow.mjs

等待最终 Spec 轴报告,以便给出最终双轴聚合结论。

■ subagent sa-5 · final-rereview-spec · finished
Spec

(a) Missing / partial requirements

  • mountIdentityApp does not enforce the required thin in-memory handoff.
    vue/src/main.ts:24 declares mountIdentityApp(accessToken: string | null = null) and the normal entry calls
    mountIdentityApp() at line 34. This permits mounting the application without a session and makes the token optional.
    ADR 0011 requires: “最小入口以 mountIdentityApp(accessToken) 接收内存薄会话”; it also says login completion should
    enter the sole minimal protected entry. The API should require an access token for the protected mount, with
    unauthenticated login UI handled separately if needed.

  • The retained UI foundation is only partially demonstrated.
    The final Vue source retains Vite/Vue/TypeScript/Tailwind/Element Plus and two generic primitives, but
    @element-plus/icons-vue is merely retained as a dependency and no icons or broader reusable foundation components are
    used. ADR 0017 requires retaining “图标、视觉样式、设计 token、布局原语和无业务语义通用组件”. This may be acceptable
    as a minimal slice, but the diff does not establish retention beyond the reduced UiPage, UiPanel, and custom CSS token
    set.

(b) Scope creep

  • None found. The final state does not reintroduce Pinia, Axios, routing, menus, permissions, Portal, local account
    flows, user center, or template business pages.

(c) Implemented-but-wrong behavior

  • The optional/default-null mount behavior above is also functionally wrong: direct normal startup mounts an
    unauthenticated app rather than requiring the exact mountIdentityApp(accessToken) memory-session boundary. The Bearer
    API boundary itself is otherwise correctly implemented in vue/src/api/identity.ts; no SMW token persistence or
    non-Bearer access-token transport was found.

(This result is already shown to the user. Act on it and relay only the decisions or next steps — do not repeat it
verbatim.)

✳ Worked for 5m23s

Tool output: expanded

Activity

  1. miwaiwai commented on Aug 21, 2026

    @miwaiwai
    Author
    1. 父代理 subagent_spawn 后完成当前 turn;
    2. 子代理在父代理刚 settled 的临界窗口返回;
    3. onSettled() 执行 defer();
    4. isIdle() 判断未触发 flushResults(true);
    5. agent_settled 已经过去,后续没有 retry/timer;
    6. 结果直到用户下一次输入才被消费。

    应重点检查:

    • subagents/index.ts 的 onSettled();
    • agent_settled 与子代理 settled 的事件竞态;
    • resultDeliveryOptions(true) 是否确实触发父代理新 turn;
    • 是否需要在 defer() 后增加 idle batch/timer,或在 agent_settled 后再次检查 pending 结果并主动唤醒。
  2. tt-a1i commented on Aug 21, 2026

    @tt-a1i
    Collaborator

    已复现并定位:这是平台无关的丢唤醒,不是 Windows 专属故障;Windows 只可能因任务/IO 耗时不同扩大竞态窗口。

    确定性事件序列:

    1. 子代理在父代理 busy 时完成;onSettled() 把结果放进 pending Map,isIdle() 为 false,不能立即唤醒。
    2. 父代理随后进入 agent_settled;当前代码固定 flushResults(false)。
    3. false 映射为 { deliverAs: "nextTurn" }。
    4. Pi 的 nextTurn 只会在下一次用户 prompt 时从 _pendingNextTurnMessages 取出,不会主动开始模型 turn。
    5. 因此结果虽然已显示在 transcript,但主代理不会消费,直到用户再发一句话。

    这与 README / subagent_spawn 工具说明的「完成后自动回传并重新唤醒主 Agent」契约直接矛盾。

    Windows 审计:OpenPI 子代理是同一 Node 进程内的 Pi Session,不是 OS child process;该投递路径没有 process.platform 分支,也没有 session 文件 watcher。Windows 影响的 shell/worktree 行为可能改变子任务完成时刻,但不会改变上述投递逻辑。

    正在做的修复不是 sleep:建立双边无丢唤醒协议——child-settled 时若父已 idle 就立即 flush;否则保留到 parent agent_settled,在父已 idle 的边上再 flush,并始终用 followUp + triggerTurn。pending Map 的 drain 是 one-shot gate,多个 busy 期间完成的 reviewer 合并为一次父 turn,subagent_wait 仍可在 flush 前消费。

    已新增纯状态机回归测试覆盖:idle 立即唤醒、busy→parent settled、两结果批量、wait consume、不重复投递。当前本地全量 743 + 29 tests 通过,bun run check 退出 0;还在做并发复审与 delivery failure/reentrancy 检查。

  3. added a commit that references this issue on Aug 23, 2026
    97cc3ff
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