fix(agent-core-v2): backfill session metadata and align subagent timeout and print-mode lifecycle with v1 - #1710
Conversation
- kap-server: accept opts.version in startServer, reported as server_version (/meta, OpenAPI, session exports, lock registry, default User-Agent); defaults to its own package version - kimi-code: pass the CLI product version when starting the server - add boot test covering /api/v1/meta, lock file, and User-Agent
- add wireRecord.seal() to write the metadata envelope at agent creation, so fresh logs satisfy v1 replay's first-record-must-be-metadata invariant - seal the wire log before any op dispatch in AgentLifecycleService.create; no-op when the log already has records (resume / forked copies) - seed empty agents/custom maps in session metadata so v1 Session.resume() can index agents['main'] on a v2-created state.json - add seal unit tests and lifecycle sealing tests
- read per-record times stamped on wire.jsonl via reduceContextTranscript and cache them alongside the transcript messages - prefer each record's real dispatch time for created_at; records without a stamp fall back to session.createdAt + index, clamped so the page stays strictly increasing (mirrors MessageLegacyService.list) - add tests for fallback, clamping, and the page-offset index mapping
…ession metadata - load() now heals pre-fix v2 state.json documents that never gained the agents/custom maps, persisting the backfill so one open on a new build leaves the session resumable by released v1 builds (Session.resume() indexes agents['main'] unconditionally) - updatedAt is deliberately untouched so the format heal does not reorder session listings
- add [subagent] config section with timeout_ms and KIMI_SUBAGENT_TIMEOUT_MS env override - resolve Agent and AgentSwarm per-run timeouts through resolveSubagentTimeoutMs - update tool descriptions and tests to reflect the 2-hour default
- add printBackgroundMode/printMaxTurns to the task config section with resolvePrintBackgroundMode (keepAliveOnExit fallback) - apply exit/drain/steer policy to kimi -p on the experimental engine, buffering turn.ended events and failing the run when a steered turn fails - register the subagent config section from the package entry
…e headers only - replace == null with === undefined in the session-metadata heal to satisfy eqeqeq (oxlint --type-aware in CI) - move the seal() rationale into the wireRecord contract header and the agents/custom invariant into the sessionMetadata header per the tree's header-only comment convention
applyPrintBackgroundPolicy now emits the ceiling warning when the turn.ended wait itself elapses with tasks still pending, matching the deadline-reached path.
- applyPrintBackgroundPolicy waits for goal continuation turns via a goalActive hook before applying the exit/drain/steer mode, bounded by the wait ceiling - createPrintTurnEndings skips the timeout when the remaining budget is not finite - update the changeset to cover the goal-run lifecycle
🦋 Changeset detectedLatest commit: 19dba2f 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19dba2f275
ℹ️ 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".
| input.warn(`print goal wait ceiling reached (${input.ceilingS}s), finishing`); | ||
| return; |
There was a problem hiding this comment.
Return non-zero when goal wait times out
When kimi -p "/goal ..." hits print_wait_ceiling_s while the goal is still active, this branch only warns and returns. runNativeGoal then summarizes that active snapshot and calls the existing goalExitCode('active'), which falls through to success, so long-running or low-ceiling goal runs can exit with code 0 even though the goal never reached a terminal success state. Treat this ceiling path as a failed/paused goal or otherwise force a non-zero exit before returning.
Useful? React with 👍 / 👎.
Related Issue
No linked issue — the problems are explained below.
Problem
This branch collects a set of agent-core-v2 (experimental engine) fixes and v1-alignment work:
agents/custommetadata maps were not healed. The kap-server snapshot history also showed wrong message times, andserver_versiondid not report the CLI version.[subagent] timeout_ms/KIMI_SUBAGENT_TIMEOUT_MSoverrides.kimi -pon v2 ignoredprint_background_mode/print_max_turns(it always drained background tasks), andkimi -p "/goal ..."exited after the first turn — v2 drives goal continuation as new turns, which the print runner never waited for.What changed
Session format & server fixes
agents/custommaps in existing session metadata, with a strict-equality heal.server_version.Subagent timeout alignment
[subagent]config-section owner (timeout_ms, 2-hour default,KIMI_SUBAGENT_TIMEOUT_MSenv override), shared by the Agent and AgentSwarm tools; timeout messages render the effective duration.Print-mode lifecycle alignment
task/ legacybackgroundconfig section gainsprint_background_mode(exit/drain/steer) andprint_max_turns, resolved with v1 semantics (explicit mode >keep_alive_on_exitfallback > defaultexit).steerstays alive so background-task completions steer new main turns, bounded byprint_wait_ceiling_sandprint_max_turns, and warns when either cap is hit.active, so goal continuation turns run to a terminal state (v1 parity forkimi -p "/goal ...").Tests
sessionLegacytest stub for theensureMainAgent(create) path.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.