Repository navigation
Conversation
Scope LoopEmitted LLM events with turnId and step via ScopedLlmRunEvent, stamp originating turnId and step on tool.delta, tool.ended, and tool.async_ended, and emit a per-step stepId on step.started.
|
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: 23f5c6abcc
ℹ️ 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".
|
|
||
| export type TurnContinuation = 'turn' | 'background' | 'none'; | ||
|
|
||
| export type ScopedLlmRunEvent = LlmRunEvent & { readonly turnId: number; readonly step: number }; |
There was a problem hiding this comment.
Add this core contract change to a changeset
This alters the @moonshot-ai/core event contract, but the commit contains no changeset and explicitly defers it to a later stack layer. If this layer lands or releases before that later commit, the library version and changelog will omit the new required event fields, leaving consumers without an accurate compatibility signal; add a patch changeset for this commit rather than relying on a future PR.
AGENTS.md reference: AGENTS.md:L169-L170
Useful? React with 👍 / 👎.
| this.currentStep = step; | ||
| this.runtime.transition(() => { | ||
| this.emit({ type: 'step.started', ...this.point }); | ||
| this.emit({ type: 'step.started', ...this.point, stepId: step.id }); |
There was a problem hiding this comment.
Reuse the emitted step ID in existing projections
When agent-core-v2 handles this event, turnProjection.ts still calls createStepState(event.step, ...) and publishes that newly generated UUID, while journal.ts independently stores another randomUUID() for the same (turnId, step). Consequently the new core stepId, the observable turn.step.started ID, and the persisted wire step UUID remain different, so consumers still cannot correlate the same step across the event surfaces this change is intended to unify; pass event.stepId through both existing consumers instead of creating parallel IDs.
AGENTS.md reference: AGENTS.md:L109-L110
Useful? React with 👍 / 👎.
Requirement or Bug
core
LoopEmitted目前缺少完整的路由信封:LlmRunEvent全家没有turnId/step,tool.ended/tool.async_ended没有归属回合,且内存投影与wire.jsonl各自生成一套步骤 UUID,导致上层无法直接消费 core 事件。本 PR 是refact-477事件驱动重构栈的第 1/10 层(base:main),在 loop 合同层以纯增量方式补齐turnId、step与统一stepId,为后续内存消费者直读 core 事件打地基。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:不在 LLM pipeline 层强行注入 turn 概念(下层
kosong/ requester 并不知道 loop 的回合边界),而是在 core loop 合同层定义带作用域的交叉类型,并在ActorTurn/LoopActor的发射点统一注入已有的this.point({ turnId, step })。关键改动:
packages/core/src/loop/contract/emitted.ts:新增ScopedLlmRunEvent;为工具 delta/结束/异步结束事件增加turnId、step;为step.started增加stepId。packages/core/src/loop/turn/contract.ts:TurnStep增加readonly id: string。packages/core/src/loop/turn/create-turn.ts:创建 step 时生成randomUUID();在step.started、requestProgress、completeRequest(含llm.delta.*与llm.retry)及工具发射点注入路由信封。packages/core/src/loop/loop-actor.ts:为 6 处tool.ended与 2 处tool.async_ended补齐归属turnId/step。阅读顺序:
contract/emitted.ts(看类型契约)→turn/create-turn.ts(看stepId生成与发射注入)→loop-actor.ts(看跨回合异步工具归属)。Behavior Changes and Affected Users
LoopEmitted事件对象字段turnId、step;step.started无stepIdturnId、step、stepId,既有字段不变loop.subscribe订阅者(新增可选/只读字段,不破坏既有读取)受影响模块与验证:
@moonshot-ai/core:test/loop/requester.test.ts覆盖跨步、重试、中止的信封断言;m0-devcore套件 434/434 通过。@moonshot-ai/agent-core-v2:test/agent/loop/core/{hooks,record,requester}.test.ts、journal.test.ts、toolAdapter.test.ts补齐跨步、恢复、detach 信封断言。验证记录
packages/core、packages/agent-core-v2、packages/kap-server、packages/acp-server、packages/klient、packages/node-sdktypecheck 0 错误。core434/434 通过;agent-core-v28496 通过 / 3 失败(2 个为 m0-dev git 2.34.1config.worktree已知环境限制,1 个mcpCore/client-stdio.test.ts超时抖动单独复跑 26/26 通过)。lint-pool.sh(含check:duplication)0 退出。Checklist
gen-changesetsskill, or this PR needs no changeset.(按栈维护约定,本栈 10 层库级 patch changeset 统一集中在第 10 层提交。)gen-docsskill, or this PR needs no doc update.