Skip to content

Feat: Store LLM Metrics (Model, Cost, Turns) in Persistent State for UI #69

Closed

Description

@integry

🎯 Goal

Update the WorkerStateManager to persistently store key LLM metrics (model, cost, turns, conversation ID) from Claude's execution. This data is required for display in a future web UI to monitor task details.

📝 Context

Currently, the claudeResult object (which contains all necessary metrics like model, finalResult.cost_usd, finalResult.num_turns, and conversationId) is correctly returned from claudeService.js to worker.js.

However, the worker only saves a partial subset of this data to the Redis state manager.

  1. src/utils/workerStateManager.js in the updateTaskState function only saves success, sessionId, and executionTime (lines 109-115).
  2. src/worker.js in processGitHubIssueJob never calls updateTaskState with the claudeResult object after Claude execution finishes (around line 220).

This issue will address both shortcomings.

🚀 Implementation Steps

  1. File: src/utils/workerStateManager.js

    • Action: Modify the updateTaskState function.
    • Logic: Expand the if (metadata.claudeResult) block (around line 109) to capture the full metrics.
    • Suggestion:
      // ... inside updateTaskState ...
      if (metadata.claudeResult) {
          state.claudeResult = {
              success: metadata.claudeResult.success,
              sessionId: metadata.claudeResult.sessionId,
              executionTime: metadata.claudeResult.executionTime,
              // Add these new fields:
              model: metadata.claudeResult.model || null,
              conversationId: metadata.claudeResult.conversationId || null,
              finalResult: metadata.claudeResult.finalResult ? {
                  num_turns: metadata.claudeResult.finalResult.num_turns || null,
                  cost_usd: metadata.claudeResult.finalResult.cost_usd || null,
                  subtype: metadata.claudeResult.finalResult.subtype || null
              } : null
          };
      }
      // ...
  2. File: src/worker.js

    • Action: Modify the processGitHubIssueJob function.
    • Logic: After claudeResult is received from executeClaudeCode (around line 220), add a call to stateManager.updateTaskState to persist these metrics.
    • Suggestion:
      // ... inside processGitHubIssueJob ...
          // (Around line 220)
          claudeResult = await executeClaudeCode({
              worktreePath: worktreeInfo.worktreePath,
              issueRef: issueRef,
              githubToken: githubToken.token
          });
          
          // ADD THIS BLOCK:
          try {
              await stateManager.updateTaskState(taskId, TaskStates.CLAUDE_EXECUTION, {
                  reason: 'Claude execution completed',
                  claudeResult: claudeResult // Pass the full result object
              });
          } catch (stateError) {
              correlatedLogger.warn({
                  taskId,
                  error: stateError.message
              }, 'Failed to update task state with Claude results');
          }
          // END ADDED BLOCK
          
          correlatedLogger.info({
          // ... (rest of the log message)

Activity

  1. propr-dev commented on Sep 16, 2025

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude-opus-4-20250514 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Model: claude-opus-4-20250514
    • Branch: ai-fix/69-feat-store-llm-metrics-mo-20250916-1334-claude-opus-4-20250514-3wn
    • Base Branch: main
    • Worktree: issue-69-20250916-1334-claude-opus-4-20250514-3wn
  2. added a commit that references this issue on Sep 16, 2025
  3. added a commit that references this issue on Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions