clone

an rts arena for scripts: submit tribe strategies over the web or mcp, run deterministic matches, watch them

fix: owners are never 'anon' — display names + friendly-id fallback

Dami committed d42fe89
Browse showed 'anon' for every owner because shoo pairwise identities
carry no name. Owners now fall back to their friendly user id, and the
Account card gains a display-name editor (PATCH /api/me {name}, sanitized,
40 chars; also settable via the set_sharing MCP tool). Cron/ladder sim
computes now dispatch as self-invocations via SELF_ORIGIN so each replay
gets its own CPU budget instead of sharing the scheduled() budget, and the
nightly retry batch grows to 32.
commit
d42fe89fbd18d654acea8e85a04b6428af91b61b
parent
f30c0b28fe0f2e0e48e4906207e9c3805cd963ef
author
Dami <dami.etoile@gmail.com>
10 files changed, +87 -13
Mpackages/protocol/src/api.ts6++++-
Mweb/src/api.ts2+-
Mweb/src/pages/browse.ts4++--
Mweb/src/pages/connect.ts35++++++++++++++++++++++++++++--
Mworker/src/db.ts8+++++++
Mworker/src/env.ts3+++
Mworker/src/ladder.ts4++--
Mworker/src/service.ts8++++++-
Mworker/src/sweep.ts25++++++++++++++++++++--
Mwrangler.jsonc5+++--
M packages/protocol/src/api.ts +5 -1
M web/src/api.ts +1 -1
M web/src/pages/browse.ts +2 -2
M web/src/pages/connect.ts +33 -2
M worker/src/db.ts +8 -0
M worker/src/env.ts +3 -0
M worker/src/ladder.ts +2 -2
M worker/src/service.ts +7 -1
M worker/src/sweep.ts +23 -2
@@ -138,7 +138,7 @@ export async function backfillR2(env: Env): Promise<{ sources: number; metrics:
138138 * cron retries a bounded batch each night. Metrics-GET views retry too;139139 * this catches the ones nobody looked at.140140 */141-export async function retryDeadPublicSims(env: Env, limit = 8): Promise<number> {141+export async function retryDeadPublicSims(env: Env, limit = 32): Promise<number> {142142 const rows = await env.DB143143 .prepare(144144 `SELECT id FROM sims
@@ -151,8 +151,29 @@ export async function retryDeadPublicSims(env: Env, limit = 8): Promise<number>
151151 .all<{ id: string }>();152152 let retried = 0;153153 for (const row of rows.results) {154- await computeSimMetrics(env, row.id); // internally idempotent + fault-tolerant154+ await dispatchCompute(env, row.id);155155 retried++;156156 }157157 return retried;158158 }159+160+/**161+ * Run a sim compute in its OWN invocation. A replay can eat most of a CPU162+ * budget by itself, so the cron never computes inline — it GETs the sim's163+ * metrics endpoint on our own origin, whose 404 path schedules the compute164+ * in that request's waitUntil. Inline fallback only when SELF_ORIGIN is165+ * unset (tests/local).166+ */167+export async function dispatchCompute(env: Env, simId: string): Promise<void> {168+ if (env.SELF_ORIGIN !== undefined && env.SELF_ORIGIN !== '') {169+ try {170+ await fetch(`${env.SELF_ORIGIN}/api/sims/${simId}/metrics`, {171+ headers: { accept: 'application/json' },172+ });173+ return;174+ } catch (err) {175+ console.warn('compute dispatch failed, falling back inline:', simId, err);176+ }177+ }178+ await computeSimMetrics(env, simId);179+}
M wrangler.jsonc +3 -2