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: keep the cheap character path cheap for legacy callers, and stop the memory tile claiming Brain (#2676)

[._.]/ Adam Eivyf75f14bed951
diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.js
index be5a75570a..fe44d6b685 100644
--- a/client/src/services/apiSystem.js
+++ b/client/src/services/apiSystem.js
@@ -9,8 +9,16 @@ export const getAlertsSummary = (options) => request('/alerts/summary', options)
// the polling CyberCity XP HUD badge). Both default on, so a caller that wants the whole
// sheet just calls getCharacter().
export const getCharacter = ({ skills = true, metrics = true, ...options } = {}) => {
- const off = [!skills && 'skills=0', !metrics && 'metrics=0'].filter(Boolean);
- return request(`/character${off.length ? `?${off.join('&')}` : ''}`, options);
+ const params = new URLSearchParams();
+ if (!skills) params.set('skills', '0');
+ if (!metrics) params.set('metrics', '0');
+ // `metrics=1` must go on the wire EXPLICITLY when skills are off, because the server infers
+ // an absent `metrics` from `skills` (back-compat: a bare `?skills=0` predates the metrics
+ // grid and means "cheap sheet"). Without this, `{ skills: false }` would silently drop the
+ // metrics this wrapper's own default promises.
+ else if (!skills) params.set('metrics', '1');
+ const query = params.toString();
+ return request(`/character${query ? `?${query}` : ''}`, options);
};
// Health
diff --git a/client/src/services/apiSystem.test.js b/client/src/services/apiSystem.test.js
index aceb2023d3..850f7dabd4 100644
--- a/client/src/services/apiSystem.test.js
+++ b/client/src/services/apiSystem.test.js
@@ -6,11 +6,12 @@ vi.mock('./apiCore.js', () => ({
let request;
let patchSettingsSlice;
+let getCharacter;
beforeEach(async () => {
vi.resetModules();
({ request } = await import('./apiCore.js'));
- ({ patchSettingsSlice } = await import('./apiSystem.js'));
+ ({ patchSettingsSlice, getCharacter } = await import('./apiSystem.js'));
request.mockReset();
});
@@ -137,3 +138,38 @@ describe('patchSettingsSlice', () => {
expect(body).toEqual({ imageGen: { local: { pythonPath: '/x' } } });
});
});
+
+// The character query builder encodes a non-obvious server rule: an ABSENT `metrics` is
+// inferred from `skills` (back-compat — a bare `?skills=0` predates the metrics grid and has
+// only ever meant "cheap sheet"). So this wrapper must put `metrics` on the wire explicitly
+// whenever inference would contradict its own documented defaults.
+describe('getCharacter query building (#2676)', () => {
+ const pathOf = () => request.mock.calls[0][0];
+
+ it('sends no query at all when the caller wants the whole sheet', () => {
+ getCharacter();
+ expect(pathOf()).toBe('/character');
+ });
+
+ it('sends both flags off for the cheap path', () => {
+ getCharacter({ skills: false, metrics: false });
+ expect(pathOf()).toBe('/character?skills=0&metrics=0');
+ });
+
+ it('sends metrics=1 explicitly when skills are off but metrics are wanted', () => {
+ // Without the explicit `1` the server would infer metrics=false from `skills=0` and
+ // silently drop the metrics this wrapper's `metrics = true` default promises.
+ getCharacter({ skills: false });
+ expect(pathOf()).toBe('/character?skills=0&metrics=1');
+ });
+
+ it('sends only metrics=0 when metrics alone are declined', () => {
+ getCharacter({ metrics: false });
+ expect(pathOf()).toBe('/character?metrics=0');
+ });
+
+ it('forwards request options without leaking the flags into them', () => {
+ getCharacter({ skills: false, metrics: false, silent: true });
+ expect(request.mock.calls[0][1]).toEqual({ silent: true });
+ });
+});
diff --git a/server/routes/character.js b/server/routes/character.js
index 36837b45ab..6d91c2e9af 100644
--- a/server/routes/character.js
+++ b/server/routes/character.js
@@ -45,9 +45,15 @@ const addEventSchema = z.object({
// `?skills=0` / `?metrics=0` opt out of each derived registry's domain fan-out, for consumers
// that only read the persisted fields plus the age level — notably the CyberCity HUD, which
-// polls this route every 15s and renders only `level`. They gate independently (a caller may
-// well want the metrics grid without the skill curve), and both default to ON so an unaware
-// caller — or an older client bundle that predates the flag — still gets the full sheet.
+// polls this route every 15s and renders only `level`. Both default to ON, so an unaware
+// caller still gets the full sheet.
+//
+// `metrics` defaults to whatever `skills` says rather than to ON. `?skills=0` predates the
+// metrics grid (#2676) and has only ever meant one thing — "give me the cheap sheet, skip the
+// domain fan-out" — so a caller that predates the flag (a browser holding a stale bundle
+// across an update, or any external script) must not silently start paying a NEW fan-out it
+// has no way to ask about. An explicit `?metrics=` always wins, so the two stay independently
+// gateable: `?skills=0&metrics=1` gets the grid without the skill curve.
const flagEnum = z.enum(['0', '1', 'false', 'true']).optional();
const getCharacterQuerySchema = z.object({
skills: flagEnum,
@@ -62,7 +68,7 @@ router.get('/', asyncHandler(async (req, res) => {
const { skills, metrics } = validateRequest(getCharacterQuerySchema, req.query);
res.json(await characterService.getCharacter({
withSkills: isEnabled(skills),
- withMetrics: isEnabled(metrics),
+ withMetrics: isEnabled(metrics ?? skills),
}));
}));
diff --git a/server/routes/character.test.js b/server/routes/character.test.js
index be729b81d5..6b8fb916f5 100644
--- a/server/routes/character.test.js
+++ b/server/routes/character.test.js
@@ -40,15 +40,25 @@ describe('GET /api/character', () => {
expect(characterService.getCharacter).toHaveBeenCalledWith({ withSkills: true, withMetrics: true });
});
- it('skips the skill fan-out for ?skills=0 and ?skills=false', async () => {
+ it('skips BOTH fan-outs for a legacy ?skills=0 caller that predates the metrics flag', async () => {
+ // Back-compat: `?skills=0` has only ever meant "give me the cheap sheet". A caller that
+ // predates #2676 (a browser on a stale bundle, an external script) has no way to ask for
+ // `metrics=0`, so it must not silently start paying the new fan-out — the CyberCity HUD
+ // issues exactly this request every 15s.
for (const value of ['0', 'false']) {
vi.clearAllMocks();
const res = await request(makeApp()).get(`/api/character?skills=${value}`);
expect(res.status).toBe(200);
- expect(characterService.getCharacter).toHaveBeenCalledWith({ withSkills: false, withMetrics: true });
+ expect(characterService.getCharacter).toHaveBeenCalledWith({ withSkills: false, withMetrics: false });
}
});
+ it('lets an explicit ?metrics= override the value inherited from ?skills=', async () => {
+ // The inheritance is only a default — the two stay independently gateable.
+ await request(makeApp()).get('/api/character?skills=0&metrics=1');
+ expect(characterService.getCharacter).toHaveBeenCalledWith({ withSkills: false, withMetrics: true });
+ });
+
it('skips the metrics fan-out for ?metrics=0 and ?metrics=false', async () => {
for (const value of ['0', 'false']) {
vi.clearAllMocks();
@@ -58,6 +68,11 @@ describe('GET /api/character', () => {
}
});
+ it('skips only the metrics fan-out when metrics alone is disabled', async () => {
+ await request(makeApp()).get('/api/character?metrics=0');
+ expect(characterService.getCharacter).toHaveBeenCalledWith({ withSkills: true, withMetrics: false });
+ });
+
it('gates the two fan-outs independently', async () => {
await request(makeApp()).get('/api/character?skills=0&metrics=0');
expect(characterService.getCharacter).toHaveBeenCalledWith({ withSkills: false, withMetrics: false });
diff --git a/server/services/characterMetrics.js b/server/services/characterMetrics.js
index f07a3bbf4a..4934ab64ca 100644
--- a/server/services/characterMetrics.js
+++ b/server/services/characterMetrics.js
@@ -116,7 +116,13 @@ export const METRICS = [
id: 'memoryCount',
label: 'Memories',
unit: 'count',
- hint: 'Captured in Brain',
+ hint: 'Active memories across PortOS',
+ // "across PortOS", NOT "captured in Brain": the signal is `countMemories({})`, and
+ // `filterMemoryIndex` with no options filters by `status: 'active'` ONLY — so agent-, CoS-
+ // and API-created memories are all in here, not just the Brain-tagged ones
+ // (`sourceAppId: 'brain'`, per brainMemoryBridge.js). The whole store is the more useful
+ // number AND the one that matches the `archivist` skill's reading of the same signal;
+ // narrowing to Brain would undercount the user's memories and make the two disagree.
compute: async (read) => read('memoryCount'),
},
{
diff --git a/server/services/characterMetrics.test.js b/server/services/characterMetrics.test.js
index 6eb954cede..fbad2cdd51 100644
--- a/server/services/characterMetrics.test.js
+++ b/server/services/characterMetrics.test.js
@@ -220,6 +220,12 @@ describe('getCharacterMetrics — populated domains', () => {
expect(media.label).not.toMatch(/render/i);
expect(media.hint).not.toMatch(/render/i);
});
+
+ it('does not claim the memory tile counts only BRAIN captures', async () => {
+ // countMemories({}) filters on `status: 'active'` only — agent/CoS/API memories are all in
+ // the tally, not just the `sourceAppId: 'brain'` ones.
+ expect(byId(await getCharacterMetrics(), 'memoryCount').hint).not.toMatch(/brain/i);
+ });
});
describe('getCharacterMetrics — goalCompletionRate', () => {
@@ -365,7 +371,7 @@ describe('getCharacterMetrics — stat-read failure (must NOT collapse into a fa
it('keeps id/label/unit/hint on an unavailable metric so the UI can still name it', async () => {
vi.mocked(countMemories).mockImplementation(fail('memory backend'));
expect(byId(await getCharacterMetrics(), 'memoryCount')).toMatchObject({
- id: 'memoryCount', label: 'Memories', unit: 'count', hint: 'Captured in Brain',
+ id: 'memoryCount', label: 'Memories', unit: 'count', hint: 'Active memories across PortOS',
});
});