Skip to content

Commit 6eee122

Browse files
committed
chore(mothership): take the worker's typed stream and pruned telemetry contracts, and rename go-era names to worker
1 parent dfff8c3 commit 6eee122

153 files changed

Lines changed: 1076 additions & 4056 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/CODEOWNERS‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
/apps/sim/app/api/mothership/execute/ @simstudioai/mothership
88

99
# Server-side stream orchestration, persistence, and protocol.
10-
/apps/sim/lib/copilot/chat/ @simstudioai/mothership
11-
/apps/sim/lib/copilot/async-runs/ @simstudioai/mothership
12-
/apps/sim/lib/copilot/request/ @simstudioai/mothership
13-
/apps/sim/lib/copilot/generated/ @simstudioai/mothership
14-
/apps/sim/lib/copilot/constants.ts @simstudioai/mothership
10+
/apps/sim/lib/mothership/chat/ @simstudioai/mothership
11+
/apps/sim/lib/mothership/async-runs/ @simstudioai/mothership
12+
/apps/sim/lib/mothership/request/ @simstudioai/mothership
13+
/apps/sim/lib/mothership/generated/ @simstudioai/mothership
14+
/apps/sim/lib/mothership/constants.ts @simstudioai/mothership
1515
/apps/sim/lib/core/utils/sse.ts @simstudioai/mothership
1616

1717
# Stream-time tool execution, confirmations, resource persistence, and handlers.
18-
/apps/sim/lib/copilot/tool-executor/ @simstudioai/mothership
19-
/apps/sim/lib/copilot/tools/ @simstudioai/mothership
20-
/apps/sim/lib/copilot/persistence/ @simstudioai/mothership
21-
/apps/sim/lib/copilot/resources/ @simstudioai/mothership
18+
/apps/sim/lib/mothership/tool-executor/ @simstudioai/mothership
19+
/apps/sim/lib/mothership/tools/ @simstudioai/mothership
20+
/apps/sim/lib/mothership/persistence/ @simstudioai/mothership
21+
/apps/sim/lib/mothership/resources/ @simstudioai/mothership
2222

