Repository navigation
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d12d05464
ℹ️ 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".
|
|
||
| constructor(private readonly input: TurnInput, private readonly runtime: TurnRuntime) { | ||
| this.id = input.id; | ||
| this.scope = withAbort(runtime.signal); |
There was a problem hiding this comment.
Honor the per-turn abort signal
For direct callers of the newly exported createTurn API, aborting the TurnInput.signal has no effect because the turn scope is derived only from runtime.signal and input.signal is never observed. Consequently, even an initially aborted input can start hooks and an LLM request, and an in-flight turn continues instead of resolving as aborted; Loop.runTurn only avoids this through its separate outer listener. Compose the input signal into this scope or register an abort listener inside ActorTurn.
Useful? React with 👍 / 👎.
|
|
||
| private async executeBatch(proc: TurnProcess, step: TurnStep): Promise<boolean> { | ||
| this.setPhase(proc, 'batching'); | ||
| const starting = await proc.step(() => this.batchStarting(step)); |
There was a problem hiding this comment.
Skip batch-starting hooks after an in-flight abort
When a turn is aborted during an LLM request but the requester ignores the signal and still resolves within the grace period with tool calls, this.outcome is already aborted, yet the new path invokes batchStarting before checking that outcome. The previous startBatch checked for an aborted turn first and skipped the hook, so configured batch hooks—such as the swarm policy hook—now run after cancellation and an asynchronous hook can delay the aborted turn even though tool execution is subsequently replaced with aborted outcomes. Check the aborted outcome before invoking the hook.
AGENTS.md reference: AGENTS.md:L111-L115
Useful? React with 👍 / 👎.
- add scoped synchronous controls, cooperative processes, and lifecycle management - cover actor scheduling, cancellation, event delivery, and close semantics
- replace loop-actor's private queues and manual idle/close with actor scheduling - track turn phase/step in a per-turn actor with step-scoped streaming callbacks - register turn host hooks once at loop init and reject repeated registration
4d12d05 to
0320214
Compare
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0320214304
ℹ️ 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.runtime.host.transition(() => { | ||
| this.emit(this.endedStep(step)); | ||
| }); | ||
| this.currentStep = undefined; |
There was a problem hiding this comment.
Finalize turn state before emitting step.ended
When a synchronous loop subscriber calls abort() from a step.ended callback—as the new reentrant-abort test does—runtime.host.transition delivers this event before currentStep is cleared. The abort therefore re-enters finishTurn, sees the same active step, and calls finalizeStep again, emitting a duplicate step.ended; after the callback unwinds, this outer invocation can also overwrite the aborted state with its captured pre-abort outcome. Commit the step and turn state before exposing the event, as the previous loop implementation did.
AGENTS.md reference: AGENTS.md:L111-L115
Useful? React with 👍 / 👎.
| timers.clear(); | ||
| const registered = cleanups.splice(0).toReversed(); | ||
| try { | ||
| for (const cleanup of registered) cleanup(); |
There was a problem hiding this comment.
Settle the step when an exit cleanup throws
If any callback registered with step.onExit throws while a step completes or is cancelled, cleanupStep() escapes after finishStep() has set settled = true but before either doneGate or the suspended process gate is settled. The task's catch then calls finishStep('reject', error) again, but the settled guard makes that call a no-op, leaving the runner suspended forever and causing ProcessHandle.done, waitForIdle(), and close() to hang. Capture cleanup failures while still settling the gates, rejecting the step with the cleanup error.
Useful? React with 👍 / 👎.
| } catch (error) { | ||
| completion.reject(error); |
There was a problem hiding this comment.
Finish closing after a scheduler error
If onSchedule throws during the initial kick() in close(), this catch only rejects the close promise: the queued close command remains pending, closing remains false, and closeCompletion permanently retains the rejected promise. A subsequent close() therefore cannot retry or drive that command, leaving the actor open; a later unrelated act() can then unexpectedly execute the stale close command even though the caller's close promise already failed. Convert this failure into a terminal close error or remove the pending close attempt so the actor is not stranded between open and closed states.
Useful? React with 👍 / 👎.
|
Superseded by #5211. |
Requirement or Bug
当前
LoopActor同时承担 MailBox、history 投影、Turn/Step 推进、LLM 请求、前台工具、abort 与恢复调度,Turn 生命周期散落在三十余种内部消息处理中,createTurn只是数据工厂。本 PR 把 Turn 的状态机独立抽出,并引入一个通用 actor 运行时承接 Loop 与 Turn 共有的事件派发、协程调度与生命周期管理,让 Turn 独占自身状态迁移和前台执行闭环。这是 turn 状态机重构的第一段提交栈,后续还有 Loop 接口整理。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:Turn 独占自身状态迁移和前台执行闭环;Loop 独占启动/终止权、MailBox、history、恢复调度、requester template 和工具实例管理。两者通过预注册的宿主 hook 与注入的运行时端口协作,Loop 与 Turn 各自持有独立的 actor 实例,不再共享私有消息队列。
createTurn,显式 phase/state,线性 async/await 推进 prompt / continue / resume / step / tool / ending / terminalpackages/core/src/actor:同步原子act、受控串行协程(spawn/step/checkpoint/waitUntil)、非重入事件派发、幂等close;Loop 与 Turn 各持独立实例starting/requesting/continuing/ending,创建 Turn 只注入同一 hook 视图flowchart TD subgraph Loop["LoopActor(Loop 侧宿主)"] MB[MailBox / history 投影 / 恢复调度] REQ[requester template] TOOLS[工具实例 map / detached completion] end subgraph Turn["Turn(独立状态机)"] SM[显式 phase/state<br/>线性 async/await 推进] end ACTOR["actor 运行时(Loop 与 Turn 各持独立实例)"] MB -->|"唯一入口 activate:同一时刻最多一个 active Turn"| SM SM -->|"宿主 hook:starting / requesting / continuing / ending"| MB SM -->|"批次端口:executeBatch / abortBatch"| TOOLS SM --> REQ MB --- ACTOR SM --- ACTOR阅读指南:
packages/core/src/actor/actor.ts— actor 运行时全部语义(act/spawn/step/checkpoint/waitUntil、事件派发、取消与close)。packages/core/src/loop/turn/— Turn 公开契约、状态机与 Step 执行、宿主 hook registry、批次工具端口。packages/core/src/loop/loop-actor.ts— Loop 如何经唯一activate创建与终止 Turn,以及保留的 MailBox / history / 工具宿主职责。packages/agent-core-v2/test/agent/loop/core/{wait,hooks}.test.ts— Turn 生命周期对抗用例与宿主 hook 单点注册用例。可略读:index 导出接线、oxlint 棘轮基线调整(
promise/no-callback-in-promise1→0)。Behavior Changes and Affected Users
None — Loop/v2 外部行为、事件顺序和消息契约不变:
turn.starting → started → message.appending → step顺序、单条 user prompt 契约(hook parts 合入同一条 prompt)、notify / resume / detached completion / abort grace 行为均保持addTurnHook可链式多次注册registerTurnHooks单次注册,重复注册抛错验证结论:
packages/core+test/agent/loop+test/features/externalHooks+test/agent/prompt合计 52 文件 627/627 通过,其中原有事件顺序 snapshot 未修改即通过。actor.ts的 V8 Statements / Branches / Functions / Lines 均 100%);Turn 生命周期对抗用例(重复 start、force abort、late outcome、finished 后不再执行);宿主 hook 单点注册用例。tsc --noEmit通过;仓库标准pnpm lint全部通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.