Skip to content

fix(chat-message): refresh stale session-agent cache from explicit input.agent#2965

Open
sjawhar wants to merge 1 commit intocode-yeongyu:devfrom
sjawhar:fix/chat-message-session-cache
Open

fix(chat-message): refresh stale session-agent cache from explicit input.agent#2965
sjawhar wants to merge 1 commit intocode-yeongyu:devfrom
sjawhar:fix/chat-message-session-cache

Conversation

@sjawhar
Copy link
Copy Markdown
Contributor

@sjawhar sjawhar commented Mar 30, 2026

Summary

  • When chat.message receives a turn with an explicit input.agent, update the session-agent map unconditionally instead of ignoring it if a value already exists
  • Adds regression test covering the stale-agent scenario

Problem

setSessionAgent uses first-write-wins semantics (only writes if key doesn't exist). This is correct for initial session setup (e.g. delegate-task/sync-task.ts initializing a subagent session), but wrong in chat-message.ts where OpenCode delivers an explicit agent on every turn.

Any programmatic caller that sends session.promptAsync with an explicit agent to an already-initialized session gets silently ignored — the session stays pinned to whatever agent was set first. This affects:

  • External integrations calling the session API directly
  • opencode run with --agent on a resumed session
  • Any MCP client interacting with existing sessions

Normal TUI agent switching is unaffected (it goes through different code paths).

Changes

src/plugin/chat-message.ts (2 lines)

  • Import updateSessionAgent alongside existing setSessionAgent
  • Replace setSessionAgent(input.sessionID, input.agent) with updateSessionAgent(input.sessionID, input.agent)

src/plugin/chat-message.test.ts (13 lines)

  • New test: pre-sets agent to "hephaestus", sends turn with input.agent = "build", verifies map updates to "build"

Summary by cubic

Refreshes the session agent on every turn when input.agent is provided, replacing first-write-wins behavior in the chat-message handler. Prevents sessions from sticking to the first-set agent for external callers, resumed sessions with --agent, and MCP clients.

  • Bug Fixes
    • Replace setSessionAgent with updateSessionAgent in src/plugin/chat-message.ts.
    • Add regression test to ensure agent updates from "hephaestus" to "build".

Written for commit 7351a53. Summary will update on new commits.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Fixes a stale cache bug by allowing explicit agent updates in the chat handler. The change is localized, logically sound, and includes a regression test.

…put.agent

resolve: rebase conflict in chat-message test
@sjawhar sjawhar force-pushed the fix/chat-message-session-cache branch from 9605378 to 7351a53 Compare April 3, 2026 21:47
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.

1 participant