Skip to content

fix(mothership): billing for mcps, hosted key tools#5740

Merged
icecrasher321 merged 3 commits into
stagingfrom
fix/mship-bugs-2
Jul 17, 2026
Merged

fix(mothership): billing for mcps, hosted key tools#5740
icecrasher321 merged 3 commits into
stagingfrom
fix/mship-bugs-2

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

Correctly bill for MCP executions + hosted key tools in the mothership.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@icecrasher321
icecrasher321 requested a review from a team as a code owner July 17, 2026 19:47
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 17, 2026 7:47pm

Request Review

@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches billing attribution and dual billing paths (ledger vs Go service cost); incorrect flags could under- or over-charge, though workflow double-billing is explicitly guarded.

Overview
Fixes missing charges when Mothership/copilot runs MCP tools and hosted-key integrations that bypass the workflow execution ledger.

The copilot tool executor now copies billingAttribution into _context for dynamic app/MCP tool calls (when present), so internal routes can send the billing-attribution header and MCP execution can require attribution. llm_chat forwards workspaceId from _context in the /api/providers body so that header validates correctly.

For hosted-key tool spend, applyHostedKeyCostToResult still sets output.cost, but also adds top-level _serviceCost when copilotToolExecution is true so Go’s per-round extractServiceCost path can bill—matching media tools. Workflow runs omit _serviceCost to avoid double billing with the execution ledger.

Tests cover attribution threading, copilot vs workflow _serviceCost behavior, and lockfile updates for lucide-react resolution.

Reviewed by Cursor Bugbot for commit b904c8b. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates billing context and hosted-key cost reporting for copilot tool executions. The main changes are:

  • Propagate billing attribution into dynamically dispatched tool context.
  • Emit hosted-key service costs for copilot calls without double-billing workflow runs.
  • Include workspace context in internal LLM provider requests.
  • Add tests for attribution propagation and caller-specific cost reporting.
  • Update dependency resolutions in bun.lock.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • Copilot and workflow billing remain separated by the existing execution-scope flag.
  • Workspace forwarding matches the provider route's existing request contract and billing validation.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/tool-executor/executor.ts Conditionally propagates billing attribution into the trusted dynamic-tool context.
apps/sim/lib/copilot/tool-executor/executor.test.ts Tests billing-attribution propagation and omission for dynamic tools.
apps/sim/tools/index.ts Adds copilot-only hosted-key service-cost output while retaining workflow ledger billing.
apps/sim/tools/index.test.ts Tests service-cost emission for copilot calls and suppression for workflow calls.
apps/sim/tools/llm/chat.ts Adds the execution workspace to internal provider requests when available.
bun.lock Updates lucide-react dependency resolutions and lockfile metadata.

Reviews (1): Last reviewed commit: "fix llm chat tool" | Re-trigger Greptile

@icecrasher321
icecrasher321 changed the base branch from dev to staging July 17, 2026 19:55
@icecrasher321
icecrasher321 merged commit 3453692 into staging Jul 17, 2026
20 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/mship-bugs-2 branch July 18, 2026 05:36
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