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: rank the Character goals card by fresh urgency, not the stale persisted value (#2675)

[._.]/ Adam Eivy0c69c6b9f2cb
diff --git a/client/src/components/character/GoalsCard.jsx b/client/src/components/character/GoalsCard.jsx
index 8f304d6b69..09f1df4b91 100644
--- a/client/src/components/character/GoalsCard.jsx
+++ b/client/src/components/character/GoalsCard.jsx
@@ -1,7 +1,7 @@
import { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { Target, ArrowRight } from 'lucide-react';
-import { getGoals } from '../../services/api';
+import { getGoalsTree } from '../../services/api';
import BrailleSpinner from '../BrailleSpinner';
// The human's real life-goals, surfaced read-only on the Character sheet (#2675) so the sheet
@@ -75,14 +75,21 @@ export default function GoalsCard() {
useEffect(() => {
let cancelled = false;
+ // The TREE endpoint, not the flat one: `urgency` is only *persisted* when a goal is
+ // written or a birth date is set, and it decays from `timeHorizons.yearsRemaining` — so
+ // the stored value drifts stale with the mere passage of time, and `getGoals()` hands it
+ // back unrecomputed. `getGoalsTree().flat` re-derives urgency from current longevity, and
+ // is the exact source /goals ranks by, so the sheet can never disagree with the page it
+ // links to. (Enriching the flat endpoint instead would change a shared API's semantics.)
+ //
// silent: this card owns its own error UI (the message below), so letting request() toast
// as well would surface the same failure twice.
- getGoals({ silent: true })
+ getGoalsTree({ silent: true })
.then((data) => {
if (cancelled) return;
// Array.isArray, not truthiness: a genuinely zero-goal install must reach the empty
// state, while a malformed payload must reach the error state.
- if (Array.isArray(data?.goals)) setState({ status: 'ready', goals: data.goals });
+ if (Array.isArray(data?.flat)) setState({ status: 'ready', goals: data.flat });
else setState({ status: 'error', goals: [] });
})
.catch(() => {
diff --git a/client/src/components/character/GoalsCard.test.jsx b/client/src/components/character/GoalsCard.test.jsx
index a75cfd6a9d..b604be3a03 100644
--- a/client/src/components/character/GoalsCard.test.jsx
+++ b/client/src/components/character/GoalsCard.test.jsx
@@ -8,10 +8,10 @@ import { MemoryRouter } from 'react-router-dom';
//
// All fixture goals use obviously-fake placeholder titles — never real goal data.
-const getGoals = vi.fn();
+const getGoalsTree = vi.fn();
vi.mock('../../services/api', () => ({
- getGoals: (...a) => getGoals(...a),
+ getGoalsTree: (...a) => getGoalsTree(...a),
}));
import GoalsCard, { selectTopGoals, progressPct, GOALS_PATH } from './GoalsCard';
@@ -28,7 +28,7 @@ const goal = (overrides = {}) => ({
// Scoped to the card's own region: the sheet renders other percentages, and a page-wide
// query would let a broken row pass.
const renderCard = async (goals) => {
- getGoals.mockResolvedValue(goals === undefined ? {} : { goals });
+ getGoalsTree.mockResolvedValue(goals === undefined ? {} : { flat: goals });
render(<MemoryRouter><GoalsCard /></MemoryRouter>);
const region = await screen.findByRole('region', { name: 'Life Goals' });
await waitFor(() => expect(within(region).queryByText(/Loading goals/)).not.toBeInTheDocument());
@@ -145,13 +145,18 @@ describe('GoalsCard — populated', () => {
.toBeInTheDocument();
});
- it('reads goals from the service without ever writing them back', async () => {
+ it('reads goals once from the tree endpoint, silently, and never writes them back', async () => {
await renderCard([goal()]);
// Surface, don't duplicate: a read-only mirror calls the read endpoint exactly once and
// owns no write path at all.
- expect(getGoals).toHaveBeenCalledTimes(1);
+ //
+ // The TREE endpoint specifically: getGoals() hands back whatever urgency was last
+ // WRITTEN, which decays as yearsRemaining falls, so ranking off it would let the sheet
+ // order goals differently from the /goals page it links to. Only getGoalsTree()
+ // re-derives urgency from current longevity.
+ expect(getGoalsTree).toHaveBeenCalledTimes(1);
// silent — the card renders its own error message, so request() must not toast it too.
- expect(getGoals).toHaveBeenCalledWith({ silent: true });
+ expect(getGoalsTree).toHaveBeenCalledWith({ silent: true });
});
});
@@ -178,7 +183,7 @@ describe('GoalsCard — empty', () => {
describe('GoalsCard — error', () => {
it('says the goals could not be loaded rather than claiming there are none', async () => {
// The sentinel rule: "we could not read this" must not read as "you have never done this".
- getGoals.mockRejectedValue(new Error('network'));
+ getGoalsTree.mockRejectedValue(new Error('network'));
render(<MemoryRouter><GoalsCard /></MemoryRouter>);
const card = within(await screen.findByRole('region', { name: 'Life Goals' }));
diff --git a/client/src/pages/CharacterSheet.a11y.test.jsx b/client/src/pages/CharacterSheet.a11y.test.jsx
index 54f14aa22e..364d5d69b2 100644
--- a/client/src/pages/CharacterSheet.a11y.test.jsx
+++ b/client/src/pages/CharacterSheet.a11y.test.jsx
@@ -13,11 +13,14 @@ const put = vi.fn();
vi.mock('../services/api', () => ({
default: { get: (...a) => get(...a), post: vi.fn(), put: (...a) => put(...a) },
generateAvatar: vi.fn(() => Promise.resolve({})),
- // The sheet's GoalsCard fetches goals itself (#2675); stubbed empty so this suite stays
- // scoped to the name-edit control.
- getGoals: vi.fn(() => Promise.resolve({ goals: [] })),
}));
+// GoalsCard (#2675) owns a mount-effect fetch of its own. Stubbed out rather than mocked at
+// the api layer so this suite stays scoped to the name-edit control AND settles
+// synchronously — a live child would resolve its promise after the sync test body and trip
+// the act(...) guard in src/test/setup.js.
+vi.mock('../components/character/GoalsCard', () => ({ default: () => null }));
+
vi.mock('../services/socket', () => ({
default: { on: vi.fn(), off: vi.fn(), emit: vi.fn() },
}));
diff --git a/client/src/pages/CharacterSheet.metrics.test.jsx b/client/src/pages/CharacterSheet.metrics.test.jsx
index 98961c64fe..49b70267ff 100644
--- a/client/src/pages/CharacterSheet.metrics.test.jsx
+++ b/client/src/pages/CharacterSheet.metrics.test.jsx
@@ -12,12 +12,15 @@ const get = vi.fn();
vi.mock('../services/api', () => ({
default: { get: (...a) => get(...a), post: vi.fn(), put: vi.fn() },
generateAvatar: vi.fn(() => Promise.resolve({})),
- // The sheet's GoalsCard fetches goals itself (#2675); stubbed empty so this suite stays
- // scoped to the metrics grid. GoalsCard's own states are covered next to it, in
- // components/character/GoalsCard.test.jsx.
- getGoals: vi.fn(() => Promise.resolve({ goals: [] })),
}));
+// GoalsCard (#2675) owns a mount-effect fetch of its own. Stubbed out rather than mocked at
+// the api layer so this suite stays scoped to the metrics grid AND settles synchronously —
+// a live child would resolve its promise after the sync test body and trip the act(...)
+// guard in src/test/setup.js. Its own states are covered next to it, in
+// components/character/GoalsCard.test.jsx.
+vi.mock('../components/character/GoalsCard', () => ({ default: () => null }));
+
vi.mock('../services/socket', () => ({
default: { on: vi.fn(), off: vi.fn(), emit: vi.fn() },
}));
diff --git a/client/src/services/apiGoals.js b/client/src/services/apiGoals.js
index 3be011c636..756541a5e8 100644
--- a/client/src/services/apiGoals.js
+++ b/client/src/services/apiGoals.js
@@ -27,7 +27,7 @@ export const updateGoal = (id, data, options = {}) => request(`/digital-twin/ide
...options
});
export const deleteGoal = (id) => request(`/digital-twin/identity/goals/${id}`, { method: 'DELETE' });
-export const getGoalsTree = () => request('/digital-twin/identity/goals/tree');
+export const getGoalsTree = (options) => request('/digital-twin/identity/goals/tree', options);
export const addGoalMilestone = (goalId, data) => request(`/digital-twin/identity/goals/${goalId}/milestones`, {
method: 'POST',
body: JSON.stringify(data)