From 1bf4a1d478d64a57bf2e15a7e6e4b44a2a127002 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Sun, 21 Dec 2025 16:47:42 +0000 Subject: [PATCH] fix: emit state after refreshing runtime info so clients get model updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Claude agent model was not showing in the UI ("Model: Unknown") because refreshRuntimeInfo() updated agent.runtimeInfo but never called emitState() to notify connected clients of the change. Fixed by: 1. Adding change detection in refreshRuntimeInfo() to check if model, sessionId, or modeId changed 2. Calling emitState(agent) when changes are detected 3. Added debug logging in handleSystemMessage() to confirm model capture 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- packages/server/src/server/agent/agent-manager.ts | 11 ++++++++++- .../src/server/agent/providers/claude-agent.ts | 1 + plan.md | 12 +++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/server/src/server/agent/agent-manager.ts b/packages/server/src/server/agent/agent-manager.ts index f7fce1496..f1c973ee1 100644 --- a/packages/server/src/server/agent/agent-manager.ts +++ b/packages/server/src/server/agent/agent-manager.ts @@ -782,7 +782,16 @@ export class AgentManager { private async refreshRuntimeInfo(agent: ActiveManagedAgent): Promise { try { - agent.runtimeInfo = await agent.session.getRuntimeInfo(); + const newInfo = await agent.session.getRuntimeInfo(); + const changed = + newInfo.model !== agent.runtimeInfo?.model || + newInfo.sessionId !== agent.runtimeInfo?.sessionId || + newInfo.modeId !== agent.runtimeInfo?.modeId; + agent.runtimeInfo = newInfo; + // Emit state if runtimeInfo changed so clients get the updated model + if (changed) { + this.emitState(agent); + } } catch { // Keep existing runtimeInfo if refresh fails. } diff --git a/packages/server/src/server/agent/providers/claude-agent.ts b/packages/server/src/server/agent/providers/claude-agent.ts index 39b2f7304..51c7afaa5 100644 --- a/packages/server/src/server/agent/providers/claude-agent.ts +++ b/packages/server/src/server/agent/providers/claude-agent.ts @@ -875,6 +875,7 @@ class ClaudeAgentSession implements AgentSession { this.persistence = null; // Capture actual model from SDK init message (not just the configured model) if (message.model) { + console.log(`[ClaudeAgentSession] Captured model from SDK init: ${message.model}`); this.lastOptionsModel = message.model; // Invalidate cached runtime info so it picks up the new model this.cachedRuntimeInfo = null; diff --git a/plan.md b/plan.md index 889793018..0a203da6d 100644 --- a/plan.md +++ b/plan.md @@ -122,12 +122,13 @@ Hard requirement: We must get the actual runtime model, not just echo back the r - If issues found: add fix tasks immediately after this task, then add re-test task after fixes. - **Done (2025-12-21 13:50)**: FAILED. Created Claude agent with "Automatic" model config. Agent self-reported running on `claude-opus-4-1-20250805` (Opus 4.1), but UI shows **Model: Unknown** in agent info menu. The implementation to capture model from SDK init message is not working - model is not being propagated to the UI. -- [ ] **Fix**: Debug and fix Claude agent model capture from SDK init message. +- [x] **Fix**: Debug and fix Claude agent model capture from SDK init message. - Check server logs to see if `handleSystemMessage()` is receiving the init message with model - Verify `this.lastOptionsModel` is being set correctly - Check if `getRuntimeInfo()` is being called after stream completion - Ensure runtime info is being persisted and sent to client via WebSocket - The model should show `claude-opus-4-1-20250805` instead of "Unknown" + - **Done (2025-12-21 14:10)**: Found and fixed the bug. The issue was in `agent-manager.ts:refreshRuntimeInfo()` - it updated `agent.runtimeInfo` but never called `emitState(agent)` to notify clients. Fixed by adding change detection and emitting state when runtimeInfo changes. Also added debug logging to `handleSystemMessage()` to confirm model capture from SDK init message. Typecheck passes. - [ ] **Test**: Re-verify Claude agent model display after fix. - Create a new Claude agent with default model @@ -141,6 +142,15 @@ Hard requirement: We must get the actual runtime model, not just echo back the r - Add implementation tasks if improvements needed - Add fix tasks if tests reveal issues +- [ ] **Plan**: Fix agent git diff not loading. + + - Investigate why git diff is not loading in agent view. + - Find where git diff is fetched and rendered. + - Identify the root cause of the loading failure. + - Add implementation/fix tasks based on findings. + - Add test task to verify git diff loads correctly via Playwright MCP. + - Add another **Plan** task to re-audit after fix if needed. + - [ ] **Plan**: Design and implement agent parent/child hierarchy. - Add `parentId` field to agents.