Repository navigation
refactor(agent-core-v2): publish enriched core loop events immediately on the agent event bus - #5674
Conversation
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd34d3ef8d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| this.syncRequester(); | ||
| loop.subscribe((event) => { | ||
| const enriched = this.turns.enrich(event, this.toolExecutor); | ||
| this.eventBus.publish(new CoreLoopEvent({ agentId: this.scopeContext.agentId, event: enriched })); |
There was a problem hiding this comment.
Keep core loop envelopes out of the SDK event stream
When a Node SDK session uses the v2 engine, SessionEventWiring subscribes to every IEventBus event (packages/node-sdk/src/v2/session-wiring.ts:164-168), and translateDomainEvent passes unknown types through by default (packages/node-sdk/src/v2/event-mapper.ts:93-110). Consequently, every event published here—including per-token deltas, raw provider response headers, and internal reminder messages—is delivered to SDK listeners as core.loop.event, despite that type not belonging to the public closed Event union. This changes the external SDK stream and can break consumers that exhaustively validate event types; explicitly drop this envelope in the SDK mapper or publish it on an internal-only channel.
AGENTS.md reference: AGENTS.md:L191-L193
Useful? React with 👍 / 👎.
cd34d3e to
38c9f44
Compare
38c9f44 to
ff1b09e
Compare
4e18382 to
5f8957b
Compare
…y on the agent event bus
ff1b09e to
7340278
Compare
Requirement or Bug
v2 内部模块与协议出口目前只能订阅
AgentTurnProjection二次翻译后的 v2 事件,且内存stepId与 wirestep.begin.uuid是两套独立 UUID。本 PR 是refact-477事件驱动重构栈的第 3/10 层(base:02-prune-unanswered-tool-calls),在 v2 边界建立带agentId的 core 事件即时透传通道,并将正常步骤的内存与落盘stepId统一为 corestep.started.stepId。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:复用现有
IEventBus的类型化订阅、跨 Agent 路由与 Scope 自动退订能力,定义非持久化的CoreLoopEvent(core.loop.event),在loop.subscribe内完成同步enrich后立即发布,绝不等待LoopJournal或磁盘 I/O。flowchart LR A[Core LoopActor] --> B[turns.enrich] B --> C[IEventBus.publish CoreLoopEvent<br/>durable=false, 同步即时透传] B --> D[notifications.project / turns.project] B --> E[LoopJournal.append<br/>旁路写 wire 1.x]关键改动:
packages/agent-core-v2/src/agent/loop/coreLoopEvent.ts:CoreLoopEvent、onCoreLoopEvent类型收窄订阅助手,以及穷尽映射纯函数turnOutcomeReason(done→completed、aborted→cancelled、failed→failed、blocked→blocked)。loopService.ts:在turns.enrich之后、journal.append之前同步发布CoreLoopEvent。journal.ts/turnProjection.ts:优先复用 corestep.started.stepId;重试第 N>1 次 attempt 没有新的step.started,LoopJournal仍分配独立 wire UUID,以保持 KAP 实时item_id前缀与回放item.removed行为完全不变。tools.settled同时作为core.loop.event即时透传,并由LoopJournal落盘为[wire] tools.settled。Behavior Changes and Affected Users
IEventBus实时事件流core.loop.event(durable=false)IEventBus订阅者(本层尚无生产订阅者消费新事件)stepId与 wirestep.begin.uuidstep.started.stepId(重试 attempt>1 仍独立)item_id与回放结构保持一致受影响模块与验证:
@moonshot-ai/agent-core-v2:新增coreLoopEvent.test.ts;更新loop.test.ts、config.test.ts、plan.test.ts、tool.test.ts总线事件流快照,并在test/harness/snapshots.ts归一化core.loop.event易变字段。core-event-passthrough11 个场景kapFrames/rest/stepIdentity100% 一致(wire 差异仅来自上游 fix(agent-core-v2): restore loop tool baseline from session journal #5635 新增tools.settled,剔除后逐字节一致)。验证记录
core434/434、agent-core-v28496 通过(仅已知环境用例);lint-pool.sh0 退出。Checklist
gen-changesetsskill, or this PR needs no changeset.(本栈 changeset 统一集中在第 10 层提交。)gen-docsskill, or this PR needs no doc update.