Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@
/apps/sim/app/api/mothership/execute/ @simstudioai/mothership

# Server-side stream orchestration, persistence, and protocol.
/apps/sim/lib/copilot/chat/ @simstudioai/mothership
/apps/sim/lib/copilot/async-runs/ @simstudioai/mothership
/apps/sim/lib/copilot/request/ @simstudioai/mothership
/apps/sim/lib/copilot/generated/ @simstudioai/mothership
/apps/sim/lib/copilot/constants.ts @simstudioai/mothership
/apps/sim/lib/mothership/chat/ @simstudioai/mothership
/apps/sim/lib/mothership/async-runs/ @simstudioai/mothership
/apps/sim/lib/mothership/request/ @simstudioai/mothership
/apps/sim/lib/mothership/generated/ @simstudioai/mothership
/apps/sim/lib/mothership/observability/ @simstudioai/mothership
/apps/sim/lib/mothership/constants.ts @simstudioai/mothership
/apps/sim/lib/core/utils/sse.ts @simstudioai/mothership

# Stream-time tool execution, confirmations, resource persistence, and handlers.
/apps/sim/lib/copilot/tool-executor/ @simstudioai/mothership
/apps/sim/lib/copilot/tools/ @simstudioai/mothership
/apps/sim/lib/copilot/persistence/ @simstudioai/mothership
/apps/sim/lib/copilot/resources/ @simstudioai/mothership
/apps/sim/lib/mothership/tool-executor/ @simstudioai/mothership
/apps/sim/lib/mothership/tools/ @simstudioai/mothership
/apps/sim/lib/mothership/persistence/ @simstudioai/mothership
/apps/sim/lib/mothership/resources/ @simstudioai/mothership

# Client-side stream consumption, hydration, and reconnect.
/apps/sim/app/workspace/*/home/hooks/index.ts @simstudioai/mothership
/apps/sim/app/workspace/*/home/hooks/use-chat.ts @simstudioai/mothership
/apps/sim/app/workspace/*/home/hooks/preview/ @simstudioai/mothership
/apps/sim/app/workspace/*/home/hooks/stream/ @simstudioai/mothership
/apps/sim/hooks/queries/tasks.ts @simstudioai/mothership
/apps/sim/hooks/queries/mothership-tasks.ts @simstudioai/mothership

# Dependency manifests and package-manager config. Any change here — adding,
# removing, or bumping a dependency, or altering install/security settings —
Expand Down
221 changes: 0 additions & 221 deletions apps/sim/app/api/billing/update-cost/replay.live.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/sim/app/api/billing/update-cost/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('POST /api/billing/update-cost — workspaceId attribution', () => {
})
})

