Repository navigation
feat(agent-core-v2): enforce minimum wire reader version - #4638
Conversation
|
Codex Review SummaryThis 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: 3b3b721213
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ef0db5e48
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e505701290
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0afe58422
ℹ️ 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".
27d27ec to
18b9bd2
Compare
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 18b9bd2b5b
ℹ️ 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".
| }); | ||
| }); | ||
| } catch (error) { | ||
| if (!wasLive) await closeSessionById(this.engineAccessor, input.id).catch(() => {}); |
There was a problem hiding this comment.
Keep failed-resume cleanup inside the session queue
When a cold resume fails after materializing the session and another lifecycle operation for the same ID is already queued, runSessionAccess releases its tail before this outer catch executes, so the cleanup can race the next resume/reload and close the session that operation is using or has just returned. The fresh evidence is that the liveness check is now inside the serialized callback, but closeSessionById still runs outside it; perform the rollback before the callback rejects and releases the queue.
Useful? React with 👍 / 👎.
| const outputRecord = | ||
| rewrittenRecords !== undefined && normalized.type === 'metadata' | ||
| ? { ...normalized, min_protocol_version: WIRE_MIN_READER_VERSION } | ||
| : normalized; |
There was a problem hiding this comment.
Raise the header minimum when writer requirements increase
When WIRE_MIN_READER_VERSION is raised independently while an existing journal is already at WIRE_PROTOCOL_VERSION but has an absent or lower minimum, rewrittenRecords remains undefined and this condition leaves the old header unchanged. The new writer can then append records requiring the raised minimum, while older readers trust the stale declaration and silently replay an incompatible tail—the exact data-loss mode this guard is meant to prevent; trigger a metadata rewrite whenever the declared minimum is below the writer requirement, not only during protocol migration.
AGENTS.md reference: AGENTS.md:L130-L132
Useful? React with 👍 / 👎.
| if (first.type === 'metadata') { | ||
| assertWireRecordsReaderVersion([first]); | ||
| this.appendLogStore.append(scope, AGENT_WIRE_RECORD_KEY, forkedRecord(agentId)); |
There was a problem hiding this comment.
Validate ordinary forks before starting target writes
When an ordinary fork contains multiple agents and one copied journal is incompatible, this assertion rejects from one appendForkedMarker task only after the target directory has been copied, while sibling tasks in the surrounding Promise.all may already have queued marker appends. Because Promise.all rejects without waiting for those siblings, the outer catch can remove the target while an append-log flush is still running, allowing that flush to recreate a partial orphan target after the failed fork. Validate all source headers before copying or writing the target, or wait for every marker task to settle before cleanup.
Useful? React with 👍 / 👎.
18b9bd2 to
8dfdd2b
Compare
Core slice of upstream MoonshotAI/kimi-code f72dc7e (MoonshotAI#4638). A wire journal can now declare `min_protocol_version`, and a reader that is older than that refuses to open it with `wire.version_too_low` instead of misreading records it does not understand. New journals are stamped with `WIRE_MIN_READER_VERSION` on creation, on migration rewrite and when rewriting a repaired journal. Not yet ported from the same commit, and the ledger says so: the kap-server route mappings (each route answers the new code), the search index changes, and the node-sdk error entry. The added case seeds a journal requiring reader `99.0` and fails with the assertion removed.
Server slice of upstream MoonshotAI/kimi-code f72dc7e (MoonshotAI#4638). A session whose wire needs a newer reader now surfaces as 40940 instead of an internal error: the handler maps the engine code before its generic fallback, the transport error table carries the pair, and the routes that can hit a wire read declare it for the OpenAPI surface. Fork adaptation: 40930 is `DEFAULT_WORKSPACE_UNAVAILABLE` here, so the code takes the next free value (40940) instead of upstream's number. The environment, interactions, sessionRating and tools routes are not declared yet — their error maps use anchors this fork does not carry.
Search slice of upstream MoonshotAI/kimi-code f72dc7e (MoonshotAI#4638). A cold session whose wire declares a newer `min_protocol_version` used to be indexed anyway, so search returned snippets from a journal this build cannot read and the index kept documents for a session the rest of the server refuses to open. Indexing now checks the metadata line first, drops that session's documents and reports the failure. The added case seeds a wire requiring reader 99.0 and fails when the guard is removed. The search suite carries five pre-existing failures in its lifecycle-diagnostics block; they reproduce on the pre-change tree.
Last slice of upstream MoonshotAI/kimi-code f72dc7e (MoonshotAI#4638). The SDK error table gains the entry so a host renders "Kimi Code upgrade required" instead of an unknown code, and the wire manifest is regenerated for the metadata record's new optional field. node-sdk's `tsc` still reports the pre-existing `#/errors` resolution errors this branch has carried since before the change; its test suite is 76 pass / 3 skip.
…target MoonshotAI#4638 lands in four slices: core enforcement (4d49fcb), the kap-server mapping and route declarations (8988dea), search skipping an unreadable wire (1a34ae1), and the SDK entry with a regenerated manifest (65a6412). MoonshotAI#4662 stays pending rather than closed: its reworded message has a site now, but it also lands on the full route-declaration set, and four routes here (environment, interactions, sessionRating, tools) carry no `WIRE_VERSION_TOO_LOW` declaration because their error maps use anchors this fork does not have. Ledger: closed 40 -> 43, remaining 56.
Port of the mention-provider half of upstream MoonshotAI/kimi-code df7efe9 (MoonshotAI#4515). The filesystem fallback scanned one root to exhaustion before the next, so a project directory holding more than the 2,000-entry cap starved the source folders entirely: `@target-needle` found nothing even though the file sat in a registered folder. The scan now interleaves the roots, one entry at a time, so unused capacity on one root is spent on others. `~` and `~/…` entries now resolve against the home directory instead of being treated as relative paths, and a root equal to the working directory is dropped instead of scanned twice. The added case uses the existing 2,000-entry fixture and fails when the scan is narrowed to the primary root. The working-directory case pins the deduplication. Also completes the MoonshotAI#4638 SDK half: `node-sdk` keeps its own error-code table, so `wire.version_too_low` had to be added there as well; the engine registry alone was not enough and the app typecheck caught it.
Port of upstream MoonshotAI/kimi-code 1b13934 (MoonshotAI#4621). A model or effort switch no longer errors out while a turn runs. A turn that has already sent its first request keeps the model it was launched with, and the switch applies from the next turn; before that first request the switch lands immediately. Choosing Compact and continue while busy queues the whole action: the queued item is a FIFO barrier like a queued /compact, so prompts behind it wait, the compaction runs when the queue drains, and it is skipped when another compaction completed in the meantime. A child agent's compaction no longer completes the wait. Local-form adaptations, because this fork's queue diverged from upstream's: - The queued item type is a five-variant union here (prompt / bash / skill / compact / model-switch); upstream has four. Steering narrows to QueuedPromptMessage | QueuedSkillActivation so the fork's slash-skill queueing keeps working, and the two dispatcher copies (KimiTUI and MessageDispatchController) both handle the new mode instead of sending the item's /model text as a prompt. - New user-facing copy goes through t() with en/zh keys (4 keys) instead of upstream's literal strings, and the queue row names the model and effort. - compactForModelSwitch detects compaction.unable by error code rather than isKimiError: the SDK normalizes RPC failures across the boundary, so the rejection is not an Error2 instance and the type guard never matched. - The fork's runModelSwitchAction keeps its extra 'new' action; only the 'compact' arm gained the busy branch. - QueuePaneComponent is a Container with its own row budget here rather than upstream's DockSection, so the model-switch row renders inline. Also adds the missing wire.version_too_low error copy (en/zh) that MoonshotAI#4638 left behind; check:t-coverage failed on it. Verified: app typecheck clean; kimi-tui-message-flow 408 tests (407 pass, 1 skipped), model-switch-confirm 21, queue-pane 12, session-event-handler compaction/goal-queue + program-status + create-tui-state 40, editor-keyboard + staging-leases 73; check:locale-keys, check:locale-placeholders, check:t-coverage, check:no-hardcoded-prose and check:no-comments green; oxlint --type-aware 0 errors on the touched files. Reverse checks: dropping model-switch from the barrier predicate reddens the Ctrl-S and queue-pane cases, forcing busy=false reddens the queued-compact case, and removing the next-turn suffix reddens two notice cases.
Requirement or Bug
Older readers currently replay newer wire journals even when the writer knows the records are incompatible, which can silently discard new record semantics. This PR lets writers declare the minimum reader protocol required by a journal and makes incompatible readers fail with actionable upgrade guidance. kap-server exposes the same failure as a structured compatibility error instead of a generic internal error.
Bug Reproduction Steps
N/A — feature PR.
Root Cause
N/A — feature PR.
Code Changes
min_protocol_versionto wire metadata and maintain it independently from the journal protocol version, so additive protocol changes can remain readable while incompatible changes can require an upgrade.wire.version_too_lowdomain error with required and current reader versions plus upgrade guidance.40930 WIRE_VERSION_TOO_LOWthrough transport, catch-all, and fs error handling, and declare it on status, goal, and existing session-conflict routes.wire.version_too_lowthrough the SDK public error contract and propagate incompatible subagent restore failures instead of silently omitting those agents.Behavior Changes and Affected Users
INTERNAL_ERROR40930 WIRE_VERSION_TOO_LOWwith the upgrade messageINTERNAL_ERRORwire.version_too_low, and newly materialized sessions are rolled back on failure using ownership captured inside the serialized resume queueChecklist
gen-changesets; the user explicitly decided not to include a changeset.gen-docsupdate is needed; the generated wire manifest is updated.