The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Name the work behind prod's untagged sixth of CPU: daemon, device, share sockets and Redis deliveries (#2393)
0xken15664dd0f63702
diff --git a/backend/src/lib/adapterWs.ts b/backend/src/lib/adapterWs.tsindex 573a99abe..7e1da75ab 100644--- a/backend/src/lib/adapterWs.ts+++ b/backend/src/lib/adapterWs.ts@@ -66,6 +66,7 @@ import {terminalP2pPolicy,} from './p2pSignaling.js'import { ShortTurnGuard } from './shortTurnGuard.js'+import { markCpuKind } from './selfProfile.js'const wss = createWss(WS_LIMITS.adapter, { echoFirstProtocol: true })@@ -276,6 +277,7 @@ async function attachAdapter(ws: WebSocket, machineId: string, userId: string, cconst preHandlerQueue: Array<[RawData, boolean]> = []let onMessage: ((raw: RawData, isBinary: boolean) => void) | null = nullws.on('message', (raw: RawData, isBinary: boolean) => {+ markCpuKind(isBinary ? 'adapter-ws binary' : 'adapter-ws text')if (onMessage) onMessage(raw, isBinary)else if (preHandlerQueue.length < 64) preHandlerQueue.push([raw, isBinary])})diff --git a/backend/src/lib/agentMessagesWs.ts b/backend/src/lib/agentMessagesWs.tsindex 7348eae93..d46160caa 100644--- a/backend/src/lib/agentMessagesWs.ts+++ b/backend/src/lib/agentMessagesWs.ts@@ -18,6 +18,7 @@ import { guardedSendJson } from './wsSend.js'import { trackSocketLiveness } from './hub.js'import { createOrderedInbox } from './orderedInbox.js'import { declaredKind, trackSocket } from './wsAttribution.js'+import { markCpuKind } from './selfProfile.js'const wss = createWss(WS_LIMITS.agentMessages, { echoFirstProtocol: true })/** The daemons' one ceiling for a shared tab's frame (cli lib/e2ee/tabSession.ts `SHARED_TAB_FRAME_MAX`). */@@ -99,6 +100,7 @@ async function attach(ws: WebSocket, userId: string, share: string, machine: str// Counted as frames arrive, not as the queue reaches them: behind a slow publish, a count taken when each is handled// let a burst of up to the queue's 256 frames in before the rate saw any (review of Task 7, 2026-10-15).ws.on('message', (raw, binary) => {+ markCpuKind('agent-messages-ws')if (closed) returnif (Date.now() - windowStart >= 1000) { windowStart = Date.now(); count = 0 }const size = Array.isArray(raw) ? raw.reduce((n, b) => n + b.length, 0) : (raw as Buffer).byteLengthdiff --git a/backend/src/lib/bus.ts b/backend/src/lib/bus.tsindex 6d56b3274..014c7bbe6 100644--- a/backend/src/lib/bus.ts+++ b/backend/src/lib/bus.ts@@ -22,6 +22,7 @@ import { createCircuitBreaker } from './circuitBreaker.js'import { guardRedisCommands, isRedisFailure, wasNotSent } from './redisGuard.js'import type { Frame, UpBusMsg, DownBusMsg } from './tunnel.js'import { redisStamps, type SwarmStamps } from '../superTabs/cache.js'+import { busKind, markCpuKind } from './selfProfile.js'// A connection in subscriber mode must never fail its (re)SUBSCRIBE commands, so the sub side keeps// ioredis' "retry forever" setting.@@ -157,7 +158,7 @@ function dispatchJson(registry: JsonSubscriber, channel: string, payload: stringfunction createJsonSubscriber(conn: Redis, label: string): JsonSubscriber {const registry: JsonSubscriber = { conn, label, channelSubs: new Map(), channelSubscribePromises: new Map() }- conn.on('message', (channel: string, payload: string) => dispatchJson(registry, channel, payload))+ conn.on('message', (channel: string, payload: string) => { markCpuKind(busKind(label, channel)); dispatchJson(registry, channel, payload) })return registry}@@ -233,7 +234,11 @@ function dispatchBinary(channel: string, payload: Buffer): void {try { callback(Buffer.from(payload)) } catch (err) { logger.error('[bus] binary subscriber callback threw', err) }}}-terminalSub.on('messageBuffer', (channelRaw: Buffer, payload: Buffer) => dispatchBinary(channelRaw.toString('utf8'), payload))+terminalSub.on('messageBuffer', (channelRaw: Buffer, payload: Buffer) => {+ const channel = channelRaw.toString('utf8')+ markCpuKind(busKind('terminal', channel))+ dispatchBinary(channel, payload)+})async function addBinarySub(channel: string, callback: BinaryCb): Promise<() => void> {let callbacks = binarySubs.get(channel)diff --git a/backend/src/lib/deviceWs.ts b/backend/src/lib/deviceWs.tsindex aeb15699a..364dff304 100644--- a/backend/src/lib/deviceWs.ts+++ b/backend/src/lib/deviceWs.ts@@ -44,6 +44,7 @@ import { parseAutonomousEnvironment } from './autonomousEnvironment.js'import { AppError } from '../errors/index.js'import type { Machine } from '@prisma/client'import { isBackendOnlyDownType } from './backendOnlyFrames.js'+import { markCpuKind } from './selfProfile.js'import {VoiceQuotaExceededError,voiceQuotaService,@@ -1249,6 +1250,7 @@ function relay(device: WebSocket, opts: RelayOpts): void {},)device.on('message', (raw: RawData, isBinary: boolean) => {+ markCpuKind(isBinary ? 'device-ws binary' : 'device-ws text')if (isBinary) {if (voiceActive) {const buf = raw as Bufferdiff --git a/backend/src/lib/observerWs.ts b/backend/src/lib/observerWs.tsindex a21d9aafc..830ac28c1 100644--- a/backend/src/lib/observerWs.ts+++ b/backend/src/lib/observerWs.ts@@ -15,6 +15,7 @@ import { guardedSendJson } from './wsSend.js'import { trackSocketLiveness } from './hub.js'import { createOrderedInbox } from './orderedInbox.js'import { declaredKind, trackSocket } from './wsAttribution.js'+import { markCpuKind } from './selfProfile.js'const wss = createWss(WS_LIMITS.web, { echoFirstProtocol: true })const RECHECK_MS = 60_000@@ -122,5 +123,5 @@ export async function attachObserver(ws: WebSocket, user: AuthUser | null,await down('observer_frame', frame.payload).catch(() => ws.close(1013, 'Owner unavailable'))} else ws.close(1008, 'Observer connections are view only')}, () => ws.close(1013, 'Sharing temporarily unavailable'), () => ws.close(1008, 'Too many observer messages'))- ws.on('message', (raw, binary) => inbox.enqueue({ raw, binary }))+ ws.on('message', (raw, binary) => { markCpuKind('observer-ws'); inbox.enqueue({ raw, binary }) })}diff --git a/backend/src/lib/selfProfile.test.ts b/backend/src/lib/selfProfile.test.tsindex 51c58dbb7..96c2b0d40 100644--- a/backend/src/lib/selfProfile.test.ts+++ b/backend/src/lib/selfProfile.test.ts@@ -1,6 +1,6 @@import Fastify from 'fastify'import { afterEach, expect, it } from 'vitest'-import { frameKind, markCpuKind, selfProfileFromEnv, startSelfProfile, topCalls, topSelfTime } from './selfProfile.js'+import { busKind, frameKind, markCpuKind, selfProfileFromEnv, startSelfProfile, topCalls, topSelfTime } from './selfProfile.js'import { enterWork, workKind } from './queryStats.js'let stop = () => {}@@ -139,3 +139,13 @@ it('counts calls of our functions from precise coverage, an anonymous one by its])expect(calls).toEqual({ 'stableId dist/superTabs/model.js': 900, '(anonymous) dist/superTabs/model.js@4021': 50 })})++it('names a Redis message by its subscriber and channel kind, never the id in the channel', () => {+ expect(busKind('terminal', 'termup:6a8fe4fcf1a6b5972eed0103')).toBe('bus terminal termup')+ expect(busKind('main', 'up:machine-123')).toBe('bus main up')+ expect(busKind('app', 'appup:stream_9')).toBe('bus app appup')+ expect(busKind('main', 'swarm-stamp')).toBe('bus main swarm-stamp')+ // Anything that does not look like one of the bus's own names counts as other.+ expect(busKind('main', 'Weird Channel:1')).toBe('bus main other')+ expect(busKind('main', `${'x'.repeat(40)}:1`)).toBe('bus main other')+})diff --git a/backend/src/lib/selfProfile.ts b/backend/src/lib/selfProfile.tsindex fe27013e9..40367b582 100644--- a/backend/src/lib/selfProfile.ts+++ b/backend/src/lib/selfProfile.ts@@ -58,6 +58,14 @@ export function frameKind(prefix: string, type: unknown, known: ReadonlySet<strireturn `${prefix} ${typeof type === 'string' && known.has(type) ? type : 'other'}`}+/** A Redis message's kind: `bus <subscriber> <channel kind>`, the channel's name before its first `:` (`termup:<machine>` is+ * `termup`), never the id after it. A name that is not one of the bus's own counts as `other`. Before these were named, a+ * sixth of prod's CPU ran under `untagged` (2026-10-31): Redis deliveries, the daemons' sockets and the share sockets. */+export function busKind(subscriber: string, channel: string): string {+ const name = channel.split(':', 1)[0]!+ return `bus ${subscriber} ${/^[a-z0-9-]{1,24}$/.test(name) ? name : 'other'}`+}+/** Every HTTP request is named by its route pattern, never its URL (no ids). */export function registerCpuKinds(app: FastifyInstance): void {app.addHook('onRequest', async request => { markCpuKind(`http ${request.method} ${request.routeOptions.url ?? 'unrouted'}`) })