Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-813]): address review (codex) round 2

[._.]/ Adam Eivy619899522939
diff --git a/client/src/hooks/useCityData.js b/client/src/hooks/useCityData.js
index cd5413ddb1..f80f2e26ba 100644
--- a/client/src/hooks/useCityData.js
+++ b/client/src/hooks/useCityData.js
@@ -255,21 +255,26 @@ export const useCityData = () => {
// (start → model:loading → model:loaded → complete/error) globally. Track the in-flight
// set so the central spire glows/beams with live model activity; the pure reducer adds
// on non-terminal phases, drops on complete/error, and prunes stale ops.
- // Prune expired ops and re-arm while any remain, so a `done` afterglow beam fades after
- // afterglowMs and a stranded in-flight op clears at opMaxAgeMs — without depending on a
- // further `ai:status` event to advance the clock. Tick at the afterglow cadence (the
- // shorter window); pruneAiOps returns the same ref when nothing expired, short-circuiting
- // the setState to no re-render.
+ // Prune expired ops AND clear a stale flare, re-arming while either is still pending —
+ // so a `done` afterglow beam (afterglowMs), a stranded in-flight op (opMaxAgeMs), and a
+ // flare-only beam (flareMs, when a fast throughput-less call left no op behind) all fade
+ // without depending on a further `ai:status` event to advance the clock. Tick at the
+ // afterglow cadence; both pruneAiOps and the lastStartTs clear short-circuit to no
+ // re-render when nothing expired.
const scheduleAiPrune = () => {
if (aiPruneTimerRef.current) clearTimeout(aiPruneTimerRef.current);
aiPruneTimerRef.current = setTimeout(() => {
- let remaining = 0;
+ let rearm = false;
setAiActivity(prev => {
- const ops = pruneAiOps(prev.ops);
- remaining = Object.keys(ops).length;
- return ops === prev.ops ? prev : { ...prev, ops };
+ const now = Date.now();
+ const ops = pruneAiOps(prev.ops, now);
+ const flareActive = prev.lastStartTs > 0 && now - prev.lastStartTs <= AI_CORE.flareMs;
+ const lastStartTs = prev.lastStartTs > 0 && !flareActive ? 0 : prev.lastStartTs;
+ rearm = Object.keys(ops).length > 0 || flareActive;
+ if (ops === prev.ops && lastStartTs === prev.lastStartTs) return prev;
+ return { ...prev, ops, lastStartTs };
});
- if (remaining > 0) scheduleAiPrune();
+ if (rearm) scheduleAiPrune();
}, AI_CORE.afterglowMs + 100);
};
diff --git a/client/src/utils/cityAiCore.js b/client/src/utils/cityAiCore.js
index 80cf424149..2056a54a73 100644
--- a/client/src/utils/cityAiCore.js
+++ b/client/src/utils/cityAiCore.js
@@ -99,12 +99,24 @@ export function applyAiStatusEvent(ops, event, now = Date.now()) {
const tokensPerSec = readTokensPerSec(event.tokensPerSec) ?? prev.tokensPerSec ?? null;
if (TERMINAL_PHASES.has(event.phase)) {
// Drop immediately when there's nothing to show; otherwise keep a short afterglow so
- // the just-measured throughput visibly thickens the beam before it fades.
+ // the just-measured throughput visibly thickens the beam before it fades. Re-read the
+ // association from the event (every phase event carries it) — the in-flight entry may
+ // have been pruned at opMaxAgeMs on a long call, so falling back to `prev` alone would
+ // lose the building target.
if (tokensPerSec === null) {
delete next[id];
return next;
}
- next[id] = { ...prev, id, done: true, tokensPerSec, ts: now };
+ next[id] = {
+ id,
+ done: true,
+ model: event.model || prev.model || null,
+ tier: modelTier(event.model || prev.model),
+ appId: event.appId ?? prev.appId ?? null,
+ workspacePath: event.workspacePath ?? prev.workspacePath ?? null,
+ tokensPerSec,
+ ts: now,
+ };
return next;
}
next[id] = {
diff --git a/client/src/utils/cityAiCore.test.js b/client/src/utils/cityAiCore.test.js
index fe9391f7ff..a28989a9c9 100644
--- a/client/src/utils/cityAiCore.test.js
+++ b/client/src/utils/cityAiCore.test.js
@@ -182,6 +182,16 @@ describe('applyAiStatusEvent building association', () => {
expect(ops.a.appId).toBe('app-1'); // association carried onto the afterglow
});
+ it('reads the association from the completion event when the in-flight op was already pruned', () => {
+ // A long call (300s) whose in-flight entry was pruned at opMaxAgeMs (60s); the completion
+ // event still carries appId, so the afterglow must target the building, not go radial.
+ const completeEvent = ev('a', 'complete', 'm', { appId: 'app-9', workspacePath: '/r/x', tokensPerSec: 40 });
+ const ops = applyAiStatusEvent({}, completeEvent, NOW); // empty prior map → no prev
+ expect(ops.a.done).toBe(true);
+ expect(ops.a.appId).toBe('app-9');
+ expect(ops.a.workspacePath).toBe('/r/x');
+ });
+
it('prunes a done afterglow op once afterglowMs has passed', () => {
let ops = applyAiStatusEvent({}, ev('a', 'start', 'm'), NOW);
ops = applyAiStatusEvent(ops, ev('a', 'complete', 'm', { tokensPerSec: 80 }), NOW + 5);