Skip to content

chore(internal): Fix cost bug#313

Merged
declan-scale merged 1 commit intonextfrom
declan-scale/address-cost-bug
Apr 7, 2026
Merged

chore(internal): Fix cost bug#313
declan-scale merged 1 commit intonextfrom
declan-scale/address-cost-bug

Conversation

@declan-scale
Copy link
Copy Markdown
Contributor

@declan-scale declan-scale commented Apr 7, 2026

Greptile Summary

This PR fixes cost tracking in run_claude_agent_activity by correctly reading message.total_cost_usd from the ResultMessage and surfacing it as cost_usd in the activity return dict, aligning with the pattern used in the sibling message_handler.py. The fix is covered by an existing test assertion (result["cost_usd"] == 0.05) and introduces no other changes.

Confidence Score: 5/5

Safe to merge — the fix correctly captures total_cost_usd from ResultMessage and no regressions are introduced.

Single-file change fixing a named field access bug, consistent with sibling handler patterns, and covered by an existing test assertion. All remaining findings are at most P2.

No files require special attention.

Important Files Changed

Filename Overview
src/agentex/lib/core/temporal/plugins/claude_agents/activities.py Fixes cost tracking bug by reading total_cost_usd from ResultMessage and returning it as cost_usd; logic is clean and consistent with sibling handler.

Sequence Diagram

sequenceDiagram
    participant W as Temporal Workflow
    participant A as run_claude_agent_activity
    participant C as ClaudeSDKClient
    participant S as AgentEx Streaming

    W->>A: call activity(prompt, workspace, tools, ...)
    A->>C: client.query(prompt)
    loop Message Stream
        C-->>A: AssistantMessage (TextBlock / ThinkingBlock / ToolUseBlock)
        A->>S: stream text delta / reasoning / tool request
        C-->>A: SystemMessage (subtype=init, capture session_id)
        C-->>A: ResultMessage (total_cost_usd, usage, session_id)
        A->>A: cost_info = message.total_cost_usd
    end
    A->>S: close text stream
    A-->>W: {messages, session_id, usage, cost_usd}
Loading

Reviews (1): Last reviewed commit: "Fix cost bug" | Re-trigger Greptile

@declan-scale declan-scale merged commit 8a12466 into next Apr 7, 2026
9 checks passed
@declan-scale declan-scale deleted the declan-scale/address-cost-bug branch April 7, 2026 21:18
stainless-app bot pushed a commit that referenced this pull request Apr 7, 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.

1 participant