Multiplayer agent harness for work.
chore: log server-side send timings (#1158)
Joshua France12137db14cb8
diff --git a/plugins/web-ui/server/index.ts b/plugins/web-ui/server/index.tsindex e37e3169b..f52901b81 100644--- a/plugins/web-ui/server/index.ts+++ b/plugins/web-ui/server/index.ts@@ -658,11 +658,20 @@ function namespacedSendKey(user: string, raw: unknown): string | undefined {}async function postTurnAndMint(res: ServerResponse, turn: unknown, user: string, threadRef: string): Promise<void> {+ const startedAt = performance.now();+ let runId: string | undefined;+ res.once("finish", () => {+ console.info("[web] turn response", {+ runId,+ status: res.statusCode,+ elapsedMs: Math.round(performance.now() - startedAt),+ });+ });const r = await coreFetch("POST", `/v1/turns?async=1`, JSON.stringify(turn));if (r.status >= 200 && r.status < 300) {try {const parsed = JSON.parse(r.text) as Record<string, unknown> & { runId?: string };- const runId = parsed.runId;+ runId = parsed.runId;if (runId) {rememberRun(runId, user, threadRef);return json(res, r.status, parsed);diff --git a/src/api/app-turn.ts b/src/api/app-turn.tsindex 829fbf8d4..9eab03e57 100644--- a/src/api/app-turn.ts+++ b/src/api/app-turn.ts@@ -76,6 +76,7 @@ export function createTurnMethods(const { shouldRouteToSpine, markTriggerHandled, addressedWakeText } = ambient;return {async turn(req: TurnRequest): Promise<TurnResult> {+ const startedAt = performance.now();await deps.refreshModels?.();await deps.identity.refresh();const actor: Principal = deps.identity.resolve(req.actor);@@ -487,9 +488,15 @@ export function createTurnMethods(maxAttempts: deps.maxAttempts,...(dedupKey ? { dedupKey } : {}),});+ const enqueueStartedAt = performance.now();const enqueued = await withCurrentProjectRoster(enqueue);if (!enqueued) return { status: "refused", reason: "project membership changed; retry from the current project" };const { run, deduped } = enqueued;+ console.info("[turn] queued", {+ runId: run.id,+ preEnqueueMs: Math.round(enqueueStartedAt - startedAt),+ enqueueMs: Math.round(performance.now() - enqueueStartedAt),+ });if (deduped && redeliveryKey && run.dedupKey === redeliveryKey) return { status: "silent" };if (!deduped) {deps.sessionStateBus?.emit({