Skip to content

fix(cli): preserve session agent for headless prompts - #13102

Merged
johnnyeric merged 2 commits into
Kilo-Org:mainfrom
quanzhuo:issues/13027
Aug 13, 2026
Merged

fix(cli): preserve session agent for headless prompts#13102
johnnyeric merged 2 commits into
Kilo-Org:mainfrom
quanzhuo:issues/13027

Conversation

@quanzhuo

Copy link
Copy Markdown
Contributor

Issue

Fixes #13027

Context

Headless sessions created with an explicit agent lost that selection when the first prompt omitted the agent field. The prompt fell back to the default code agent, so the custom agent's model and permissions were not applied.

This change preserves the agent selected during session creation when a later headless prompt does not explicitly override it.

Implementation

Agent resolution for user messages now falls back to the agent stored on the session when input.agent is absent. Explicit prompt-level agent selections continue to take precedence, and sessions without a selected agent continue to use the configured default agent.

The regression test exercises the public headless HTTP flow by creating a session with a custom test-engineer agent, sending a prompt without an agent, and verifying that both the custom agent and its configured model remain selected.

Screenshots / Video

N/A — this change has no visual impact.

How to Test

Manual/local verification

  • Agent: ran git diff --check; it completed successfully.
  • Agent: ran bun run script/check-opencode-annotations.ts --worktree; all shared OpenCode changes were correctly annotated.
  • Agent: reviewed the HTTP regression test against the session create and prompt route schemas.

Reviewer test steps

  1. From packages/opencode/, run bun test ./test/kilocode/headless-session-agent.test.ts.
  2. Confirm the test creates a session with agent: "test-engineer" and sends the first prompt without an agent field.
  3. Confirm the returned user message uses test-engineer and mock/custom-model rather than the default code agent.
  4. Run bun run typecheck from packages/opencode/.

Blocked checks and substitute verification

  • Agent: bun test ./test/kilocode/headless-session-agent.test.ts could not start because the current workspace dependencies are incomplete (@opentui/solid/preload is missing). Substitute verification consisted of reviewing the test setup and HTTP route schemas, running git diff --check, and running the OpenCode annotation guard.
  • Agent: bun run typecheck from packages/opencode/ could not start because tsgo is missing from the current workspace dependencies. The diff and annotation checks above completed successfully, but the target test and typecheck should be rerun after installing dependencies.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes

Fall back to the agent selected during session creation when a headless
prompt does not specify one. This preserves custom agent models and
permissions instead of resetting the session to the default code agent.

Fixes Kilo-Org#13027
Comment thread packages/opencode/test/kilocode/headless-session-agent.test.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previous CRITICAL finding (wrong endpoint path in the regression test) was resolved in 80b54f7: the test now posts to POST /session/:sessionID/message, which is the correct v1 synchronous prompt endpoint (SessionPaths.prompt). Verified the endpoint accepts the noReply + parts payload, returns SessionV1.WithParts ({ info, parts }) where the user message info carries the resolved agent and model, and that with noReply: true no LLM call is made so the unreachable mock provider is never contacted. Session create accepts and persists agent, and GET /session/:sessionID exposes it.

Files Reviewed (3 files)
  • .changeset/calm-agents-wait.md
  • packages/opencode/src/session/prompt.ts
  • packages/opencode/test/kilocode/headless-session-agent.test.ts
Previous Review Summary (commit c1a6c3f)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c1a6c3f)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0

The one-line fix in prompt.ts is correct and well-scoped: it falls back to the session's stored agent when input.agent is absent, keeps explicit prompt-level agents taking precedence, and preserves the default-agent path for sessions without one. The changeset is user-facing and the change is properly marked for fork hygiene.

However, the new regression test targets a non-existent route (/session/:id/prompt instead of /session/:id/message), so it will fail once dependencies allow it to run — consistent with the PR note that the test could not be executed locally.

Fix these issues in Kilo Cloud

Issue Details (click to expand)

CRITICAL

File Line Issue
packages/opencode/test/kilocode/headless-session-agent.test.ts 52 Test posts to /session/:id/prompt, which does not exist; the v1 prompt endpoint is /session/:id/message. The request hits the UI catch-all and returns 404, failing the test.
Files Reviewed (3 files)
  • .changeset/calm-agents-wait.md - no issues
  • packages/opencode/src/session/prompt.ts - no issues
  • packages/opencode/test/kilocode/headless-session-agent.test.ts - 1 issue

Reviewed by kimi-k3 · Input: 141.5K · Output: 10.7K · Cached: 1.2M

Review guidance: REVIEW.md from base branch main

Send the regression test request through the v1 session message endpoint
so it reaches the synchronous prompt handler.

Addresses review feedback on Kilo-Org#13102.
@johnnyeric
johnnyeric enabled auto-merge (squash) August 13, 2026 20:09
@johnnyeric

Copy link
Copy Markdown
Contributor

Thanks for pushing this fix!

@johnnyeric
johnnyeric merged commit f4cba05 into Kilo-Org:main Aug 13, 2026
32 checks passed
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
* fix(cli): preserve session agent for headless prompts

Fall back to the agent selected during session creation when a headless
prompt does not specify one. This preserves custom agent models and
permissions instead of resetting the session to the default code agent.

Fixes Kilo-Org#13027

* test(cli): use the correct headless prompt endpoint

Send the regression test request through the v1 session message endpoint
so it reaches the synchronous prompt handler.

Addresses review feedback on Kilo-Org#13102.
johnnyeric added a commit that referenced this pull request Aug 14, 2026
Omitting the frontend default left session.agent=ask in place after #13102, so Code turns still used Ask. Persist a permission-neutral Ask-to-Code reminder so prior Ask replies no longer override the current agent.

Co-authored-by: Cursor <cursoragent@cursor.com>
johnnyeric added a commit that referenced this pull request Aug 14, 2026
Omitting the frontend default left session.agent=ask in place after #13102, so Code turns still used Ask. Persist a permission-neutral Ask-to-Code reminder so prior Ask replies no longer override the current agent.
johnnyeric added a commit that referenced this pull request Aug 14, 2026
* fix: keep Code agent after switching from Ask

Omitting the frontend default left session.agent=ask in place after #13102, so Code turns still used Ask. Persist a permission-neutral Ask-to-Code reminder so prior Ask replies no longer override the current agent.

* test(vscode): cover explicit Ask to Code agent send

Extract resolvePromptAgent and assert Code after Ask, pending Code, and omitted selection.
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.

Headless: session.create(agent=test-engineer) resolves to agent=code on first prompt (7.4.x)

2 participants