Skip to content

Fix: GetInsightActiveRoomModel in agent run - #3082

Open
ckelly17 wants to merge 2 commits into
devfrom
claude/mcp-tool-model-detection-runagent-15bhlm
Open

ckelly17 wants to merge 2 commits into
devfrom
claude/mcp-tool-model-detection-runagent-15bhlm

Conversation

@ckelly17

@ckelly17 ckelly17 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Overview

GetInsightActiveRoomModelReactor only checked options.modelId from a fresh DB fetch of the room.
AgentRunner resolves the model through up to four tiers and sets it only on the cached Room object,
never writing it back to the options JSON. The reactor therefore always missed it.

The impact is that anything happening in the agent run that might rely on that reactor silently fails.

Changes

Two changes in GetInsightActiveRoomModelReactor.execute():

1. Use RoomUtils.getOrLoadRoom() instead of ModelInferenceLogsUtils.getRoomById().
getOrLoadRoom checks the user's in-memory room cache first (insight.getUser().getRoomHash()).
During an agent run, AgentRunner already resolved and set the model on that cached Room via
room.setModelId(modelId). The old DB fetch bypassed the cache entirely and got a stale copy
with no model set.

2. Broaden the model-ID lookup to match AgentRunner.resolveModelId().
The old code only checked optionsMap.get("modelId") (the options JSON blob, written by the
playground). The fix checks in priority order:

  • Tier 1 — optionsMap.get("modelId") — playground path, preserved as-is.
  • Tier 2 — room.getModelId() — the MODEL_ID column, set on room creation when
    engine= is passed to RunAgent, and also set by AgentRunner on the cached room after
    resolving from any tier.
  • Tier 3 — legacy option keys: engine, model, engineId — written by older callers.

Reproduction and Testing

In order to demonstrate the error, completed the following test cases:

All runs used workspace 4b862ba6 ("MCP Model Detection Test") with Pixel MCP project ac57474e
("Model Probe MCP") and tool GetInsightActiveRoomModel. Model engine in all cases:
aa876e7e (Claude Sonnet 4-6 Vertex).

# Room creation Model resolved via Before fix After fix
1 RunAgent(engine=[...]) — new room Tier 1: explicit engine= param No model associated with the room aa876e7e-... ✓
2 Same room, second run, no engine= Tier 2: room MODEL_ID column No model associated with the room aa876e7e-... ✓
3 CreateRoom(workspaceId=[...]) then RunAgent with no engine= Tier 4: workspace CONFIG_JSON.model_id No model associated with the room aa876e7e-... ✓

A null room now throws a clear IllegalArgumentException instead of an NPE.

…iveRoomModel

GetInsightActiveRoomModel only read options.modelId from the stored ROOM
row. The playground writes that key, but RunAgent resolves the model from
engine=, ROOM.MODEL_ID, legacy option keys or the workspace config and
only sets it on the cached Room, so MCP tools in an agent run got
"No model associated with the room".

Keep options.modelId first so playground behaviour is unchanged, then
fall back to the cached room's model id, the stored MODEL_ID column and
the legacy engine/model/engineId option keys. A missing room now gives a
clear error instead of a NullPointerException.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AEekNvT8xFqvVam2ADu1Hu
@ckelly17
ckelly17 requested a review from a team as a code owner October 3, 2026 18:51
@snyk-io

snyk-io Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@ckelly17 ckelly17 changed the title fix(insights): resolve room model for RunAgent tools in GetInsightAct… Fix: GetInsightActiveRoomModel in agent run Oct 3, 2026
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