feat(runtime-hooks): P5 async/async_rewake(internal-only)+ run 内存通知队列 + ephemeral 注入 (#493)#544
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
One functional issue and one documentation issue.
docs/runtime-hooks-design.mdstill saysasync / async_rewakeare unimplemented and does not listhook_notificationin the observable event set.docs/guides/configuration.mdstill describes hooks as sync-only without clarifying that the new async modes are internal-only.
The inline comment below covers the code path that currently breaks provider-agnostic delivery of the new ephemeral notifications.
|
@xgopilot 你能详细、有逻辑且使用通俗易懂的话语解答我下述问题吗?
|
结论先说你的理解大方向是对的,但有两个地方需要收紧一下:
1. 当前 HOOK 机制到底在做什么可以把它理解成:runtime 的“受控扩展插槽”。 它不是在代码里随便找地方加回调,而是先定义一组固定挂点,再由 executor 在这些挂点统一调度。挂点定义在
这些点位不是“都能改流程”。项目还专门做了一个能力矩阵,也就是每个挂点允许做什么,定义也在
所以更准确地说,它想达到的目的不是“在不改主循环前提下随意拦截、观察或篡改行为”,而是:
如果再通俗一点说,HOOK 在这里更像“预留的检查岗”和“观测岗”,不是“任意改线的后门”。 2. 当前项目里的 HOOK 底座做到什么程度了我看下来,底座已经不是空壳,已经有一条比较完整的基础链路了。 2.1 已经具备的核心能力从
2.2 已经接到主链的哪些地方它不是“只定义了类型没接线”,而是已经接到 runtime 关键路径里了:
这说明它已经是真实参与主链的内部扩展机制,不是概念层设计。 2.3 现在还处在什么阶段虽然底座很完整,但当前仍然是**“受控、偏保守”的阶段**,不是完全开放式 hook 平台。 主要体现在:
所以第二问的准确答案是: 有基础底座,而且已经打进 runtime 主链了;但它目前还是“内部优先、同步优先、能力边界明确”的状态,不是一个完全开放、任意扩展的 hook 系统。 3. 这次 PR 的异步执行,你的理解对不对你的理解大方向是对的,我把它改成更精确一点的话: 是的,它本质上就是一个 run 生命周期内的内存通知队列,然后在下一轮 provider 请求前,把这些通知临时注入到 system prompt 里,作为这一次请求的附加提示。 但有 4 个关键限定,最好一起记住: 3.1 只有
|
Summary
本 PR 落地 #493(P5)最小闭环:在不改 FinalDecider/acceptance 终态裁决的前提下,新增 internal hooks 的
async/async_rewake执行能力,并实现“run 内存通知队列 + 下一轮 provider 请求前 ephemeral 注入”。Background
当前 hooks 仅支持
sync,对长耗时观察型逻辑和“异步提醒下一轮处理”场景支持不足。同时,通知回灌如果落到 session/db 或直接变成对话消息,会污染会话历史并引入状态歧义。
Problem
当前行为:
hook_notification可观测事件。期望行为:
async/async_rewake;影响:
User Scenario
当某个 internal hook 在工具后置观察阶段检测到异常(或需要下一轮补动作)时:
hook_notification日志,但不会把它当 user/assistant 消息展示。Goals
HookModeAsync/HookModeAsyncRewake(internal 可用)。hook_notification事件贯通 runtime -> gateway/tui(仅可观测)。Non-Goals
Proposed Design
1) hooks 核心执行语义
sync:保持现状(可阻断、可短路)。async:后台执行,不影响当前RunOutput.Blocked。async_rewake:后台执行;满足条件时产出通知信号。HookResult.Metadata新增结构化回灌字段:rewakerewake_reasonrewake_summaryfailed/block/metadata.rewake=true,不做 message 文本匹配。2) run 内存通知队列
runState,仅 run 生命周期有效:hookNotificationshookNotificationSeen(dedupe)hookNotificationOmittedMaxNotificationsPerRunMaxNotificationCharsNotificationTTLMaxInjectedNotificationsPerTurnN more notifications omitted3) ephemeral 注入
4) 生命周期与安全边界
SetHookExecutor增加 sink 绑定兜底,避免替换执行器后回灌失效;scope=user/repo仅支持sync,禁止async/async_rewake(防绕过配置层)。Scope
涉及模块:
internal/runtime/hooksinternal/runtimeinternal/tui/servicesinternal/tui/core/app主要文件:
internal/runtime/hooks/executor.gointernal/runtime/hooks/types.gointernal/runtime/hooks/result.gointernal/runtime/hooks/events.gointernal/runtime/hook_notifications.go(新增)internal/runtime/run.gointernal/runtime/runtime.gointernal/runtime/hooks_integration.gointernal/runtime/state.gointernal/runtime/session_scheduler.gointernal/runtime/events.gointernal/tui/services/runtime_contract.gointernal/tui/services/gateway_stream_client.gointernal/tui/core/app/update.goAcceptance Criteria
hook_notification,但不转对话消息。Test Plan
已执行:
go test ./internal/runtime/hooks/...go test ./internal/runtime/...go test ./internal/tui/services ./internal/tui/core/appgo test ./internal/config/...新增/更新覆盖点:
Risks / Compatibility
风险:
兼容策略:
hook_notification为新增可选事件,不破坏旧事件消费;Follow-ups