Skip to content

feat(kimi): support native sessions, delegation, and runtime diagnostics - #161

Open
kingsoftheweb wants to merge 17 commits into
qafrom
fix/kimi-runtime-errors
Open

kingsoftheweb wants to merge 17 commits into
qafrom
fix/kimi-runtime-errors

Conversation

@kingsoftheweb

@kingsoftheweb kingsoftheweb commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Kimi's print runner dropped reasoning, usage, delegated-agent lifecycle events, and interactive requests. Provider failures such as HTTP 307 could surface as opaque exit errors. This change uses the pinned Kimi CLI's authenticated loopback REST/WebSocket server, with a private stdio bridge in the same host or project container.

Changes

  • Preserve provider diagnostics and distinguish failed/interrupted runs from completion. Wait for background agents, interactions, goals, and tracked cron work; deduplicate per-step usage across agents.
  • Support foreground/background delegation, swarms, nested agent correlation, child reasoning/tool activity, stop/detach controls, and cancellation cleanup.
  • Expose native model/thinking settings, Plan reviews and alternatives, approvals, multi-select questions, resume/fork, custom agents, skills, browser MCP, goals, context controls, and isolated /btw side questions. Kimi continues to load its own hooks, plugins, and MCP configuration.
  • Update user guides and feature/limitation tables. Detailed coverage is in the runtime review.
  • Remove stray tokens from an existing auth test that prevented the backend suite from compiling; this is isolated in its own commit.

Structure

  • Explicit bridge startup and centralized limits; separate session setup, preference translation, MCP preparation, transport lifecycle, and terminal outcomes.
  • Dedicated state owners for delegated-agent activity/task controls, per-step usage, cron lifetime, and pending interactions. Typed native requests and pure answer validation preserve wire semantics and event ordering.
  • Component-local question state behind a hook; forms emit typed user actions and the interaction service encodes native replies. Delegated control targets also pass through a hook.
  • The refactor is split into 11 signed-off commits with focused validation per move. Existing behavior is preserved, including documented follow-ups.

Validation

  • Full backend suite: go test ./....
  • Focused race tests for Kimi, shared runtime, agent contracts, prompt orchestration, and capability discovery; go vet ./...; go build ./....
  • All 250 frontend tests and the production build. Browser checks cover question selection/free text, dismissal, plan feedback/choices, and stop/background controls.
  • Installed Kimi 0.40.1 compatibility tests with isolated homes and a local mock provider: valid/invalid 307 redirects, reasoning/usage, questions and approvals, Plan alternative selection, delegation/swarms, whole-run and individual-agent cancellation, resume/fork, custom profiles/skills, browser MCP, goals, and side-question context isolation.

GitHub Actions: frontend CI passes. The backend and infra jobs reproduce existing
CI problems in unchanged files: backend vet runs before generated backend/public
assets exist, and the deploy-script test expects the installation error while a
non-root runner first hits the root guard. CI run.

Limits

The original live endpoint behind the reported 307 is still unverified, and deployed QA/LXC validation remains pending. Native administration/TUI utilities remain in Kimi. Cron edits made outside Remote require a native CronList refresh to reconcile mirrored job IDs; durable scheduling without an active chat uses Remote's scheduled-task tools.

The refactor also documents an existing /agent<TAB>profile preflight/submission parsing inconsistency for a separate behavior fix; use the documented space syntax.

Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Replace the print stream with a private REST/WebSocket bridge to the pinned CLI. Preserve provider failures and usage, correlate all child agents, and expose native permissions, planning, questions, task controls, resume/fork, skills, goals and side conversations. Add installed-CLI compatibility coverage and document the native interface boundaries.

Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Copilot AI lite review requested due to automatic review settings September 6, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It introduces a large end-to-end behavior shift (new transport, lifecycle/usage semantics, UI interactions, and docs), and the remaining diagnostic-handling tradeoffs merit final human verification in real deployment scenarios.

Pull request overview

This PR overhauls the Kimi agent integration to use Kimi’s authenticated loopback REST/WebSocket server (via an embedded Node stdio bridge) instead of the legacy print/JSONL stream, enabling native sessions (resume/fork), richer lifecycle/diagnostic events, delegation controls, and more complete runtime telemetry. It also updates the frontend interaction UI and documentation to reflect the expanded Kimi feature surface and limitations.