it('keeps the worker callback protocol aligned with the Go-produced wire constants', () => {
it('keeps the callback protocol aligned with the worker wire constants', () => {
expect(Object.values(BillingProtocol).sort()).toEqual(
Object.values(COPILOT_BILLING_PROTOCOL).sort()
)
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('POST /api/billing/update-cost — workspaceId attribution', () => {
expect(mockRecordCumulativeUsage).not.toHaveBeenCalled()
})

it('returns no-op success for markerless local self-hosted Go when billing is disabled', async () => {
it('returns no-op success for a markerless self-hosted caller when billing is disabled', async () => {
setEnvFlags({ isBillingEnabled: false })

const res = await POST(
Expand Down
22 changes: 11 additions & 11 deletions apps/sim/app/api/billing/update-cost/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ import { generateRequestId } from '@/lib/core/utils/request'
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
import { BillingInFlightCode } from '@/lib/mothership/generated/billing'
import { BILLING_CALLBACK_OUTCOME } from '@/lib/mothership/generated/billing-protocol-v1'
import { BillingRouteOutcome } from '@/lib/mothership/generated/trace-attribute-values-v1'
import { TraceAttr } from '@/lib/mothership/generated/trace-attributes-v1'
import { TraceSpan } from '@/lib/mothership/generated/trace-spans-v1'
import { recordJobRunSpend } from '@/lib/mothership/jobs/budget'
import { BillingRouteOutcome } from '@/lib/mothership/observability/trace-attribute-values'
import { TraceAttr } from '@/lib/mothership/observability/trace-attributes'
import { TraceSpan } from '@/lib/mothership/observability/trace-spans'
import { checkInternalApiKey } from '@/lib/mothership/request/http'
import { withIncomingGoSpan } from '@/lib/mothership/request/otel'
import { withIncomingWorkerSpan } from '@/lib/mothership/request/otel'

const logger = createLogger('BillingUpdateCostAPI')
/**
Expand Down Expand Up @@ -174,13 +174,13 @@ function getBillingResolution(
* POST /api/billing/update-cost
* Update user cost with a pre-calculated cost value (internal API key auth required)
*
* Parented under the Go-side `sim.update_cost` span via W3C traceparent
* propagation. Every mothership request that bills should therefore show
* the Go client span AND this Sim server span sharing one trace, with
* Parented under the worker's span via W3C traceparent propagation. Every
* mothership request that bills should therefore show the worker's span AND
* this Sim server span sharing one trace, with
* the actual usage/overage work nested below.
*/
export const POST = withRouteHandler((req: NextRequest) =>
withIncomingGoSpan(
withIncomingWorkerSpan(
req.headers,
TraceSpan.CopilotBillingUpdateCost,
{
Expand Down Expand Up @@ -417,7 +417,7 @@ async function updateCostInner(req: NextRequest, span: Span): Promise<NextRespon
})

/**
* Go sends cumulative cost across partial, terminal, and retry flushes.
* The worker sends cumulative cost across partial, terminal, and retry flushes.
* Every accepted callback has a stable key, so the maximum cumulative cost
* converges on one ledger event without underbilling or double-billing.
*/
Expand Down Expand Up @@ -456,7 +456,7 @@ async function updateCostInner(req: NextRequest, span: Span): Promise<NextRespon

// Reconcile the payer's ledger-backed threshold after every cumulative
// callback, including duplicate retries after a prior settlement failure.
// Strict error handling lets Go retry until the committed usage is settled.
// Strict error handling lets the worker retry until the committed usage is settled.
if (billingContext) {
try {
await checkAndBillPayerOverageThreshold(billingContext.billingEntity, {
Expand Down Expand Up @@ -492,7 +492,7 @@ async function updateCostInner(req: NextRequest, span: Span): Promise<NextRespon
const duration = Date.now() - startTime

// Same-or-lower cumulative than already recorded: nothing new to bill.
// Reconciliation has completed, so preserve Go's established 409 outcome.
// Reconciliation has completed, so return the 409 the worker reads as already settled.
if (!billed) {
logger.info('Duplicate/non-increasing cumulative cost; no new charge', {
idempotencyKey,
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/copilot/api-keys/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { GET } from '@/app/api/copilot/api-keys/route'

const mockGetMothershipBaseURL = mothershipAgentUrlMockFns.mockGetMothershipBaseURL

// `fetchGo` reads `response.status` and `response.headers.get('content-length')`
// `fetchWorker` reads `response.status` and `response.headers.get('content-length')`
// to stamp span attributes, so mock responses need both fields or the call
// path throws before the route handler sees the body.
function buildMockResponse(init: {
Expand Down
16 changes: 8 additions & 8 deletions apps/sim/app/api/copilot/api-keys/validate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ import {
COPILOT_VALIDATION_PURPOSE,
type CopilotBillingProtocol,
} from '@/lib/mothership/generated/billing-protocol-v1'
import { CopilotValidateOutcome } from '@/lib/mothership/generated/trace-attribute-values-v1'
import { TraceAttr } from '@/lib/mothership/generated/trace-attributes-v1'
import { TraceSpan } from '@/lib/mothership/generated/trace-spans-v1'
import { CopilotValidateOutcome } from '@/lib/mothership/observability/trace-attribute-values'
import { TraceAttr } from '@/lib/mothership/observability/trace-attributes'
import { TraceSpan } from '@/lib/mothership/observability/trace-spans'
import { checkInternalApiKey } from '@/lib/mothership/request/http'
import { withIncomingGoSpan } from '@/lib/mothership/request/otel'
import { withIncomingWorkerSpan } from '@/lib/mothership/request/otel'

const logger = createLogger('CopilotApiKeysValidate')

Expand Down Expand Up @@ -92,7 +92,7 @@ type AdmissionBillingDecision =
}

/**
* Resolves new-turn admission against the versioned Go callback protocol.
* Resolves new-turn admission against the versioned worker callback protocol.
*
* Markerless self-hosted admission is legacy-v0. A locally resolvable
* workspace selects its current payer; an absent or opaque workspace preserves
Expand Down Expand Up @@ -313,13 +313,13 @@ async function checkAdmissionUsage(admission: AdmissionBillingDecision): Promise
}

/**
* Incoming-from-Go: extracts traceparent so this handler's work shows up as
* a child of the Go-side `sim.validate_api_key` span in the same trace. If
* Incoming from the worker: extracts traceparent so this handler's work shows
* up as a child of the worker's span in the same trace. If
* there's no traceparent (manual curl / browser), the helper falls back to a
* new root span.
*/
export const POST = withRouteHandler((req: NextRequest) =>
withIncomingGoSpan(
withIncomingWorkerSpan(
req.headers,
TraceSpan.CopilotAuthValidateApiKey,
{
Expand Down
Loading
Loading