Public: anyone can read this; the crew can change it.
The job watch and child-time minutes belong to a forge, not the process, so one test file's jobs never show in another's #12619
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12614-the-job-watch-and-child-time-minutes-bel → main 9 commits fork 1 thread · 1 unresolved
44 files
changed +300
−145
src/actions/ask_host.ts +1 −1
| @@ -379,7 +379,7 @@ export function watch(app: App): void { | ||
| 379 | 379 | refreshAsks(app).finally(() => { |
| 380 | 380 | watching.delete(app); |
| 381 | 381 | watch(app); |
| 382 | }), | |
| 382 | }), undefined, app, | |
| 383 | 383 | ), |
| 384 | 384 | LOOK_MS, |
| 385 | 385 | ); |
src/apps/feature_schedule.ts +1 −1
| @@ -198,7 +198,7 @@ export function startFeatureSchedule(app: App, tickMs: number = TICK_MS): { stop | ||
| 198 | 198 | const tick = setInterval(() => { |
| 199 | 199 | if (running) return; |
| 200 | 200 | running = true; |
| 201 | void during("feature-schedule", () => fireDue(app)).finally(() => (running = false)); | |
| 201 | void during("feature-schedule", () => fireDue(app), undefined, app).finally(() => (running = false)); | |
| 202 | 202 | }, tickMs); |
| 203 | 203 | tick.unref(); |
| 204 | 204 | return { stop: () => clearInterval(tick) }; |
src/apps/pull_schedule.ts +1 −1
| @@ -247,7 +247,7 @@ export function startPullSchedule(app: App, tickMs: number = TICK_MS): { stop(): | ||
| 247 | 247 | const tick = setInterval(() => { |
| 248 | 248 | if (running) return; |
| 249 | 249 | running = true; |
| 250 | void during("pull-schedule", () => pullDue(app)).finally(() => (running = false)); | |
| 250 | void during("pull-schedule", () => pullDue(app), undefined, app).finally(() => (running = false)); | |
| 251 | 251 | }, tickMs); |
| 252 | 252 | tick.unref(); |
| 253 | 253 | return { stop: () => clearInterval(tick) }; |
src/apps/runtime.ts +2 −2
| @@ -804,7 +804,7 @@ export class AppsRuntime { | ||
| 804 | 804 | this.pruneDirs(known); |
| 805 | 805 | await this.sampleStorage(); |
| 806 | 806 | this.sweeper = setInterval( |
| 807 | () => void during("apps-sweep", () => this.sweep(), this.options.owner), | |
| 807 | () => void during("apps-sweep", () => this.sweep(), this.options.owner, this.app), | |
| 808 | 808 | this.options.sweepEveryMs ?? SWEEP_EVERY_MS, |
| 809 | 809 | ); |
| 810 | 810 | } |
| @@ -1840,7 +1840,7 @@ export class AppsRuntime { | ||
| 1840 | 1840 | live.commitOid, |
| 1841 | 1841 | oom ? "oom" : "restart", |
| 1842 | 1842 | ); |
| 1843 | }, this.options.owner), | |
| 1843 | }, this.options.owner, this.app), | |
| 1844 | 1844 | delay, |
| 1845 | 1845 | ); |
| 1846 | 1846 | }) |
src/apps/timer_service.ts +1 −1
| @@ -78,7 +78,7 @@ export function startTimers(app: App, tickMs = 1000): { stop(): void } | undefin | ||
| 78 | 78 | firing = false; |
| 79 | 79 | } |
| 80 | 80 | }; |
| 81 | const tick = setInterval(() => void during("timers", cycle).catch((e) => app.log.warn("timers: could not fire", { error: String(e) })), tickMs); | |
| 81 | const tick = setInterval(() => void during("timers", cycle, undefined, app).catch((e) => app.log.warn("timers: could not fire", { error: String(e) })), tickMs); | |
| 82 | 82 | tick.unref(); |
| 83 | 83 | return { stop: () => clearInterval(tick) }; |
| 84 | 84 | } |
src/apps/tty_registry.ts +1 −1
| @@ -80,7 +80,7 @@ export function openAppTty(app: App, open: OpenAppTty): AppTtyHandle { | ||
| 80 | 80 | () => |
| 81 | 81 | during("app-tty-idle", () => { |
| 82 | 82 | if (idleFor(entry, open.idleMs())) stop(app, entry); |
| 83 | }), | |
| 83 | }, undefined, app), | |
| 84 | 84 | Math.max(10, Math.min(open.idleMs(), open.checkMs ?? CHECK_MS)), |
| 85 | 85 | ), |
| 86 | 86 | }; |
src/boards/memory.ts +2 −2
| @@ -73,8 +73,8 @@ export function startMemorySampler(app: App, everyMs = MEMORY_EVERY_MS): MemoryS | ||
| 73 | 73 | app.log.warn("memory sample failed", { error: String(error) }); |
| 74 | 74 | } |
| 75 | 75 | }; |
| 76 | during("memory-sampler", () => tick()); | |
| 77 | const timer = setInterval(() => during("memory-sampler", () => tick()), everyMs); | |
| 76 | during("memory-sampler", () => tick(), undefined, app); | |
| 77 | const timer = setInterval(() => during("memory-sampler", () => tick(), undefined, app), everyMs); | |
| 78 | 78 | timer.unref?.(); |
| 79 | 79 | return { tick, stop: () => clearInterval(timer) }; |
| 80 | 80 | } |
src/boards/sampler.ts +2 −2
| @@ -170,8 +170,8 @@ export function startSampler( | ||
| 170 | 170 | app.log.warn("machine sample failed", { error: String(error) }); |
| 171 | 171 | } |
| 172 | 172 | }; |
| 173 | during("sampler", tick); | |
| 174 | const timer = setInterval(() => during("sampler", tick), options.everyMs ?? FINE_MS); | |
| 173 | during("sampler", tick, undefined, app); | |
| 174 | const timer = setInterval(() => during("sampler", tick, undefined, app), options.everyMs ?? FINE_MS); | |
| 175 | 175 | timer.unref?.(); |
| 176 | 176 | return { |
| 177 | 177 | tick, |
src/checks/service.ts +4 −4
| @@ -1989,7 +1989,7 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle { | ||
| 1989 | 1989 | // (`perf/child_time.ts`). |
| 1990 | 1990 | const owner = options.label === undefined ? undefined : childLabel(options.label); |
| 1991 | 1991 | const timer = setInterval(() => { |
| 1992 | if (!stopped) during("lane", schedule, owner); | |
| 1992 | if (!stopped) during("lane", schedule, owner, app); | |
| 1993 | 1993 | }, options.tickMs ?? TICK_MS); |
| 1994 | 1994 | // Main is verified after landing on a schedule, when the forge says how often. |
| 1995 | 1995 | const sweeper = |
| @@ -1997,14 +1997,14 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle { | ||
| 1997 | 1997 | ? undefined |
| 1998 | 1998 | : setInterval(() => { |
| 1999 | 1999 | if (!stopped) |
| 2000 | during("verify-sweep", askVerifications, owner).catch((error) => | |
| 2000 | during("verify-sweep", askVerifications, owner, app).catch((error) => | |
| 2001 | 2001 | log.error("verification not asked", { error: String(error) }), |
| 2002 | 2002 | ); |
| 2003 | 2003 | }, Math.min(VERIFY_SWEEP_MS, options.verifyEveryMs)); |
| 2004 | 2004 | // A gate's slot frees: the pull check held for it starts now, not at the tick. |
| 2005 | 2005 | const unwatch = watchGates(schedule); |
| 2006 | during("lane", schedule, owner); | |
| 2007 | void during("lane-catch-up", catchUp, owner); | |
| 2006 | during("lane", schedule, owner, app); | |
| 2007 | void during("lane-catch-up", catchUp, owner, app); | |
| 2008 | 2008 | |
| 2009 | 2009 | /** One gate's run on the lane: the full tier on `commitOid`, traced, cut off by `controller`. */ |
| 2010 | 2010 | async function gateOnce( |
src/contract/probes.ts +2 −2
| @@ -238,7 +238,7 @@ export function startProbes( | ||
| 238 | 238 | if (!record) return; |
| 239 | 239 | const timer = setTimeout(() => { |
| 240 | 240 | timers.delete(timer); |
| 241 | if (!stopped) void during("probes", () => one(record)); | |
| 241 | if (!stopped) void during("probes", () => one(record), undefined, app); | |
| 242 | 242 | }, AFTER_DEPLOY_MS); |
| 243 | 243 | timers.add(timer); |
| 244 | 244 | }); |
| @@ -247,7 +247,7 @@ export function startProbes( | ||
| 247 | 247 | const scheduleNightly = (): void => { |
| 248 | 248 | if (options.nightly === false) return; |
| 249 | 249 | nightly = setTimeout(() => { |
| 250 | void track(during("probes", round)).finally(scheduleNightly); | |
| 250 | void track(during("probes", round, undefined, app)).finally(scheduleNightly); | |
| 251 | 251 | }, untilNightly()); |
| 252 | 252 | }; |
| 253 | 253 | scheduleNightly(); |
src/crew/dispatch.ts +4 −4
| @@ -304,7 +304,7 @@ export async function startCrew( | ||
| 304 | 304 | )); |
| 305 | 305 | } |
| 306 | 306 | pump(app, ready, inFlight); |
| 307 | }); | |
| 307 | }, undefined, app); | |
| 308 | 308 | } catch (error) { |
| 309 | 309 | log.error("crew tick failed", { error: String(error) }); |
| 310 | 310 | } |
| @@ -319,13 +319,13 @@ export async function startCrew( | ||
| 319 | 319 | const pruned = pruneRunFiles(app.config.dataDir); |
| 320 | 320 | if (pruned > 0) log.info("removed old run logs", { count: pruned }); |
| 321 | 321 | }; |
| 322 | during("clone-sweep", sweepClones); | |
| 323 | const cloneTimer = setInterval(() => !stopped && during("clone-sweep", sweepClones), 60 * 60_000); | |
| 322 | during("clone-sweep", sweepClones, undefined, app); | |
| 323 | const cloneTimer = setInterval(() => !stopped && during("clone-sweep", sweepClones, undefined, app), 60 * 60_000); | |
| 324 | 324 | during("crew", () => { |
| 325 | 325 | requeueInterrupted(app); |
| 326 | 326 | sweepAssigned(app); |
| 327 | 327 | pump(app, ready, inFlight); |
| 328 | }); | |
| 328 | }, undefined, app); | |
| 329 | 329 | |
| 330 | 330 | const handle: CrewHandle = { |
| 331 | 331 | ready: detected.ok, |
src/crew/notify.ts +2 −2
| @@ -596,7 +596,7 @@ export function startNotifier(app: App, options: NotifyOptions): Notifier { | ||
| 596 | 596 | } catch (error) { |
| 597 | 597 | app.log.error("notify failed", { error: String(error) }); |
| 598 | 598 | } |
| 599 | })); | |
| 599 | }, undefined, app)); | |
| 600 | 600 | }, options.clockMs ?? CLOCK_MS); |
| 601 | 601 | clock.unref(); |
| 602 | 602 | |
| @@ -613,7 +613,7 @@ export function startNotifier(app: App, options: NotifyOptions): Notifier { | ||
| 613 | 613 | return queue; |
| 614 | 614 | }; |
| 615 | 615 | const pager = setInterval( |
| 616 | () => void during("notify-page", pageAll), | |
| 616 | () => void during("notify-page", pageAll, undefined, app), | |
| 617 | 617 | Math.min(options.clockMs ?? CLOCK_MS, PAGE_MS), |
| 618 | 618 | ); |
| 619 | 619 | pager.unref(); |
src/crew/prompts.ts +1 −1
| @@ -102,7 +102,7 @@ export function startPromptRoutine( | ||
| 102 | 102 | |
| 103 | 103 | const timer = setInterval(() => { |
| 104 | 104 | if (stopped) return; |
| 105 | during("prompts", runDue).catch((error) => | |
| 105 | during("prompts", runDue, undefined, app).catch((error) => | |
| 106 | 106 | log.error("prompt sweep failed", { error: String(error) }), |
| 107 | 107 | ); |
| 108 | 108 | }, options.everyMs ?? TICK_MS); |
src/crew/routines.ts +1 −1
| @@ -79,7 +79,7 @@ export function startRoutines(app: App, signal: AbortSignal): () => void { | ||
| 79 | 79 | const loop = (wait: number): void => { |
| 80 | 80 | timer = setTimeout(() => { |
| 81 | 81 | if (signal.aborted) return; |
| 82 | void during("routines", () => runDue(app, new Date())).finally(() => loop(60_000)); | |
| 82 | void during("routines", () => runDue(app, new Date()), undefined, app).finally(() => loop(60_000)); | |
| 83 | 83 | }, wait); |
| 84 | 84 | timer.unref(); |
| 85 | 85 | }; |
src/engine/duties.ts +11 −11
| @@ -52,19 +52,19 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 52 | 52 | pruneSessions(app.db); |
| 53 | 53 | pruneTokens(app.db); |
| 54 | 54 | }; |
| 55 | timers.push(setInterval(() => during("delivery", delivery), 5_000)); | |
| 55 | timers.push(setInterval(() => during("delivery", delivery, undefined, app), 5_000)); | |
| 56 | 56 | // Sweep anything queued while we were down. |
| 57 | during("delivery", delivery); | |
| 57 | during("delivery", delivery, undefined, app); | |
| 58 | 58 | // Estimates of "done" come due as time passes (#11955). |
| 59 | timers.push(setInterval(() => during("estimates-due", () => void settleDue(app.db)), 300_000)); | |
| 59 | timers.push(setInterval(() => during("estimates-due", () => void settleDue(app.db), undefined, app), 300_000)); | |
| 60 | 60 | // Accounts an agent started and nobody claimed sleep after a week and are |
| 61 | 61 | // archived after a month (`actions/start_sweep.ts`, #10912): hourly, and on boot. |
| 62 | timers.push(setInterval(() => during("starts", () => void sweepStarts(app)), HOUR_MS)); | |
| 63 | during("starts", () => void sweepStarts(app)); | |
| 62 | timers.push(setInterval(() => during("starts", () => void sweepStarts(app), undefined, app), HOUR_MS)); | |
| 63 | during("starts", () => void sweepStarts(app), undefined, app); | |
| 64 | 64 | // A token a brokered sign-in sealed is swept by a timer a minute later |
| 65 | 65 | // (`spawn/origin_broker.ts`), and a timer dies with its process: what a restart left past its |
| 66 | 66 | // minute goes here, on boot. |
| 67 | during("origin-broker-sweep", () => pruneBroker(app)); | |
| 67 | during("origin-broker-sweep", () => pruneBroker(app), undefined, app); | |
| 68 | 68 | // An agent's hold that has stood 24 h is released each minute (#6918). |
| 69 | 69 | timers.push( |
| 70 | 70 | setInterval( |
| @@ -75,7 +75,7 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 75 | 75 | } catch (error) { |
| 76 | 76 | app.log.warn("hold expiry failed", { error: String(error) }); |
| 77 | 77 | } |
| 78 | }), | |
| 78 | }, undefined, app), | |
| 79 | 79 | 60_000, |
| 80 | 80 | ), |
| 81 | 81 | ); |
| @@ -89,7 +89,7 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 89 | 89 | } catch (error) { |
| 90 | 90 | app.log.warn("model review failed", { error: String(error) }); |
| 91 | 91 | } |
| 92 | }), | |
| 92 | }, undefined, app), | |
| 93 | 93 | HOUR_MS, |
| 94 | 94 | ), |
| 95 | 95 | ); |
| @@ -105,7 +105,7 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 105 | 105 | } catch (error) { |
| 106 | 106 | app.log.warn("week retrospective failed", { error: String(error) }); |
| 107 | 107 | } |
| 108 | }), | |
| 108 | }, undefined, app), | |
| 109 | 109 | HOUR_MS, |
| 110 | 110 | ), |
| 111 | 111 | ); |
| @@ -116,7 +116,7 @@ export function startDuties(app: App, options: { onWorker: boolean }): () => voi | ||
| 116 | 116 | stops.push(startReaders(app, () => void adoptObserved(app.db))); |
| 117 | 117 | // The one checkpointer: the serving thread's commits never pay for it (`main.ts`). A passive one |
| 118 | 118 | // takes what no reader still needs and waits for none; a log nobody reads is reset by the next write. |
| 119 | timers.push(setInterval(() => during("checkpoint", () => app.db.exec("PRAGMA wal_checkpoint(PASSIVE)")), 2_000)); | |
| 119 | timers.push(setInterval(() => during("checkpoint", () => app.db.exec("PRAGMA wal_checkpoint(PASSIVE)"), undefined, app), 2_000)); | |
| 120 | 120 | } |
| 121 | 121 | return () => { |
| 122 | 122 | for (const timer of timers) clearInterval(timer); |
| @@ -151,7 +151,7 @@ function startReaders(app: App, adopt: () => void): () => void { | ||
| 151 | 151 | } catch (error) { |
| 152 | 152 | app.log.warn("database size reading failed", { error: String(error) }); |
| 153 | 153 | } |
| 154 | }), | |
| 154 | }, undefined, app), | |
| 155 | 155 | 120_000, |
| 156 | 156 | ); |
| 157 | 157 | return () => { |
src/engine/host.ts +4 −2
| @@ -69,6 +69,8 @@ export function startEngine( | ||
| 69 | 69 | stallMs?: number; |
| 70 | 70 | giveUpDeaths?: number; |
| 71 | 71 | onGiveUp?: (what: string) => void; |
| 72 | /** The forge this engine serves: its restart and watch count on that forge's job watch. */ | |
| 73 | forge?: object; | |
| 72 | 74 | } = {}, |
| 73 | 75 | ): Engine { |
| 74 | 76 | let worker: Worker | undefined; |
| @@ -155,7 +157,7 @@ export function startEngine( | ||
| 155 | 157 | during("engine-restart", () => { |
| 156 | 158 | restarts++; |
| 157 | 159 | launch(); |
| 158 | }), | |
| 160 | }, undefined, options.forge), | |
| 159 | 161 | wait, |
| 160 | 162 | ); |
| 161 | 163 | }; |
| @@ -167,7 +169,7 @@ export function startEngine( | ||
| 167 | 169 | clearInterval(watch); |
| 168 | 170 | w.terminate(); |
| 169 | 171 | died("silent"); |
| 170 | }); | |
| 172 | }, undefined, options.forge); | |
| 171 | 173 | }, BEAT_MS); |
| 172 | 174 | watch.unref(); |
| 173 | 175 | w.onerror = (event: ErrorEvent) => died(String(event.message ?? event)); |
src/engine/run.ts +2 −2
| @@ -71,7 +71,7 @@ export function runSplit( | ||
| 71 | 71 | }; |
| 72 | 72 | const engine = optional<Engine | undefined>( |
| 73 | 73 | "the engine's Worker", |
| 74 | () => startEngine(app.config, tail, { ...options, onGiveUp: givenUp }), | |
| 74 | () => startEngine(app.config, tail, { ...options, onGiveUp: givenUp, forge: app }), | |
| 75 | 75 | (error) => { |
| 76 | 76 | givenUp(`could not be started (${String(error).slice(0, 200)})`); |
| 77 | 77 | return undefined; |
| @@ -82,7 +82,7 @@ export function runSplit( | ||
| 82 | 82 | // watch and asks ledger to read. |
| 83 | 83 | if (fell === undefined) |
| 84 | 84 | observed = setInterval( |
| 85 | () => during("observed-publish", () => void publishObserved(app.db)), | |
| 85 | () => during("observed-publish", () => void publishObserved(app.db), undefined, app), | |
| 86 | 86 | 2_000, |
| 87 | 87 | ); |
| 88 | 88 | return { |
src/engine/worker.ts +1 −1
| @@ -64,7 +64,7 @@ async function boot(init: EngineInit): Promise<void> { | ||
| 64 | 64 | app.close(); |
| 65 | 65 | }; |
| 66 | 66 | // Alive: a thread stuck in one statement stops saying so, and the serving thread ends it (`host.ts`). |
| 67 | const beat = setInterval(() => during("engine-beat", () => postMessage("h")), BEAT_MS); | |
| 67 | const beat = setInterval(() => during("engine-beat", () => postMessage("h"), undefined, app), BEAT_MS); | |
| 68 | 68 | const was = stop; |
| 69 | 69 | stop = () => { |
| 70 | 70 | clearInterval(beat); |
src/flow/keeper.ts +1 −1
| @@ -188,7 +188,7 @@ export function startKeeper(app: App, onLift: () => void, everyMs = 60_000, now: | ||
| 188 | 188 | during("keeper", () => { |
| 189 | 189 | prepare(); |
| 190 | 190 | tickKeeper(app, new Date(now()), onLift); |
| 191 | }); | |
| 191 | }, undefined, app); | |
| 192 | 192 | } catch (error) { |
| 193 | 193 | log.warn("keeper tick failed", { error: String(error) }); |
| 194 | 194 | } |
src/http/server.ts +2 −2
| @@ -2643,7 +2643,7 @@ export async function serve(app: App): Promise<Servers> { | ||
| 2643 | 2643 | during("standing-sweep", () => |
| 2644 | 2644 | sweepStanding(app.db, (error) => |
| 2645 | 2645 | app.log.warn("standing sweep did not finish", { error: String(error) }), |
| 2646 | ), | |
| 2646 | ), undefined, app, | |
| 2647 | 2647 | ), |
| 2648 | 2648 | app.config.standingSweepMs ?? 5_000, |
| 2649 | 2649 | ); |
| @@ -2727,7 +2727,7 @@ export async function serve(app: App): Promise<Servers> { | ||
| 2727 | 2727 | }, |
| 2728 | 2728 | ); |
| 2729 | 2729 | liveOf(app).loopWatch.finished(hostedChild === undefined ? tag.pattern : childLabel(hostedChild), started, end); |
| 2730 | if (hostedChild !== undefined) noteChildRequest(hostedChild, ms); | |
| 2730 | if (hostedChild !== undefined) noteChildRequest(app, hostedChild, ms); | |
| 2731 | 2731 | // Evidence of what was read, and the running capture, if any (never a signed-in person's). |
| 2732 | 2732 | const signedIn = tag.role !== "anon" && tag.role !== "crawler"; |
| 2733 | 2733 | const cls = classOf({ signedIn, crawler: wasCrawler(request), deepStranger: wasDeepStranger(request), internal: wasInternal(request) }); |
src/looks/service.ts +2 −2
| @@ -329,8 +329,8 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 329 | 329 | // Production missing a picture at its head — one never taken, or a |
| 330 | 330 | // thumb from before thumbs were the page — gets one while it is up. |
| 331 | 331 | // A woken app says nothing on the bus, so this is how it is pictured. |
| 332 | const firstSweep = setTimeout(() => during("looks", sweep), FIRST_SWEEP_MS); | |
| 333 | const sweeping = setInterval(() => during("looks", sweep), SWEEP_MS); | |
| 332 | const firstSweep = setTimeout(() => during("looks", sweep, undefined, app), FIRST_SWEEP_MS); | |
| 333 | const sweeping = setInterval(() => during("looks", sweep, undefined, app), SWEEP_MS); | |
| 334 | 334 | firstSweep.unref?.(); |
| 335 | 335 | sweeping.unref?.(); |
| 336 | 336 |
src/main.ts +26 −26
| @@ -415,7 +415,7 @@ if (byHand !== undefined) { | ||
| 415 | 415 | settleLiveNow(app.db); |
| 416 | 416 | } |
| 417 | 417 | const flagTimer = setInterval( |
| 418 | () => during("flag-uses", () => flushFlagUses(app.db)), | |
| 418 | () => during("flag-uses", () => flushFlagUses(app.db), undefined, app), | |
| 419 | 419 | 10_000, |
| 420 | 420 | ); |
| 421 | 421 | await reconcile(app); |
| @@ -738,13 +738,13 @@ function positive(value: string | undefined, fallback: number): number { | ||
| 738 | 738 | // the sweep. The operator guard's sweep of stored origins rides it too: one |
| 739 | 739 | // origin a tick, the never-checked first (so on boot), every other daily. |
| 740 | 740 | const syncTimer = setInterval(() => { |
| 741 | during("sync", () => runSync(app)); | |
| 742 | void during("ahead", () => runAheadReads(app)); | |
| 743 | void during("guard-sweep", () => runGuardSweep(app)); | |
| 741 | during("sync", () => runSync(app), undefined, app); | |
| 742 | void during("ahead", () => runAheadReads(app), undefined, app); | |
| 743 | void during("guard-sweep", () => runGuardSweep(app), undefined, app); | |
| 744 | 744 | }, 60_000); |
| 745 | 745 | // One pass on boot: a forge that was down has fetching to do. |
| 746 | during("sync", () => runSync(app)); | |
| 747 | void during("guard-sweep", () => runGuardSweep(app)); | |
| 746 | during("sync", () => runSync(app), undefined, app); | |
| 747 | void during("guard-sweep", () => runGuardSweep(app), undefined, app); | |
| 748 | 748 | |
| 749 | 749 | // Which green pulls no longer merge as they stand, so the asks can leave |
| 750 | 750 | // them out (`crew/stale_asks.ts`): git answers, off the request path, and an |
| @@ -811,28 +811,28 @@ const followTimer = setInterval( | ||
| 811 | 811 | await checkDue(app); |
| 812 | 812 | // The apps a spawn sent down: offered, taken and kept current (`spawn/app_follow.ts`). |
| 813 | 813 | await followTick(app); |
| 814 | }), | |
| 814 | }, undefined, app), | |
| 815 | 815 | 60_000, |
| 816 | 816 | ); |
| 817 | 817 | // An app landing on this forge is told to the children awake here that follow it at once. |
| 818 | 818 | const landingsWatch = watchLandings(app); |
| 819 | 819 | // A child born before its apps were linked is offered the link, and a child offered one takes it: at boot, then every tick. |
| 820 | 820 | void followTick(app, true).catch((error) => app.log.error("could not link the apps", { error: String(error) })); |
| 821 | const staleTimer = setInterval(() => void during("asks", tickAsks), 120_000); | |
| 821 | const staleTimer = setInterval(() => void during("asks", tickAsks, undefined, app), 120_000); | |
| 822 | 822 | // A desk note whose time is up goes off the home line at once, over the stream. |
| 823 | const deskTimer = setInterval(() => void during("desk", () => sweepDesk(app)), 30_000); | |
| 823 | const deskTimer = setInterval(() => void during("desk", () => sweepDesk(app), undefined, app), 30_000); | |
| 824 | 824 | // Every paid entitlement is re-read from Stripe once a day, so a missed webhook heals (#11247). |
| 825 | const entitlementTimer = setInterval(() => void during("entitlements", () => sweepEntitlements(app)), 86_400_000); | |
| 826 | void during("entitlements", () => sweepEntitlements(app)); | |
| 825 | const entitlementTimer = setInterval(() => void during("entitlements", () => sweepEntitlements(app), undefined, app), 86_400_000); | |
| 826 | void during("entitlements", () => sweepEntitlements(app), undefined, app); | |
| 827 | 827 | // The cost ledger's chain is walked at boot and once a day (#12273), on this thread: |
| 828 | 828 | // health reads the verdict from this thread's memory. |
| 829 | 829 | const walkLedger = (): void => |
| 830 | 830 | void checkLedger(join(dataDir, "ledger"), (line) => app.log.info(line)); |
| 831 | 831 | const ledgerTimer = readOnly |
| 832 | 832 | ? undefined |
| 833 | : setInterval(() => during("ledger", walkLedger), 86_400_000); | |
| 834 | if (!readOnly) during("ledger", walkLedger); | |
| 835 | void during("asks", tickAsks); | |
| 833 | : setInterval(() => during("ledger", walkLedger, undefined, app), 86_400_000); | |
| 834 | if (!readOnly) during("ledger", walkLedger, undefined, app); | |
| 835 | void during("asks", tickAsks, undefined, app); | |
| 836 | 836 | |
| 837 | 837 | // Every start is counted, and one that follows a process that never said |
| 838 | 838 | // goodbye is a crash the log could not record (kernel/boots.ts, #3708). |
| @@ -880,18 +880,18 @@ const nightlyScanTimer = setInterval(() => { | ||
| 880 | 880 | const repo = getRepoById(app.db, id); |
| 881 | 881 | if (repo !== undefined) await scanNightly(app, repo); |
| 882 | 882 | } |
| 883 | }).catch((error) => app.log.warn("nightly scan failed", { error: String(error) })); | |
| 883 | }, undefined, app).catch((error) => app.log.warn("nightly scan failed", { error: String(error) })); | |
| 884 | 884 | }, 3_600_000); |
| 885 | 885 | // The cost ledger's chain goes to the `ledger` branch in signed batches: once an hour, and only |
| 886 | 886 | // when there is something new (core/ledger_git.ts). |
| 887 | 887 | const ledgerGitTimer = readOnly |
| 888 | 888 | ? undefined |
| 889 | 889 | : setInterval( |
| 890 | () => void during("ledger-git", () => ledgerGitTick(app, join(dataDir, "ledger"))).catch((error) => app.log.warn("ledger batch failed", { error: String(error) })), | |
| 890 | () => void during("ledger-git", () => ledgerGitTick(app, join(dataDir, "ledger")), undefined, app).catch((error) => app.log.warn("ledger batch failed", { error: String(error) })), | |
| 891 | 891 | BATCH_EVERY_MS, |
| 892 | 892 | ); |
| 893 | const processTimer = setInterval(() => during("processes", processTick), 60_000); | |
| 894 | during("processes", processTick); | |
| 893 | const processTimer = setInterval(() => during("processes", processTick, undefined, app), 60_000); | |
| 894 | during("processes", processTick, undefined, app); | |
| 895 | 895 | // A new version proves itself against the public URL; a failed one again, 5 min after and backing off to hourly (release/prove.ts). |
| 896 | 896 | proveRunning({ |
| 897 | 897 | dataDir: app.config.dataDir, |
| @@ -926,14 +926,14 @@ if (app.config.forgeRepo) { | ||
| 926 | 926 | read: ownTagsReader(app, app.config.forgeRepo), |
| 927 | 927 | }); |
| 928 | 928 | setBehind(watch); |
| 929 | void during("release-behind", () => watch.tick()); | |
| 929 | void during("release-behind", () => watch.tick(), undefined, app); | |
| 930 | 930 | setInterval( |
| 931 | () => void during("release-behind", () => watch.tick()), | |
| 931 | () => void during("release-behind", () => watch.tick(), undefined, app), | |
| 932 | 932 | CHECK_EVERY_MS, |
| 933 | 933 | ); |
| 934 | 934 | // The no-release alarm reads what this keeps of the running commit (#7638). |
| 935 | void during("landings", () => readLandings(app)); | |
| 936 | setInterval(() => void during("landings", () => readLandings(app)), 60_000); | |
| 935 | void during("landings", () => readLandings(app), undefined, app); | |
| 936 | setInterval(() => void during("landings", () => readLandings(app), undefined, app), 60_000); | |
| 937 | 937 | } |
| 938 | 938 | // The release keeper (#7557): cut on cadence, promote, verify under page load, roll back to the named |
| 939 | 939 | // known-good image and hold. Off unless FORGE_RELEASE_KEEPER=on in a cluster (keeper/wire.ts). |
| @@ -956,10 +956,10 @@ if (keeperOn.on) { | ||
| 956 | 956 | said = line; |
| 957 | 957 | }) |
| 958 | 958 | .catch((error) => app.log.warn("release keeper step failed", { error: String(error) })); |
| 959 | during("release-keeper", step); | |
| 960 | setInterval(() => during("release-keeper", step), 60_000); | |
| 959 | during("release-keeper", step, undefined, app); | |
| 960 | setInterval(() => during("release-keeper", step, undefined, app), 60_000); | |
| 961 | 961 | setInterval( |
| 962 | () => void during("roll-probe", () => rollProbe(ports)).catch(() => {}), | |
| 962 | () => void during("roll-probe", () => rollProbe(ports), undefined, app).catch(() => {}), | |
| 963 | 963 | 1000, |
| 964 | 964 | ); |
| 965 | 965 | } |
| @@ -1011,7 +1011,7 @@ const leaseTimer = setInterval(() => during("lease", () => { | ||
| 1011 | 1011 | requeueAbandonedChecks(app, STALE_AFTER_MS); |
| 1012 | 1012 | // A grant whose run is no longer running is a crash's leftover: close it. |
| 1013 | 1013 | releaseOrphans(app.db); |
| 1014 | }), 30_000); | |
| 1014 | }, undefined, app), 30_000); | |
| 1015 | 1015 | |
| 1016 | 1016 | // A release that read healthy beside this process takes over (#1663), |
| 1017 | 1017 | // and this one lets go of the port before it drains (#2040). |
src/maintain/runner.ts +2 −2
| @@ -89,8 +89,8 @@ export function startMaintain(app: App, options: { duties?: readonly Duty[]; eve | ||
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | const first = setTimeout(() => void during("maintain", () => tick()), FIRST_MS); | |
| 93 | const every = setInterval(() => void during("maintain", () => tick()), options.everyMs ?? TICK_MS); | |
| 92 | const first = setTimeout(() => void during("maintain", () => tick(), undefined, app), FIRST_MS); | |
| 93 | const every = setInterval(() => void during("maintain", () => tick(), undefined, app), options.everyMs ?? TICK_MS); | |
| 94 | 94 | first.unref?.(); |
| 95 | 95 | every.unref?.(); |
| 96 | 96 | return { |
src/nightly/service.ts +2 −2
| @@ -133,7 +133,7 @@ export function startNightly( | ||
| 133 | 133 | const waitRadar = (): void => { |
| 134 | 134 | const timer = setTimeout(() => { |
| 135 | 135 | timers.delete(timer); |
| 136 | void during("nightly", runRadarNight).finally(() => !abort.signal.aborted && waitRadar()); | |
| 136 | void during("nightly", runRadarNight, undefined, app).finally(() => !abort.signal.aborted && waitRadar()); | |
| 137 | 137 | }, untilNext(RADAR_SLOT, now()) + 1_000); |
| 138 | 138 | timers.add(timer); |
| 139 | 139 | }; |
| @@ -143,7 +143,7 @@ export function startNightly( | ||
| 143 | 143 | const wait = (job: Job): void => { |
| 144 | 144 | const timer = setTimeout(() => { |
| 145 | 145 | timers.delete(timer); |
| 146 | void during("nightly", () => run(job.name)).finally(() => !abort.signal.aborted && wait(job)); | |
| 146 | void during("nightly", () => run(job.name), undefined, app).finally(() => !abort.signal.aborted && wait(job)); | |
| 147 | 147 | // A second past the slot: a timer that fires early would read yesterday's. |
| 148 | 148 | }, untilNext(job.slot, now()) + 1_000); |
| 149 | 149 | timers.add(timer); |
src/origins/mirror-pulls.ts +2 −2
| @@ -336,7 +336,7 @@ export function startMirrorPulls(app: App): () => void { | ||
| 336 | 336 | busy = false; |
| 337 | 337 | }); |
| 338 | 338 | }; |
| 339 | const timer = setInterval(() => during("mirror-pulls", tick), MIRROR_PULLS_EVERY_MS); | |
| 340 | during("mirror-pulls", tick); | |
| 339 | const timer = setInterval(() => during("mirror-pulls", tick, undefined, app), MIRROR_PULLS_EVERY_MS); | |
| 340 | during("mirror-pulls", tick, undefined, app); | |
| 341 | 341 | return () => clearInterval(timer); |
| 342 | 342 | } |
src/perf/child_time.ts +32 −9
| @@ -30,10 +30,31 @@ interface Minute { | ||
| 30 | 30 | jobMs: number; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | /** By child name, then by minute: at most sixty small rows a child. */ | |
| 34 | const minutes = new Map<string, Map<number, Minute>>(); | |
| 33 | type Minutes = Map<string, Map<number, Minute>>; | |
| 35 | 34 | |
| 36 | function minuteOf(name: string, at: number): Minute { | |
| 35 | /** | |
| 36 | * By hosting forge, then child name, then minute: at most sixty small rows a | |
| 37 | * child. Held per forge, as `askingOf` holds its reading (#12614): one map for | |
| 38 | * the process showed one test file's children on every later file's forge. | |
| 39 | */ | |
| 40 | const byHost = new WeakMap<object, Minutes>(); | |
| 41 | function minutesOf(host: object): Minutes { | |
| 42 | let m = byHost.get(host); | |
| 43 | if (m === undefined) byHost.set(host, (m = new Map())); | |
| 44 | return m; | |
| 45 | } | |
| 46 | ||
| 47 | /** Which forge hosts each hosted child's `App`: its work is counted on that host. */ | |
| 48 | const hosts = new WeakMap<object, object>(); | |
| 49 | /** `child` is served on `host`'s thread (`spawn/child-apps.ts`). */ | |
| 50 | export function hostChild(child: object, host: object): void { | |
| 51 | hosts.set(child, host); | |
| 52 | } | |
| 53 | /** The forge hosting `app`, when it is a hosted child; undefined for a forge of its own. */ | |
| 54 | export const hostOf = (app: object): object | undefined => hosts.get(app); | |
| 55 | ||
| 56 | function minuteOf(host: object, name: string, at: number): Minute { | |
| 57 | const minutes = minutesOf(host); | |
| 37 | 58 | let mine = minutes.get(name); |
| 38 | 59 | if (mine === undefined) minutes.set(name, (mine = new Map())); |
| 39 | 60 | const key = Math.floor(at / MINUTE_MS); |
| @@ -46,13 +67,14 @@ function minuteOf(name: string, at: number): Minute { | ||
| 46 | 67 | return m; |
| 47 | 68 | } |
| 48 | 69 | |
| 49 | /** A request this process answered for the hosted child `name`, open for `ms`. */ | |
| 70 | /** A request `host` answered for its hosted child `name`, open for `ms`. */ | |
| 50 | 71 | export function noteChildRequest( |
| 72 | host: object, | |
| 51 | 73 | name: string, |
| 52 | 74 | ms: number, |
| 53 | 75 | at = Date.now(), |
| 54 | 76 | ): void { |
| 55 | const m = minuteOf(name, at); | |
| 77 | const m = minuteOf(host, name, at); | |
| 56 | 78 | m.requests++; |
| 57 | 79 | m.requestMs += ms; |
| 58 | 80 | } |
| @@ -61,9 +83,9 @@ export function noteChildRequest( | ||
| 61 | 83 | * A timer slice that held the thread for `ms`, owned by `owner` (`child:<name>`); any other owner |
| 62 | 84 | * is not a child's. |
| 63 | 85 | */ |
| 64 | export function noteChildJob(owner: string, ms: number, at = Date.now()): void { | |
| 86 | export function noteChildJob(host: object, owner: string, ms: number, at = Date.now()): void { | |
| 65 | 87 | if (!owner.startsWith(CHILD_PREFIX)) return; |
| 66 | const m = minuteOf(owner.slice(CHILD_PREFIX.length), at); | |
| 88 | const m = minuteOf(host, owner.slice(CHILD_PREFIX.length), at); | |
| 67 | 89 | m.jobs++; |
| 68 | 90 | m.jobMs += ms; |
| 69 | 91 | } |
| @@ -94,11 +116,12 @@ export function childOfRoute(route: string): string | undefined { | ||
| 94 | 116 | } |
| 95 | 117 | |
| 96 | 118 | /** |
| 97 | * Every child counted in the hour ending at `now`, most thread first. | |
| 119 | * Every child `host` counted in the hour ending at `now`, most thread first. | |
| 98 | 120 | * `stalled` is the stall tally's hour (`loopWatch.tally(...).hour`); `also` |
| 99 | 121 | * names children to list even when they did nothing (those open now). |
| 100 | 122 | */ |
| 101 | 123 | export function childHours( |
| 124 | host: object, | |
| 102 | 125 | now = Date.now(), |
| 103 | 126 | stalled: readonly { |
| 104 | 127 | readonly route: string; |
| @@ -137,7 +160,7 @@ export function childHours( | ||
| 137 | 160 | return r; |
| 138 | 161 | }; |
| 139 | 162 | for (const name of also) row(name); |
| 140 | for (const [name, mine] of minutes) { | |
| 163 | for (const [name, mine] of minutesOf(host)) { | |
| 141 | 164 | for (const [key, m] of mine) { |
| 142 | 165 | if (key <= from || key > to) continue; |
| 143 | 166 | const r = row(name); |
src/perf/duty.ts +1 −1
| @@ -57,7 +57,7 @@ export function startPerfWatcher( | ||
| 57 | 57 | app.log.warn("performance watcher failed", { error: String(error) }); |
| 58 | 58 | } |
| 59 | 59 | }; |
| 60 | const timer = setInterval(() => during("perf-watcher", tick), everyMs); | |
| 60 | const timer = setInterval(() => during("perf-watcher", tick, undefined, app), everyMs); | |
| 61 | 61 | timer.unref(); |
| 62 | 62 | return Object.assign(() => clearInterval(timer), { tick }); |
| 63 | 63 | } |
src/perf/jobs.ts +59 −11
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | * is `performance.now`, the stall watcher's. |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | import { noteChildJob } from "./child_time.ts"; | |
| 15 | import { hostOf, noteChildJob } from "./child_time.ts"; | |
| 16 | 16 | |
| 17 | 17 | /** Finished slices kept to match a stall against: a tick a second fills it in about two minutes. */ |
| 18 | 18 | const KEPT = 256; |
| @@ -113,20 +113,68 @@ export function createJobWatch(now: () => number = () => performance.now()): Job | ||
| 113 | 113 | }; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | /** The process's one job watch, read by the loop watch in `live.ts`. */ | |
| 117 | export const jobWatch = createJobWatch(); | |
| 116 | /** What reads a job watch: the loop watch asks these three (`live.ts`). */ | |
| 117 | export type JobReader = Pick<JobWatch, "across" | "held" | "awaited">; | |
| 118 | ||
| 118 | 119 | /** |
| 119 | * Run `fn` as background job `name` on the process's job watch. With `owner` | |
| 120 | * (a forge hosted in this process, `child:<name>`) the job is named | |
| 121 | * `<owner>:<name>`, so a stall it ran across names the child, and the slice | |
| 122 | * it held the thread is counted against that child (`child_time.ts`). | |
| 120 | * Jobs no forge was named for: the thread's own, run by code that holds no | |
| 121 | * forge (a git reader sweep, a cell watch, a store's flush timer). Every call | |
| 122 | * with a forge in scope passes it, so this holds only what is truly no forge's. | |
| 123 | 123 | */ |
| 124 | export const during = <T>(name: string, fn: () => T, owner?: string): T => { | |
| 125 | if (owner === undefined) return jobWatch.during(name, fn); | |
| 124 | const unowned = createJobWatch(); | |
| 125 | /** | |
| 126 | * Each forge's own watch, as `askingOf` keeps its reading (#12614): one for | |
| 127 | * the process put one test file's jobs in every later file's forge. | |
| 128 | */ | |
| 129 | const watches = new WeakMap<object, JobWatch>(); | |
| 130 | export function jobWatchOf(app: object): JobWatch { | |
| 131 | let watch = watches.get(app); | |
| 132 | if (watch === undefined) watches.set(app, (watch = createJobWatch())); | |
| 133 | return watch; | |
| 134 | } | |
| 135 | ||
| 136 | /** | |
| 137 | * What a forge's loop watch reads (`live.ts`): its own jobs (with its hosted | |
| 138 | * children's, counted on it) and the thread's unowned ones, which hold the | |
| 139 | * loop under every forge. Another forge's are not read, so a test file's jobs | |
| 140 | * are never named in a later file's stalls (#12569, #12614). | |
| 141 | */ | |
| 142 | export function jobsOf(app: object): JobReader { | |
| 143 | const both = (): JobWatch[] => [unowned, jobWatchOf(app)]; | |
| 144 | return { | |
| 145 | across(from, to) { | |
| 146 | // A slice that held the thread wins over an awaiting one, across both as within one. | |
| 147 | const each = both().map((w) => ({ w, blocked: w.held(from, to).length > 0 })); | |
| 148 | const any = each.some((e) => e.blocked); | |
| 149 | return [...new Set(each.filter((e) => !any || e.blocked).flatMap((e) => e.w.across(from, to)))]; | |
| 150 | }, | |
| 151 | held(from, to) { | |
| 152 | return both() | |
| 153 | .flatMap((w) => w.held(from, to)) | |
| 154 | .sort((x, y) => y.ms - x.ms); | |
| 155 | }, | |
| 156 | awaited(from, to) { | |
| 157 | return [...new Set(both().flatMap((w) => w.awaited(from, to)))]; | |
| 158 | }, | |
| 159 | }; | |
| 160 | } | |
| 161 | ||
| 162 | /** | |
| 163 | * Run `fn` as background job `name`. With `app` it is counted on that | |
| 164 | * forge's watch, or on the forge hosting it when it is a hosted child | |
| 165 | * (`child_time.ts`); without, on the thread's own. With `owner` (a forge | |
| 166 | * hosted in this process, `child:<name>`) the job is named `<owner>:<name>`, | |
| 167 | * so a stall it ran across names the child, and the slice it held the | |
| 168 | * thread is counted against that child on its host. | |
| 169 | */ | |
| 170 | export const during = <T>(name: string, fn: () => T, owner?: string, app?: object): T => { | |
| 171 | const forge = app === undefined ? undefined : (hostOf(app) ?? app); | |
| 172 | const watch = forge === undefined ? unowned : jobWatchOf(forge); | |
| 173 | if (owner === undefined) return watch.during(name, fn); | |
| 126 | 174 | const start = performance.now(); |
| 127 | 175 | try { |
| 128 | return jobWatch.during(`${owner}:${name}`, fn); | |
| 176 | return watch.during(`${owner}:${name}`, fn); | |
| 129 | 177 | } finally { |
| 130 | noteChildJob(owner, performance.now() - start); | |
| 178 | if (forge !== undefined) noteChildJob(forge, owner, performance.now() - start); | |
| 131 | 179 | } |
| 132 | 180 | }; |
src/perf/live.ts +4 −3
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | import { createBootStall } from "./boot_stall.ts"; |
| 7 | 7 | import { createGitRecord } from "./git.ts"; |
| 8 | import { jobWatch } from "./jobs.ts"; | |
| 8 | import { jobsOf } from "./jobs.ts"; | |
| 9 | 9 | import { createLoopWatch } from "./loop.ts"; |
| 10 | 10 | import { createInFlight } from "./in_flight.ts"; |
| 11 | 11 | import { childRequestLabel } from "./child_time.ts"; |
| @@ -31,7 +31,7 @@ export const captureStore = createCaptureStore(); | ||
| 31 | 31 | * set for the process, so in a test run a file's traffic or stall was in every |
| 32 | 32 | * later file's /system and /traffic, by the order the files ran in. |
| 33 | 33 | * |
| 34 | * The loop watch is told of jobs from `jobWatch` and of requests from | |
| 34 | * The loop watch is told of jobs from `jobsOf` (this forge's watch and the thread's unowned one, #12614) and of requests from | |
| 35 | 35 | * `inFlight`, which stay the process's: a timer and a request in flight are |
| 36 | 36 | * the thread's, and the watch only reads them. |
| 37 | 37 | * |
| @@ -56,9 +56,10 @@ export function liveOf(app: object): Live { | ||
| 56 | 56 | let live = lives.get(app); |
| 57 | 57 | if (live === undefined) { |
| 58 | 58 | const stallBlame = createStallBlame(); |
| 59 | const jobs = jobsOf(app); | |
| 59 | 60 | live = { |
| 60 | 61 | perfRecord: createPerfRecord(), |
| 61 | loopWatch: createLoopWatch(undefined, jobWatch.across, inFlight.since, jobWatch.held, jobWatch.awaited), | |
| 62 | loopWatch: createLoopWatch(undefined, jobs.across, inFlight.since, jobs.held, jobs.awaited), | |
| 62 | 63 | stallBlame, |
| 63 | 64 | lagMinutes: createLagMinutes((to, span) => stallBlame.worst(to, span, 1)[0]?.what ?? null), |
| 64 | 65 | }; |
src/perf/stall_blame.ts +1 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | * Who ran is the loop watch's finding (`loop.ts`): the route patterns whose |
| 7 | 7 | * request ran across the blocked window, then those still running at the |
| 8 | 8 | * wake as `<pattern> (in flight)` (#11478), else the background jobs marked |
| 9 | * with `jobWatch.during` (`jobs.ts`), else nothing. `what` is the first of | |
| 9 | * with `during` (`jobs.ts`), else nothing. `what` is the first of | |
| 10 | 10 | * those — the longest-running finished route, the oldest open one, or |
| 11 | 11 | * `job:<name>` — and `unknown` when nothing marked ran across the stall. A job that |
| 12 | 12 | * was only awaiting across a stall nothing measured is `awaiting:<name>`: a suspect, |
src/snapshot/service.ts +6 −6
| @@ -432,7 +432,7 @@ export function startSnapshots( | ||
| 432 | 432 | void during("snapshot", async () => { |
| 433 | 433 | if (active === 0 && crewHolds()) return arm(holdRetryMs); |
| 434 | 434 | await take(); |
| 435 | }).catch(() => {}); | |
| 435 | }, undefined, app).catch(() => {}); | |
| 436 | 436 | }, ms); |
| 437 | 437 | } |
| 438 | 438 | arm(options.nightlyInMs ?? untilNightly()); |
| @@ -452,7 +452,7 @@ export function startSnapshots( | ||
| 452 | 452 | const scheduleDrill = (): void => { |
| 453 | 453 | if (options.nightly === false || stopped) return; |
| 454 | 454 | drillTimer = setTimeout(() => { |
| 455 | during("drill", () => runIfDue()).finally(scheduleDrill); | |
| 455 | during("drill", () => runIfDue(), undefined, app).finally(scheduleDrill); | |
| 456 | 456 | }, untilDrill()); |
| 457 | 457 | }; |
| 458 | 458 | // While the newest drill is red, look again when it is owed again. |
| @@ -463,7 +463,7 @@ export function startSnapshots( | ||
| 463 | 463 | const newest = lastDrill(app.db); |
| 464 | 464 | if (newest?.verdict !== "red") return; |
| 465 | 465 | const wait = Math.max(catchUpMs, Date.parse(newest.at) + redRetryMs - Date.now()); |
| 466 | redRetry = setTimeout(() => void during("drill", () => runIfDue()).finally(armRedRetry), wait); | |
| 466 | redRetry = setTimeout(() => void during("drill", () => runIfDue(), undefined, app).finally(armRedRetry), wait); | |
| 467 | 467 | }; |
| 468 | 468 | // Owed and not yet kept: run it once. A restart after a green drill finds it |
| 469 | 469 | // kept; one after a red drill runs it again, once it is past the boot floor. |
| @@ -478,7 +478,7 @@ export function startSnapshots( | ||
| 478 | 478 | if (options.nightly !== false) { |
| 479 | 479 | catchUp = setTimeout( |
| 480 | 480 | () => |
| 481 | void during("drill", () => runIfDue(options.bootRedFloorMs ?? BOOT_RED_FLOOR_MS)) | |
| 481 | void during("drill", () => runIfDue(options.bootRedFloorMs ?? BOOT_RED_FLOOR_MS), undefined, app) | |
| 482 | 482 | .finally(armRedRetry), |
| 483 | 483 | catchUpMs, |
| 484 | 484 | ); |
| @@ -490,7 +490,7 @@ export function startSnapshots( | ||
| 490 | 490 | const scheduleMirror = (first: boolean): void => { |
| 491 | 491 | if (options.nightly === false || stopped) return; |
| 492 | 492 | mirrorTimer = setTimeout(() => { |
| 493 | during("snapshot-mirror", mirrorNow) | |
| 493 | during("snapshot-mirror", mirrorNow, undefined, app) | |
| 494 | 494 | .catch(() => {}) |
| 495 | 495 | .finally(() => scheduleMirror(false)); |
| 496 | 496 | }, first ? Math.min(30_000, everyMs) : everyMs); |
| @@ -503,7 +503,7 @@ export function startSnapshots( | ||
| 503 | 503 | const scheduleCatchUp = (ms: number): void => { |
| 504 | 504 | if (options.nightly === false || stopped) return; |
| 505 | 505 | catchUpSnapshot = setTimeout(() => { |
| 506 | during("snapshot", takeIfDue) | |
| 506 | during("snapshot", takeIfDue, undefined, app) | |
| 507 | 507 | .catch(() => {}) |
| 508 | 508 | .finally(() => { |
| 509 | 509 | bootLookAt = undefined; |
src/spawn/child-apps.ts +3 −1
| @@ -15,7 +15,7 @@ import { listApps } from "../core/apps.ts"; | ||
| 15 | 15 | import { appsRuntime, AppsRuntime } from "../apps/runtime.ts"; |
| 16 | 16 | import { childHost } from "./door.ts"; |
| 17 | 17 | import { childPublicUrl, parentOrigin } from "./placement.ts"; |
| 18 | import { childLabel } from "../perf/child_time.ts"; | |
| 18 | import { childLabel, hostChild } from "../perf/child_time.ts"; | |
| 19 | 19 | |
| 20 | 20 | interface Running { |
| 21 | 21 | readonly child: App; |
| @@ -41,6 +41,8 @@ export async function startChildApps(parent: App, child: App, name: string): Pro | ||
| 41 | 41 | let held = running.get(parent); |
| 42 | 42 | if (!held) running.set(parent, (held = new Map())); |
| 43 | 43 | if (held.has(name)) return; |
| 44 | // Its timers and requests hold this thread: counted on the parent (`perf/child_time.ts`). | |
| 45 | hostChild(child, parent); | |
| 44 | 46 | const runtime = new AppsRuntime(child, { |
| 45 | 47 | domain: `--${name}--${childHost(parent)}`, |
| 46 | 48 | scheme: own.options.scheme, |
src/spawn/heartbeat.ts +1 −1
| @@ -352,7 +352,7 @@ export async function sendBeat( | ||
| 352 | 352 | /** Report now and then every BEAT_MS; returns the timer to clear. */ |
| 353 | 353 | export function startHeartbeat(app: App): ReturnType<typeof setInterval> { |
| 354 | 354 | void sendBeat(app); |
| 355 | return setInterval(() => void during("heartbeat", () => sendBeat(app)), BEAT_MS); | |
| 355 | return setInterval(() => void during("heartbeat", () => sendBeat(app), undefined, app), BEAT_MS); | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | export type Standing = "reporting" | "quiet" | "unheard"; |
src/spawn/host.ts +3 −3
| @@ -282,7 +282,7 @@ function wakeWhenDue(parent: App, ledger: ChildLedger, at: number, now = Date.no | ||
| 282 | 282 | ); |
| 283 | 283 | }; |
| 284 | 284 | const timer = setTimeout( |
| 285 | () => void during("spawn-due-wake", due).catch(() => {}), | |
| 285 | () => void during("spawn-due-wake", due, undefined, parent).catch(() => {}), | |
| 286 | 286 | Math.min(TIMER_MAX_MS, Math.max(0, at - now)), |
| 287 | 287 | ); |
| 288 | 288 | timer.unref?.(); |
| @@ -359,7 +359,7 @@ const floorWatchers = new WeakMap<App, ReturnType<typeof setInterval>>(); | ||
| 359 | 359 | |
| 360 | 360 | function keepWatchingFloor(parent: App): void { |
| 361 | 361 | if (floorWatchers.has(parent)) return; |
| 362 | const timer = setInterval(() => void during("spawn-floor", () => sleepBelowFloor(parent)).catch(() => {}), FLOOR_EVERY_MS); | |
| 362 | const timer = setInterval(() => void during("spawn-floor", () => sleepBelowFloor(parent), undefined, parent).catch(() => {}), FLOOR_EVERY_MS); | |
| 363 | 363 | timer.unref?.(); |
| 364 | 364 | floorWatchers.set(parent, timer); |
| 365 | 365 | } |
| @@ -457,7 +457,7 @@ function keepSweeping(parent: App): void { | ||
| 457 | 457 | const timer = setInterval(() => void during("spawn-idle", async () => { |
| 458 | 458 | await sleepLapsed(parent); |
| 459 | 459 | await sleepIdleChildren(parent); |
| 460 | }).catch(() => {}), every); | |
| 460 | }, undefined, parent).catch(() => {}), every); | |
| 461 | 461 | timer.unref?.(); |
| 462 | 462 | sweepers.set(parent, timer); |
| 463 | 463 | } |
src/spawn/origin_broker.ts +1 −1
| @@ -488,7 +488,7 @@ export async function brokerCallback( | ||
| 488 | 488 | if (ready.changes !== 1) return back({ failure: "failed" }); |
| 489 | 489 | // A token waits a minute, not until somebody next asks: its row is swept when its time is up. |
| 490 | 490 | setTimeout( |
| 491 | () => void during("origin-broker-sweep", () => sweepBroker(app)), | |
| 491 | () => void during("origin-broker-sweep", () => sweepBroker(app), undefined, app), | |
| 492 | 492 | CODE_TTL_MS + 1_000, |
| 493 | 493 | ).unref(); |
| 494 | 494 | // The audit names who and where. Never a token, never the code. |
src/spawn/reach.ts +2 −2
| @@ -296,8 +296,8 @@ export function startReachWatch( | ||
| 296 | 296 | everyMs = REACH_EVERY_MS, |
| 297 | 297 | asleep: (name: string) => boolean = () => false, |
| 298 | 298 | ): ReturnType<typeof setInterval> { |
| 299 | const first = setTimeout(() => void during("reach", () => sweepReach(app, asleep)), 30_000); | |
| 300 | const timer = setInterval(() => void during("reach", () => sweepReach(app, asleep)), everyMs); | |
| 299 | const first = setTimeout(() => void during("reach", () => sweepReach(app, asleep), undefined, app), 30_000); | |
| 300 | const timer = setInterval(() => void during("reach", () => sweepReach(app, asleep), undefined, app), everyMs); | |
| 301 | 301 | app.closing.signal.addEventListener("abort", () => clearTimeout(first), { once: true }); |
| 302 | 302 | return timer; |
| 303 | 303 | } |
src/spawn/upstream.ts +1 −1
| @@ -214,7 +214,7 @@ function tellOwner(app: App, repo: Repo, fork: string, behind: number, commits = | ||
| 214 | 214 | /** Check at boot and every hour; returns the timer to clear. */ |
| 215 | 215 | export function startUpstreamWatch(app: App): ReturnType<typeof setInterval> { |
| 216 | 216 | void checkUpstream(app); |
| 217 | return setInterval(() => void during("upstream", () => checkUpstream(app)), CHECK_MS); | |
| 217 | return setInterval(() => void during("upstream", () => checkUpstream(app), undefined, app), CHECK_MS); | |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** The state in one plain sentence, escaped by whoever renders it. */ |
src/system/retention.ts +5 −5
| @@ -208,35 +208,35 @@ export function startRetention(app: App, which: { local: boolean; engine: boolea | ||
| 208 | 208 | pending[0] = setTimeout(() => { |
| 209 | 209 | if (stopped) return; |
| 210 | 210 | if (held(backfill)) return; |
| 211 | during("landed-backfill", () => backfill(work(jobs.backfill, "deploy landing backfill"))); | |
| 211 | during("landed-backfill", () => backfill(work(jobs.backfill, "deploy landing backfill")), undefined, app); | |
| 212 | 212 | }, delay); |
| 213 | 213 | }; |
| 214 | 214 | const live = (delay: number): void => { |
| 215 | 215 | pending[1] = setTimeout(() => { |
| 216 | 216 | if (stopped) return; |
| 217 | 217 | if (held(live)) return; |
| 218 | during("retention-live", () => live(work(jobs.live, "live event prune"))); | |
| 218 | during("retention-live", () => live(work(jobs.live, "live event prune")), undefined, app); | |
| 219 | 219 | }, delay); |
| 220 | 220 | }; |
| 221 | 221 | const events = (delay: number): void => { |
| 222 | 222 | pending[2] = setTimeout(() => { |
| 223 | 223 | if (stopped) return; |
| 224 | 224 | if (held(events)) return; |
| 225 | during("retention-events", () => events(work(jobs.events, "event prune"))); | |
| 225 | during("retention-events", () => events(work(jobs.events, "event prune")), undefined, app); | |
| 226 | 226 | }, delay); |
| 227 | 227 | }; |
| 228 | 228 | const samples = (delay: number): void => { |
| 229 | 229 | pending[3] = setTimeout(() => { |
| 230 | 230 | if (stopped) return; |
| 231 | 231 | if (held(samples)) return; |
| 232 | during("retention-samples", () => samples(work(jobs.samples, "machine sample prune"))); | |
| 232 | during("retention-samples", () => samples(work(jobs.samples, "machine sample prune")), undefined, app); | |
| 233 | 233 | }, delay); |
| 234 | 234 | }; |
| 235 | 235 | const deploys = (delay: number): void => { |
| 236 | 236 | pending[4] = setTimeout(() => { |
| 237 | 237 | if (stopped) return; |
| 238 | 238 | if (held(deploys)) return; |
| 239 | during("retention-deploys", () => deploys(work(jobs.deploys, "deploy ledger trim"))); | |
| 239 | during("retention-deploys", () => deploys(work(jobs.deploys, "deploy ledger trim")), undefined, app); | |
| 240 | 240 | }, delay); |
| 241 | 241 | }; |
| 242 | 242 | if (which.engine) { |
src/web/pages/system.ts +1 −1
| @@ -604,7 +604,7 @@ export async function systemPage(ctx: Ctx): Promise<Response> { | ||
| 604 | 604 | // Only this forge's own: the count is the process's, and a process holds one forge everywhere but |
| 605 | 605 | // a test. |
| 606 | 606 | const mine = new Set(listed.map((c) => c.name)); |
| 607 | const inProcess = childHours(Date.now(), tally.hour, openChildren(ctx.app).map((c) => c.name)).filter((r) => mine.has(r.name)); | |
| 607 | const inProcess = childHours(ctx.app, Date.now(), tally.hour, openChildren(ctx.app).map((c) => c.name)).filter((r) => mine.has(r.name)); | |
| 608 | 608 | const nowMono = performance.now(); |
| 609 | 609 | const worst = liveOf(ctx.app).stallBlame.worst(nowMono, HOUR_MS, WORST_STALLS); |
| 610 | 610 | // Never waits on the cluster: the last reading, or the declared rows while the first read runs behind. |
test/mcp-system-stalls.test.ts +6 −5
| @@ -38,13 +38,14 @@ test("a stall under a named job is read through system, at most 10, most ms firs | ||
| 38 | 38 | // The watch is the process's one: stalls and requests an earlier file left |
| 39 | 39 | // would crowd the top 10 or be blamed ahead of the job. Start from nothing. |
| 40 | 40 | liveOf(app).loopWatch.clear(); |
| 41 | // The job holds the loop for a real share of the stall: one that only brushed it is not | |
| 42 | // named (`perf/loop.ts`). | |
| 41 | // The job holds the loop for the whole stall: one that only brushed it is not named | |
| 42 | // (`perf/loop.ts`), and a window wider than the job reaches back into the file before (#12614). | |
| 43 | const from = performance.now(); | |
| 43 | 44 | during("test-job-10907", () => { |
| 44 | const until = performance.now() + 40; | |
| 45 | const until = from + LIMIT_MS + 10; | |
| 45 | 46 | while (performance.now() < until); |
| 46 | }); | |
| 47 | liveOf(app).loopWatch.stalled(LIMIT_MS + 10, performance.now()); | |
| 47 | }, undefined, app); | |
| 48 | liveOf(app).loopWatch.stalled(LIMIT_MS + 10, Math.max(performance.now(), from + LIMIT_MS + 10)); | |
| 48 | 49 | const res = await fetch(`${servers.url}/mcp`, { |
| 49 | 50 | method: "POST", |
| 50 | 51 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` }, |
test/module-state.baseline.txt −2
| @@ -60,7 +60,6 @@ src/crew/autonomy.ts:cleanAt | ||
| 60 | 60 | src/crew/autonomy.ts:conflicted |
| 61 | 61 | src/crew/autonomy.ts:conflictedAt |
| 62 | 62 | src/crew/autonomy.ts:sweeping |
| 63 | src/crew/ceiling_stagger.ts:memo | |
| 64 | 63 | src/crew/conversation.ts:live |
| 65 | 64 | src/crew/conversation.ts:queues |
| 66 | 65 | src/crew/conversation.ts:stoppers |
| @@ -145,7 +144,6 @@ src/origins/providers/index.ts:cache | ||
| 145 | 144 | src/origins/sync.ts:inFlight |
| 146 | 145 | src/origins/token-reach.ts:kept |
| 147 | 146 | src/origins/work-branch.ts:tipsSeen |
| 148 | src/perf/child_time.ts:minutes | |
| 149 | 147 | src/release/changelog.ts:cache |
| 150 | 148 | src/release/prove.ts:superseded |
| 151 | 149 | src/runs/activity.ts:lastAt |
test/perf-jobs-per-forge.test.ts added +76
| @@ -0,0 +1,76 @@ | ||
| 1 | /** | |
| 2 | * The job watch and a hosted child's minutes are each forge's own (#12614): | |
| 3 | * two forges booted in one process, as two test files are, never read each | |
| 4 | * other's jobs or children, and each forge's loop watch reads its own. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { startMemorySampler } from "../src/boards/memory.ts"; | |
| 12 | import { childHours, hostChild, noteChildRequest } from "../src/perf/child_time.ts"; | |
| 13 | import { during, jobsOf, jobWatchOf } from "../src/perf/jobs.ts"; | |
| 14 | ||
| 15 | let dirs: string[] = []; | |
| 16 | let one: App; | |
| 17 | let other: App; | |
| 18 | ||
| 19 | beforeAll(async () => { | |
| 20 | dirs = [await mkdtemp(join(tmpdir(), "jobs-one-")), await mkdtemp(join(tmpdir(), "jobs-other-"))]; | |
| 21 | one = createApp({ dataDir: dirs[0]!, url: "https://one.test", port: 0 }); | |
| 22 | other = createApp({ dataDir: dirs[1]!, url: "https://other.test", port: 0 }); | |
| 23 | }); | |
| 24 | ||
| 25 | afterAll(async () => { | |
| 26 | one?.close(); | |
| 27 | other?.close(); | |
| 28 | for (const d of dirs) await rm(d, { recursive: true, force: true }); | |
| 29 | }); | |
| 30 | ||
| 31 | const block = (ms: number) => { | |
| 32 | const until = performance.now() + ms; | |
| 33 | while (performance.now() < until); | |
| 34 | }; | |
| 35 | ||
| 36 | test("a job and a child minute noted on one forge are not the other's", () => { | |
| 37 | const before = performance.now(); | |
| 38 | during("own-sweep", () => block(2), undefined, one); | |
| 39 | during("lane", () => block(2), "child:kid", one); | |
| 40 | noteChildRequest(one, "kid", 40); | |
| 41 | const after = performance.now(); | |
| 42 | ||
| 43 | expect(jobWatchOf(one).across(before, after)).toEqual(expect.arrayContaining(["own-sweep", "child:kid:lane"])); | |
| 44 | expect(childHours(one).find((r) => r.name === "kid")).toMatchObject({ requests: 1, jobs: 1 }); | |
| 45 | ||
| 46 | expect(jobWatchOf(other).across(before, after)).toEqual([]); | |
| 47 | expect(jobWatchOf(other).held(before, after)).toEqual([]); | |
| 48 | expect(childHours(other)).toEqual([]); | |
| 49 | ||
| 50 | // Each forge's stall watcher reads its own jobs, and not the other's. | |
| 51 | expect(jobsOf(one).across(before, after)).toEqual(expect.arrayContaining(["own-sweep", "child:kid:lane"])); | |
| 52 | expect(jobsOf(other).across(before, after)).toEqual([]); | |
| 53 | }); | |
| 54 | ||
| 55 | test("a hosted child's job is counted on the forge hosting it", () => { | |
| 56 | const child = {}; | |
| 57 | hostChild(child, other); | |
| 58 | const before = performance.now(); | |
| 59 | during("apps-sweep", () => block(2), "child:hosted", child); | |
| 60 | const after = performance.now(); | |
| 61 | expect(jobWatchOf(other).across(before, after)).toEqual(["child:hosted:apps-sweep"]); | |
| 62 | expect(childHours(other).map((r) => r.name)).toEqual(["hosted"]); | |
| 63 | expect(jobWatchOf(child).across(before, after)).toEqual([]); | |
| 64 | expect(childHours(one).some((r) => r.name === "hosted")).toBe(false); | |
| 65 | }); | |
| 66 | ||
| 67 | test("a forge's own timer, started with no owner, is read on that forge's watch and not another's", () => { | |
| 68 | const before = performance.now(); | |
| 69 | const sampler = startMemorySampler(one, 3_600_000); | |
| 70 | sampler.stop(); | |
| 71 | const after = performance.now(); | |
| 72 | expect(jobWatchOf(one).across(before, after)).toContain("memory-sampler"); | |
| 73 | expect(jobWatchOf(other).across(before, after)).not.toContain("memory-sampler"); | |
| 74 | expect(jobWatchOf(other).held(before, after)).toEqual([]); | |
| 75 | expect(jobsOf(one).across(before, after)).toContain("memory-sampler"); | |
| 76 | }); |
test/relay-stall-name.test.ts +2 −2
| @@ -29,7 +29,7 @@ import { getAppByRepo } from "../src/core/apps.ts"; | ||
| 29 | 29 | import type { Repo } from "../src/core/repos.ts"; |
| 30 | 30 | import { createUser, type User } from "../src/core/users.ts"; |
| 31 | 31 | import { serve, type Servers } from "../src/http/server.ts"; |
| 32 | import { createJobWatch, jobWatch } from "../src/perf/jobs.ts"; | |
| 32 | import { createJobWatch, during } from "../src/perf/jobs.ts"; | |
| 33 | 33 | import { liveOf } from "../src/perf/live.ts"; |
| 34 | 34 | import { createLoopWatch, type Stall } from "../src/perf/loop.ts"; |
| 35 | 35 | import { loopWorst } from "../src/perf/loop_worst.ts"; |
| @@ -171,7 +171,7 @@ describe("forge-stall on the relayed answer", () => { | ||
| 171 | 171 | * blocks the loop, so the test takes no time and the stall is exactly `ms`. |
| 172 | 172 | */ |
| 173 | 173 | const stallAsJob = (name: string, ms: number) => { |
| 174 | jobWatch.during(name, () => {}); | |
| 174 | during(name, () => {}); | |
| 175 | 175 | const now = performance.now(); |
| 176 | 176 | loopWorst.note(ms, now); |
| 177 | 177 | // A job that ran for a moment was only across the stall (`WITNESS_SHARE`, `perf/loop.ts`): |
test/spawn-in-process-visible.test.ts +16 −12
| @@ -19,7 +19,7 @@ import { | ||
| 19 | 19 | childOfRoute, |
| 20 | 20 | noteChildRequest, |
| 21 | 21 | } from "../src/perf/child_time.ts"; |
| 22 | import { during, jobWatch } from "../src/perf/jobs.ts"; | |
| 22 | import { during, jobWatchOf } from "../src/perf/jobs.ts"; | |
| 23 | 23 | import { liveOf } from "../src/perf/live.ts"; |
| 24 | 24 | import { stallLine } from "../src/perf/loop.ts"; |
| 25 | 25 | import { clientRows, servedWindow } from "../src/spawn/clients.ts"; |
| @@ -118,10 +118,12 @@ describe("what a forge in this process took of the serving thread", () => { | ||
| 118 | 118 | test("its requests and timer slices are counted against it by name, for an hour", () => { |
| 119 | 119 | // Its own clock, a year off the other tests': what they count is outside this hour. |
| 120 | 120 | const now = Date.parse("2025-11-13T12:00:00Z"); |
| 121 | noteChildRequest("counted", 40, now - 10 * 60_000); | |
| 122 | noteChildRequest("counted", 60, now - 5_000); | |
| 123 | noteChildRequest("counted", 999, now - 61 * 60_000); // past the hour | |
| 121 | const host = {}; | |
| 122 | noteChildRequest(host, "counted", 40, now - 10 * 60_000); | |
| 123 | noteChildRequest(host, "counted", 60, now - 5_000); | |
| 124 | noteChildRequest(host, "counted", 999, now - 61 * 60_000); // past the hour | |
| 124 | 125 | const rows = childHours( |
| 126 | host, | |
| 125 | 127 | now, |
| 126 | 128 | [ |
| 127 | 129 | { route: "child:counted", ms: 640, count: 2 }, |
| @@ -141,6 +143,7 @@ describe("what a forge in this process took of the serving thread", () => { | ||
| 141 | 143 | }); |
| 142 | 144 | |
| 143 | 145 | test("a timer it owns is named for it in the job ring, so a stall across it reads child:<name>", () => { |
| 146 | const host = {}; | |
| 144 | 147 | const before = performance.now(); |
| 145 | 148 | during( |
| 146 | 149 | "sweep-of-a-test", |
| @@ -149,20 +152,21 @@ describe("what a forge in this process took of the serving thread", () => { | ||
| 149 | 152 | while (performance.now() < until); |
| 150 | 153 | }, |
| 151 | 154 | "child:timed", |
| 155 | host, | |
| 152 | 156 | ); |
| 153 | 157 | const after = performance.now(); |
| 154 | expect(jobWatch.across(before, after)).toContain("child:timed:sweep-of-a-test"); | |
| 158 | expect(jobWatchOf(host).across(before, after)).toContain("child:timed:sweep-of-a-test"); | |
| 155 | 159 | expect(stallLine({ at: after, lateMs: after - before, routes: [], jobs: ["child:timed:sweep-of-a-test"] })).toContain( |
| 156 | 160 | "no request; jobs child:timed:sweep-of-a-test", |
| 157 | 161 | ); |
| 158 | const row = childHours().find((r) => r.name === "timed"); | |
| 162 | const row = childHours(host).find((r) => r.name === "timed"); | |
| 159 | 163 | expect(row?.jobs).toBe(1); |
| 160 | 164 | expect(row?.jobMs).toBeGreaterThan(0); |
| 161 | 165 | // A job with no owner is the forge's own, and is counted against no child. |
| 162 | const rows = childHours().length; | |
| 163 | during("sweep-of-a-test", () => {}); | |
| 164 | expect(childHours().length).toBe(rows); | |
| 165 | expect(childHours().find((r) => r.name === "timed")?.jobs).toBe(1); | |
| 166 | const rows = childHours(host).length; | |
| 167 | during("sweep-of-a-test", () => {}, undefined, host); | |
| 168 | expect(childHours(host).length).toBe(rows); | |
| 169 | expect(childHours(host).find((r) => r.name === "timed")?.jobs).toBe(1); | |
| 166 | 170 | }); |
| 167 | 171 | }); |
| 168 | 172 | |
| @@ -230,7 +234,7 @@ describe("a parent holding a forge in its own process", () => { | ||
| 230 | 234 | // Open it, so the next request is answered by a forge already in this process. |
| 231 | 235 | await (await fetch(`${servers.url}/healthz`, { headers: { host: "homie--forge.test" } })).text(); |
| 232 | 236 | const child = openChildren(parent).find((c) => c.name === "homie")!.app; |
| 233 | const had = childHours().find((r) => r.name === "homie")?.requests ?? 0; | |
| 237 | const had = childHours(parent).find((r) => r.name === "homie")?.requests ?? 0; | |
| 234 | 238 | liveOf(parent).loopWatch.clear(); |
| 235 | 239 | // The child's own request holds the parent's thread: its first statement takes 80 ms of |
| 236 | 240 | // synchronous work, as a slow query or a git call of the child's would. A stall is named |
| @@ -247,7 +251,7 @@ describe("a parent holding a forge in its own process", () => { | ||
| 247 | 251 | const stall = liveOf(parent).loopWatch.stalled(250, performance.now()); |
| 248 | 252 | expect(stall?.routes).toContain("child:homie"); |
| 249 | 253 | expect(stallLine(stall!)).toContain("running then: child:homie"); |
| 250 | expect(childHours().find((r) => r.name === "homie")?.requests).toBe(had + 1); | |
| 254 | expect(childHours(parent).find((r) => r.name === "homie")?.requests).toBe(had + 1); | |
| 251 | 255 | // The parent's own request is still its route's. |
| 252 | 256 | liveOf(parent).loopWatch.clear(); |
| 253 | 257 | const mine = holdOnce(parent, 80); |
new above
offline
unownedis still a process-wide singleton that every app-lessduringcall shares, which is the leak #12614 names. Move the callers that have an app in scope ontojobWatchOf(app); keep this only for jobs that truly have no forge.