Changes:

  • Replace Kimi’s print-mode parser with a native server transport + event mapping that preserves diagnostics, supports sessions/forking, delegation/swarms, cancellations, and deduped usage aggregation.
  • Extend the frontend to support native approvals, plan reviews/alternatives, multi-select questions, and child-agent stop/detach controls.
  • Refresh docs to reflect new Kimi runtime behavior, browser MCP support, approvals separation from sandboxing, and updated usage/cost reporting.
File summaries
File Description
frontend/src/ui/chat/messages/CollaborationCard.tsx Adds per-child stop/detach controls and optional reasoning display for Kimi subagent threads.
frontend/src/ui/chat/messages/AssistantPartList.tsx Wires interaction responder into collaboration cards so child controls can respond.
frontend/src/ui/chat/interactions/UserInputInteractionForm.tsx Supports multi-select + “other” answers and adds a Dismiss action for native questions.
frontend/src/ui/chat/interactions/ApprovalInteractionForm.tsx Adds plan review rendering, selectable plan alternatives, and optional feedback submission via provider-native responses.
frontend/src/ui/chat/composer/ComposerExecutionControls.tsx Makes approval options provider-driven (decoupled from sandbox execution policies).
frontend/src/ui/chat/composer/ChatComposer.tsx Plumbs approvalPolicyOptions through to execution controls and updates visibility logic.
frontend/src/state/hooks/chat/agentCapabilityState.ts Surfaces provider-native approval policies independently of sandbox execution policy support.
frontend/src/state/hooks/chat/agentCapabilityState.test.ts Adds coverage for Kimi exposing approvals even when OS sandbox/execution policies are absent.
frontend/src/models/chatInteraction.ts Extends question model with body/multiSelect/option IDs and keeps intents for provider-native responses.
frontend/src/models/agentCapabilities.ts Adds provider approval policies and exposes them in composer capability state.
docs/known-limitations.md Updates limitations to reflect Kimi native Plan/approvals/fork/usage and remaining gaps.
docs/dev/agents/kimi-runtime-review.md New detailed runtime/feature coverage review for the native Kimi adapter and validation notes.
docs/dev/agents/06-features-and-platform-consumers.md Updates feature matrix to include Kimi fork and approvals separation.
docs/dev/agents/05-provisioning-and-updates.md Updates provisioning notes (credential sync timing, AGENTS.md provisioning).
docs/dev/agents/03-capabilities-cache-and-refresh.md Updates capability discovery description for Kimi’s native server catalog and approvals.
docs/dev/agents/02-runtime-and-event-parsing.md Replaces old print-parser description with native server-driven runtime/event model.
docs/02-workspaces/10-usage-and-cost.md Updates usage/cost semantics to reflect native Kimi usage telemetry (vs legacy print mode).
docs/02-workspaces/04-chat-and-agents.md Updates user-facing Plan/Thinking/approval behavior for Kimi’s native integration.
docs/02-user-guide/13-feature-reference.md Updates user feature inventory and provider comparison table (approvals, usage, fork, browser MCP).
docs/02-user-guide/12-troubleshooting.md Updates troubleshooting guidance for Kimi diagnostics (incl. HTTP 307 explanation).
docs/02-user-guide/11-everyday-workflows.md Updates workflow guidance: Kimi supports context-preserving forks; Antigravity does not.
docs/02-user-guide/07-agent-browser.md Adds Kimi to supported providers for Browser MCP preparation.
docs/02-user-guide/03-chat-and-agent-controls.md Updates Thinking/Plan/Approvals guidance for Kimi’s native session settings.
docs/01-overview/00-philosophy.md Updates platform philosophy/acceptance notes re: Kimi Browser MCP and skill activation model.
backend/internal/service/prompt/service.go Plumbs UserPrompt into RunRequest so native commands can use unenriched user input.
backend/internal/service/auth/service_test.go Removes stray tokens that broke compilation in auth tests.
backend/internal/integration/agents/runtime/process.go Improves stderr capture by retaining a bounded tail so final diagnostics survive noisy runs.
backend/internal/integration/agents/runtime/process_test.go Adds test ensuring the final diagnostic is retained after long stderr progress output.
backend/internal/integration/agents/kimi/testdata/mcp.mjs Adds a minimal MCP fixture for browser/MCP compatibility testing.
backend/internal/integration/agents/kimi/server_transport.go New stdio bridge transport for authenticated Kimi loopback REST/WebSocket server.
backend/internal/integration/agents/kimi/server_transport_test.go Verifies shutdown drains late fatal/event frames before accepting process exit.
backend/internal/integration/agents/kimi/server_run.go New Kimi native session execution loop: resume/fork, preferences, idle detection, background work.
backend/internal/integration/agents/kimi/server_run_test.go Tests preference application, background waiting, Q&A encoding, cron lifetime behavior, command handling.
backend/internal/integration/agents/kimi/server_interactions.go Implements native approval/question/task control request/response mapping with privacy constraints.
backend/internal/integration/agents/kimi/server_events.go Maps native WebSocket events to Remote events, child-card separation, and usage dedupe.
backend/internal/integration/agents/kimi/server_events_test.go Tests nested agent isolation, step-usage dedupe, and suppression of private interaction payloads.
backend/internal/integration/agents/kimi/server_cron.go Tracks native cron job lifecycle and mirrors IDs in session metadata to keep runs open appropriately.
backend/internal/integration/agents/kimi/server_commands.go Implements native /agent, /swarm, /tower, /btw, /goal, /compact, /undo, /skill: command routing.
backend/internal/integration/agents/kimi/provider.go Switches Provider.Run to native transport/run loop, adds explicit mode validation, emits richer completion/failure events.
backend/internal/integration/agents/kimi/provider_test.go Tests that server startup diagnostics (e.g., 307) are surfaced and unknown modes are rejected pre-launch.
backend/internal/integration/agents/kimi/profile.go Provisions AGENTS.md into Kimi home and updates profile behavior accordingly.
backend/internal/integration/agents/kimi/profile_test.go Ensures provisioning policy remains stable with new instruction target.
backend/internal/integration/agents/kimi/parser.go Removes legacy print-mode stream-json parser.
backend/internal/integration/agents/kimi/parser_test.go Removes legacy print-mode parser tests.
backend/internal/integration/agents/kimi/native_smoke_test.go Adds opt-in installed-CLI compatibility tests covering native behaviors end-to-end.
backend/internal/integration/agents/kimi/factory.go Declares native fork support and browser MCP runtime preparation for Kimi.
backend/internal/integration/agents/kimi/command.go Runs embedded Node bridge instead of passing prompts/models via process args; uses node in container too.
backend/internal/integration/agents/kimi/command_test.go Verifies prompt/model are not exposed via process arguments (private stdio bridge).
backend/internal/integration/agents/kimi/cli_smoke_test.go Adds opt-in redirect (307) behavior compatibility test against installed CLI.
backend/internal/integration/agents/kimi/capability_parser.go Adds approval policy exposure + richer model capabilities (modalities/thinking) from native catalog.
backend/internal/integration/agents/kimi/capabilities.go Replaces CLI list/help probing with native server-based discovery via stdio bridge.
backend/internal/integration/agents/kimi/capabilities_test.go Updates capability parsing tests for new reasoning/approvals behavior.
backend/internal/integration/agents/kimi/bridge.mjs New Node-side bridge: spawns kimi web, extracts token, performs REST calls, and forwards WS events.
backend/internal/config/agents_test.go Updates expected native-fork support to include Kimi.
backend/internal/agent/model.go Adds UserPrompt to RunRequest for command safety (commands must use current user input).
backend/internal/agent/capability_model.go Adds ApprovalPolicies to normalized capabilities and ensures Clone copies them.
Review details
  • Files reviewed: 56/56 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +54 to +60
// The bridge consumes the CLI's startup banner, which contains a private
// bearer token. Only normalized protocol frames cross this boundary.
cmd.Stderr = io.Discard
if err := cmd.Start(); err != nil {
in.Close()
return nil, fmt.Errorf("start Kimi bridge: %w", err)
}
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Signed-off-by: Kings Of The Web <kingsofthewebofficial@gmail.com>
Preserve Kimi native session and interaction support alongside QA account selection, application tools, transcript loading, and saved answers. Update the capability fixture to the application-tools contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants