fix(kimi-code): keep kimi -p alive while background tasks are pending - #2675
Conversation
The 10-year default print wait ceiling (315360000s) overflowed Node's setTimeout limit (2^31-1 ms) into a 1ms fire, so the steer/drain wait returned instantly and kimi -p exited right after the main turn, killing pending background tasks and subagents. - add setClampedTimeout in agent-core-v2 _base, clamping delays to MAX_TIMER_DELAY_MS, and route every config-driven timer through it (timeoutOutcome, task wait/manager timeout, swarm attempt timeout) - chunk the print turn-endings wait against the real deadline instead of returning null on the first clamped timer fire - restore v1 semantics: a non-positive swarm subagent timeout is unbounded - default print_wait_ceiling_s to 2147483s (~24.8 days, the timer maximum)
🦋 Changeset detectedLatest commit: c403b82 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c403b821e9
ℹ️ 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".
| // A clamped early return just makes callers (e.g. the print drain | ||
| // loop) re-poll — the task may still be running, which the caller | ||
| // observes from the returned info. |
There was a problem hiding this comment.
Move the wait note out of the method body
In packages/agent-core-v2 implementation files, the local guide requires comments to live only in the top-of-file block; this new explanatory note is inside wait() beside a statement, so it violates the package convention and should be removed or folded into the file header if still needed.
AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L17-L17
Useful? React with 👍 / 👎.
…MoonshotAI#2675) The 10-year default print wait ceiling (315360000s) overflowed Node's setTimeout limit (2^31-1 ms) into a 1ms fire, so the steer/drain wait returned instantly and kimi -p exited right after the main turn, killing pending background tasks and subagents. - add setClampedTimeout in agent-core-v2 _base, clamping delays to MAX_TIMER_DELAY_MS, and route every config-driven timer through it (timeoutOutcome, task wait/manager timeout, swarm attempt timeout) - chunk the print turn-endings wait against the real deadline instead of returning null on the first clamped timer fire - restore v1 semantics: a non-positive swarm subagent timeout is unbounded - default print_wait_ceiling_s to 2147483s (~24.8 days, the timer maximum)
Related Issue
No linked issue — the problem is explained below.
Problem
In print mode (
kimi -p), the default background-policy wait ceiling is 10 years (315360000s). Converted to milliseconds it exceeds Node'ssetTimeoutlimit (2^31-1 ms), and Node silently re-arms such a timer at ~1ms instead of rejecting it (the only trace is aTimeoutOverflowWarning). Every wait in the print background policy — bothsteer(the default) anddrain— therefore returned immediately: akimi -prun whose main turn fanned out background Bash tasks or subagents exited right after the main turn, shutting down all pending work and losing its output.This is a v1→v2 porting regression: v1 clamps the delay to 2^31-1 ms (
MAX_TIMER_DELAY_MSinpackages/agent-core/src/utils/promise.ts), but the v2 port dropped the clamp, andkimi -pruns on the v2 engine by default.What changed
setClampedTimeoutin agent-core-v2's_base/utils/timer.tsclamps any delay toMAX_TIMER_DELAY_MS; every config-driven timer routes through it (timeoutOutcome, taskwait/ manager timeout, swarm attempt timeout), so no call site handles the constant itself.print_wait_ceiling_snow defaults to 2147483s (~24.8 days, the timer maximum) — still effectively unbounded, but the default itself can no longer overflow. Explicitly configured larger ceilings remain safe via the clamp + chunking. User docs (en/zh) updated.timeout <= 0guard, so print mode's unbounded subagent timeout (0) would have aborted swarm subagents immediately; restored.Regression tests cover: the default-ceiling steer wait staying alive with pending tasks, oversized turn-ending budgets resolving only at the real deadline,
taskService.waitclamping, and swarmtimeout: 0meaning unbounded.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.