2323
# Client-side stream consumption, hydration, and reconnect.
2424
/apps/sim/app/workspace/*/home/hooks/index.ts @simstudioai/mothership

‎apps/sim/app/api/billing/update-cost/route.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe('POST /api/billing/update-cost — workspaceId attribution', () => {
169169
})
170170
})
171171

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

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

236236
const res = await POST(

‎apps/sim/app/api/billing/update-cost/route.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { TraceAttr } from '@/lib/mothership/generated/trace-attributes-v1'
5252
import { TraceSpan } from '@/lib/mothership/generated/trace-spans-v1'
5353
import { recordJobRunSpend } from '@/lib/mothership/jobs/budget'
5454
import { checkInternalApiKey } from '@/lib/mothership/request/http'
55-
import { withIncomingGoSpan } from '@/lib/mothership/request/otel'
55+
import { withIncomingWorkerSpan } from '@/lib/mothership/request/otel'
5656

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

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

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

494494
// Same-or-lower cumulative than already recorded: nothing new to bill.
495-
// Reconciliation has completed, so preserve Go's established 409 outcome.
495+
// Reconciliation has completed, so return the 409 the worker reads as already settled.
496496
if (!billed) {
497497
logger.info('Duplicate/non-increasing cumulative cost; no new charge', {
498498
idempotencyKey,

‎apps/sim/app/api/copilot/api-keys/route.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { GET } from '@/app/api/copilot/api-keys/route'
2626

2727
const mockGetMothershipBaseURL = mothershipAgentUrlMockFns.mockGetMothershipBaseURL
2828

29-
// `fetchGo` reads `response.status` and `response.headers.get('content-length')`
29+
// `fetchWorker` reads `response.status` and `response.headers.get('content-length')`
3030
// to stamp span attributes, so mock responses need both fields or the call
3131
// path throws before the route handler sees the body.
3232
function buildMockResponse(init: {

‎apps/sim/app/api/copilot/api-keys/validate/route.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { CopilotValidateOutcome } from '@/lib/mothership/generated/trace-attribu
6262
import { TraceAttr } from '@/lib/mothership/generated/trace-attributes-v1'
6363
import { TraceSpan } from '@/lib/mothership/generated/trace-spans-v1'
6464
import { checkInternalApiKey } from '@/lib/mothership/request/http'
65-
import { withIncomingGoSpan } from '@/lib/mothership/request/otel'
65+
import { withIncomingWorkerSpan } from '@/lib/mothership/request/otel'
6666

6767
const logger = createLogger('CopilotApiKeysValidate')
6868

@@ -92,7 +92,7 @@ type AdmissionBillingDecision =
9292
}
9393

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

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

‎apps/sim/app/api/copilot/byok/validate/route.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const logger = createLogger('CopilotByokValidate')
1212

1313
/**
1414
* Authoritative entitlement gate for enterprise BYOK, called server-to-server by
15-
* the mothership (Go) before it uses a workspace's own provider key. Gated by
15+
* the mothership worker before it uses a workspace's own provider key. Gated by
1616
* INTERNAL_API_SECRET — never exposed to the browser.
1717
*
1818
* Returns 200 when EITHER:
@@ -22,7 +22,7 @@ const logger = createLogger('CopilotByokValidate')
2222
* another org's stored key to be used) AND the workspace is on an
2323
* enterprise plan.
2424
*
25-
* Any other case returns 403 (not entitled) or 401 (bad internal auth). The Go
25+
* Any other case returns 403 (not entitled) or 401 (bad internal auth). The
2626
* caller fails closed to hosted keys on anything but a 200.
2727
*/
2828
export const POST = withRouteHandler(async (req: NextRequest) => {

‎apps/sim/app/api/copilot/chat/steer/route.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('POST /api/copilot/chat/steer', () => {
6666
mockAppend.mockResolvedValue(undefined)
6767
})
6868

69-
it('returns 409 when Go rejects the steer so the client falls back to a normal send', async () => {
69+
it('returns 409 when the worker rejects the steer so the client falls back to a normal send', async () => {
7070
mockRequestStreamSteering.mockResolvedValue({ queued: false, status: 429 })
7171

7272
const response = await POST(steerRequest())

‎apps/sim/app/api/copilot/chat/steer/route.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
SteeringNotQueuedError,
1414
steerRun,
1515
} from '@/lib/mothership/request/application/controls'
16-
import { withIncomingGoSpan } from '@/lib/mothership/request/otel'
16+
import { withIncomingWorkerSpan } from '@/lib/mothership/request/otel'
1717

1818
const handler = defineInternalJsonRoute({
1919
contract: copilotChatSteerContract,
@@ -26,14 +26,14 @@ const handler = defineInternalJsonRoute({
2626
errorPolicy: {
2727
project: (error) =>
2828
error instanceof SteeringNotQueuedError
29-
? internalErrorResponse(409, { ok: false, queued: false, goStatus: error.goStatus })
29+
? internalErrorResponse(409, { ok: false, queued: false, workerStatus: error.workerStatus })
3030
: internalOrchestrationErrorPolicy.project(error),
3131
},
3232
mapInput: ({ body }) => body,
3333
useCase: steerRun,
3434
})
3535

3636
export const POST = (request: NextRequest, context?: Parameters<typeof handler>[1]) =>
37-
withIncomingGoSpan(request.headers, TraceSpan.CopilotChatSteerStream, undefined, () =>
37+
withIncomingWorkerSpan(request.headers, TraceSpan.CopilotChatSteerStream, undefined, () =>
3838
handler(request, context)
3939
)

‎apps/sim/app/api/copilot/confirm/route.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
createRequestTracker,
3434
createUnauthorizedResponse,
3535
} from '@/lib/mothership/request/http'
36-
import { withIncomingGoSpan } from '@/lib/mothership/request/otel'
36+
import { withIncomingWorkerSpan } from '@/lib/mothership/request/otel'
3737
import { sealClientToolSettlement } from '@/lib/mothership/request/tools/client-completion-seal.server'
3838
import {
3939
type ClientToolSettlementGuard,
@@ -165,7 +165,7 @@ async function updateToolCallStatus(
165165
export const POST = withRouteHandler((req: NextRequest) => {
166166
const tracker = createRequestTracker()
167167

168-
return withIncomingGoSpan(
168+
return withIncomingWorkerSpan(
169169
req.headers,
170170
TraceSpan.CopilotConfirmToolResult,
171171
{ [TraceAttr.RequestId]: tracker.requestId },

‎apps/sim/app/api/copilot/tool-permission/route.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
createRequestTracker,
3131
createUnauthorizedResponse,
3232
} from '@/lib/mothership/request/http'
33-
import { withIncomingGoSpan } from '@/lib/mothership/request/otel'
33+
import { withIncomingWorkerSpan } from '@/lib/mothership/request/otel'
3434
import { isWorkspaceCapabilityWithheld } from '@/lib/permission-groups/capability-assertions'
3535

3636
const logger = createLogger('CopilotToolPermissionAPI')
@@ -150,7 +150,7 @@ async function applyDecision(
150150
export const POST = withRouteHandler((req: NextRequest) => {
151151
const tracker = createRequestTracker()
152152

153-
return withIncomingGoSpan(
153+
return withIncomingWorkerSpan(
154154
req.headers,
155155
TraceSpan.CopilotToolPermissionDecide,
156156
{ [TraceAttr.RequestId]: tracker.requestId },

0 commit comments

Comments
 (0)