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

feat([issue-2673]): age-based character level replaces XP leveling

[._.]/ Adam Eivy602136d77140
diff --git a/client/src/components/city/CityXpBadge.jsx b/client/src/components/city/CityXpBadge.jsx
index 47ab8ee72e..7b3076624a 100644
--- a/client/src/components/city/CityXpBadge.jsx
+++ b/client/src/components/city/CityXpBadge.jsx
@@ -1,18 +1,19 @@
import { useState, useEffect, useRef, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
-import { computeXpView, diffXp } from '../../utils/characterXp';
+import { computeAgeView, diffXp } from '../../utils/characterXp';
-// CyberCity character XP HUD badge (roadmap 2.11). A compact floating panel showing the
-// current level + an XP progress bar toward the next level (and HP when known). Since
-// there's no XP-gain socket event, useCityData polls the character on an interval; this
-// component diffs successive snapshots and fires a transient flash on XP gain — a louder,
-// longer celebratory flash on level-up.
+// CyberCity character HUD badge (roadmap 2.11; reframed in #2673). A compact floating panel
+// showing the current **age-based level** (life experience = age) and a progress bar =
+// fractional part of the current year of life (progress toward the next birthday), plus HP
+// when known. useCityData polls the character on an interval; this component still diffs
+// successive snapshots and fires a transient flash on XP gain (xp survives as a cumulative
+// stat) — a louder, longer celebratory flash when the level ticks up (a birthday).
//
// Animations are self-contained (transient state + inline transition) so the component
// stays standalone and doesn't depend on global keyframes.
export default function CityXpBadge({ character }) {
const navigate = useNavigate();
- const view = useMemo(() => computeXpView(character), [character]);
+ const view = useMemo(() => computeAgeView(character), [character]);
const prevCharRef = useRef(null);
// burst.kind: null | 'gain' | 'levelup' — drives the flash overlay; burst.seq forces a
@@ -47,6 +48,9 @@ export default function CityXpBadge({ character }) {
const gaining = burst.kind !== null;
const barColor = leveling ? '#f59e0b' : '#06b6d4';
const pct = Math.round(view.progress * 100);
+ // No birthDate set → level is null; show a prompt instead of NaN. The badge still links
+ // to /character where the birth date can be set (Slice 5 owns the inline prompt UI).
+ const levelLabel = view.hasBirthDate ? `LV ${view.level}` : 'LV —';
return (
<div className="absolute bottom-16 right-3 pointer-events-auto">
@@ -82,11 +86,8 @@ export default function CityXpBadge({ character }) {
className={`font-pixel text-base tracking-wider ${leveling ? 'text-amber-300' : 'text-cyan-300'}`}
style={{ textShadow: leveling ? '0 0 10px rgba(245,158,11,0.7)' : '0 0 8px rgba(6,182,212,0.5)' }}
>
- LV {view.level}
+ {levelLabel}
</span>
- {view.atMax && (
- <span className="font-pixel text-[8px] text-amber-400/80 tracking-wider">MAX</span>
- )}
</div>
{gaining && burst.gained > 0 && (
<span
@@ -98,12 +99,12 @@ export default function CityXpBadge({ character }) {
)}
</div>
- {/* XP progress bar toward next level */}
+ {/* Progress bar toward the next birthday (fractional part of the current year) */}
<div className="relative mt-1.5 w-full h-1.5 bg-gray-800/70 rounded-full overflow-hidden">
<div
className="h-full rounded-full transition-all duration-700"
style={{
- width: `${view.atMax ? 100 : pct}%`,
+ width: `${pct}%`,
backgroundColor: barColor,
boxShadow: `0 0 6px ${barColor}`,
}}
@@ -112,7 +113,7 @@ export default function CityXpBadge({ character }) {
<div className="relative flex items-center justify-between mt-1">
<span className="font-pixel text-[8px] text-gray-500 tracking-wider">
- {view.atMax ? 'MAX LEVEL' : `${view.xpIntoLevel}/${view.xpForNextLevel} XP`}
+ {view.hasBirthDate ? `${pct}% TO NEXT` : 'SET BIRTH DATE'}
</span>
{view.hp != null && view.maxHp != null && (
<span
diff --git a/client/src/utils/README.md b/client/src/utils/README.md
index 7276681a52..83cc621750 100644
--- a/client/src/utils/README.md
+++ b/client/src/utils/README.md
@@ -57,7 +57,7 @@ grep -i "what you want to do" client/src/utils/README.md
| Module | Purpose |
|---|---|
-| `characterXp` | Avatar XP/level math: `levelFromXP`, `computeXpView`, `diffXp`, and the XP threshold table. |
+| `characterXp` | Character HUD badge math: `computeAgeView` (age-based level + progress to next birthday), plus legacy XP helpers `levelFromXP`, `computeXpView`, `diffXp` and the XP threshold table. |
## CyberCity — scene compute helpers
diff --git a/client/src/utils/characterXp.js b/client/src/utils/characterXp.js
index 9a98937630..e91c46b3f4 100644
--- a/client/src/utils/characterXp.js
+++ b/client/src/utils/characterXp.js
@@ -1,8 +1,11 @@
-// Pure, deterministic helpers for CyberCity's character XP HUD badge (roadmap 2.11):
-// given the D&D-style character sheet from GET /api/character, compute a view-model
-// for the floating level/XP badge (current level, progress toward the next level) and
-// detect XP gains / level-ups by diffing two successive character snapshots. No React
-// imports so the math is unit-testable (mirrors cityTaskQueue.js).
+// Pure, deterministic helpers for CyberCity's character HUD badge (roadmap 2.11): given the
+// character sheet from GET /api/character, compute the badge view-model and detect XP gains
+// by diffing two successive snapshots. No React imports so the math is unit-testable.
+//
+// As of #2673 the badge shows an **age-based level** (`computeAgeView`) — level = years lived
+// — with a progress bar toward the next birthday. The legacy XP-threshold helpers below
+// (`levelFromXP`, `computeXpView`, `XP_THRESHOLDS`) are retained for `cityArtifacts` and the
+// D&D-style `/character` page; the badge no longer uses them.
// MIRRORS the server constant `XP_THRESHOLDS` in server/services/character.js — index i
// is the cumulative XP required to reach level i+1. Keep these two arrays in sync: if the
@@ -59,6 +62,40 @@ export function computeXpView(character) {
};
}
+// Age-based level view-model for the CyberCity badge (#2673, epic #2672). The Character's
+// level is now life experience = age: `level = floor(ageYears)`, derived server-side from
+// the canonical birthDate. The badge shows that age level and a progress bar = fractional
+// part of the current year of life (progress toward the next birthday). Tolerates a missing
+// character / unset birthDate (server sends `level: null`, `ageYears: null`) by returning a
+// zeroed view with `hasBirthDate: false` and never NaNs.
+export function computeAgeView(character) {
+ const ageYears = Number.isFinite(character?.ageYears) ? character.ageYears : null;
+ // Prefer the server-derived level; fall back to flooring ageYears if only that came through.
+ const level = Number.isFinite(character?.level)
+ ? Math.floor(character.level)
+ : (ageYears != null ? Math.floor(ageYears) : null);
+ const hasBirthDate = level != null;
+
+ // Fraction through the current year of life = progress toward the next birthday.
+ const progress = (hasBirthDate && ageYears != null)
+ ? Math.min(1, Math.max(0, ageYears - Math.floor(ageYears)))
+ : 0;
+
+ const xp = Number.isFinite(character?.xp) ? Math.max(0, character.xp) : 0;
+
+ return {
+ level,
+ ageYears,
+ hasBirthDate,
+ progress,
+ // Rough countdown to next birthday for the badge caption; null when age is unknown.
+ daysToNextBirthday: hasBirthDate ? Math.max(0, Math.ceil((1 - progress) * 365.25)) : null,
+ xp,
+ hp: Number.isFinite(character?.hp) ? character.hp : null,
+ maxHp: Number.isFinite(character?.maxHp) ? character.maxHp : null,
+ };
+}
+
// Compare two character snapshots to detect a fresh XP gain / level-up so the badge can
// fire a transient burst. Tolerates null on either side (first poll has no prev). `gained`
// is clamped to >= 0 so a manual XP reset (xp dropping) never reports a negative burst.
diff --git a/client/src/utils/characterXp.test.js b/client/src/utils/characterXp.test.js
index abf6315d73..f959a311d3 100644
--- a/client/src/utils/characterXp.test.js
+++ b/client/src/utils/characterXp.test.js
@@ -4,6 +4,7 @@ import {
MAX_LEVEL,
levelFromXP,
computeXpView,
+ computeAgeView,
diffXp,
} from './characterXp';
@@ -96,6 +97,55 @@ describe('computeXpView', () => {
});
});
+describe('computeAgeView', () => {
+ it('derives the age level and progress toward the next birthday', () => {
+ const vm = computeAgeView({ level: 42, ageYears: 42.5, xp: 1000, hp: 12, maxHp: 15 });
+ expect(vm.level).toBe(42);
+ expect(vm.hasBirthDate).toBe(true);
+ expect(vm.progress).toBeCloseTo(0.5);
+ expect(vm.xp).toBe(1000);
+ expect(vm.hp).toBe(12);
+ expect(vm.maxHp).toBe(15);
+ expect(Number.isNaN(vm.progress)).toBe(false);
+ });
+
+ it('floors ageYears for level when only ageYears is present', () => {
+ const vm = computeAgeView({ ageYears: 30.9, xp: 0 });
+ expect(vm.level).toBe(30);
+ expect(vm.progress).toBeCloseTo(0.9);
+ expect(vm.hasBirthDate).toBe(true);
+ });
+
+ it('is 0 progress exactly on a birthday', () => {
+ const vm = computeAgeView({ level: 40, ageYears: 40 });
+ expect(vm.level).toBe(40);
+ expect(vm.progress).toBe(0);
+ });
+
+ it('returns a safe no-birthDate view (null level, no NaN)', () => {
+ for (const input of [null, undefined, {}, { level: null, ageYears: null, xp: 500 }]) {
+ const vm = computeAgeView(input);
+ expect(vm.level).toBeNull();
+ expect(vm.hasBirthDate).toBe(false);
+ expect(vm.progress).toBe(0);
+ expect(vm.daysToNextBirthday).toBeNull();
+ expect(Number.isNaN(vm.progress)).toBe(false);
+ }
+ });
+
+ it('carries xp through as a stat while level is null (no birthDate)', () => {
+ const vm = computeAgeView({ level: null, ageYears: null, xp: 777 });
+ expect(vm.xp).toBe(777);
+ expect(vm.level).toBeNull();
+ });
+
+ it('computes a bounded days-to-next-birthday countdown', () => {
+ const vm = computeAgeView({ level: 25, ageYears: 25.0 });
+ expect(vm.daysToNextBirthday).toBeGreaterThan(360);
+ expect(vm.daysToNextBirthday).toBeLessThanOrEqual(366);
+ });
+});
+
describe('diffXp', () => {
it('reports a gain when XP increased without a level change', () => {
const d = diffXp({ xp: 100, level: 1 }, { xp: 250, level: 1 });
diff --git a/server/services/character.js b/server/services/character.js
index 793d5a3d01..4d78bc97d3 100644
--- a/server/services/character.js
+++ b/server/services/character.js
@@ -1,6 +1,11 @@
/**
* Character Sheet Service
- * D&D 5e-style character tracking XP, HP, level, damage, rests, and events.
+ *
+ * The Character's `level` is **life experience = age**: each year lived is a level
+ * (`level = Math.floor(ageYears)`), derived on read from the canonical `birthDate`
+ * (see #2673, epic #2672). `xp` survives only as a cumulative stat — it no longer
+ * drives level. HP/damage/rest mechanics are retained for backward-compat with a
+ * flat maxHp (no longer scaled off level).
*/
import crypto from 'crypto';
@@ -8,26 +13,33 @@ import path from 'path';
import { atomicWrite, ensureDir, readJSONFile, PATHS } from '../lib/fileUtils.js';
import * as jiraService from './jira.js';
import * as cosService from './cos.js';
+import { getBirthDate } from './meatspace.js';
const CHARACTER_FILE = path.join(PATHS.data, 'character.json');
-const BASE_HP = 10;
-const HP_PER_LEVEL = 5;
+// HP is no longer scaled off level (level is now age, which would balloon maxHp). The
+// damage/rest mechanics survive for backward-compat against a flat maxHp.
+const DEFAULT_MAX_HP = 15;
-const XP_THRESHOLDS = [
- 0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000,
- 85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000, 305000, 355000
-];
+const MS_PER_YEAR = 365.25 * 24 * 60 * 60 * 1000;
-function getLevelFromXP(xp) {
- for (let i = XP_THRESHOLDS.length - 1; i >= 0; i--) {
- if (xp >= XP_THRESHOLDS[i]) return i + 1;
- }
- return 1;
+// Derived fields getCharacter() attaches on read; they are stripped before persisting so a
+// stale age-level never lands on disk or in the federated snapshot.
+const DERIVED_FIELDS = ['level', 'ageYears'];
+
+// Pure: fractional years lived since birthDate, or null when birthDate is unset/invalid.
+export function ageYearsFromBirthDate(birthDate, now = new Date()) {
+ if (!birthDate) return null;
+ const birth = new Date(birthDate);
+ if (Number.isNaN(birth.getTime())) return null;
+ const years = (now.getTime() - birth.getTime()) / MS_PER_YEAR;
+ if (!Number.isFinite(years) || years < 0) return null;
+ return Math.round(years * 100) / 100;
}
-function getMaxHP(level) {
- return BASE_HP + (level * HP_PER_LEVEL);
+// Pure: age-based level = whole years lived. null when age is unknown.
+export function levelFromAge(ageYears) {
+ return Number.isFinite(ageYears) ? Math.floor(ageYears) : null;
}
function createEvent(type, description, overrides = {}) {
@@ -45,27 +57,14 @@ function createEvent(type, description, overrides = {}) {
};
}
-function recalcLevel(character) {
- const oldLevel = character.level;
- character.level = getLevelFromXP(character.xp);
- character.maxHp = getMaxHP(character.level);
- const leveledUp = character.level > oldLevel;
- if (leveledUp) {
- character.hp = character.maxHp;
- console.log(`🎉 Level up! ${oldLevel} -> ${character.level}`);
- }
- return leveledUp;
-}
-
export function createDefaultCharacter() {
const now = new Date().toISOString();
return {
name: 'Adventurer',
class: 'Developer',
xp: 0,
- hp: 15,
- maxHp: 15,
- level: 1,
+ hp: DEFAULT_MAX_HP,
+ maxHp: DEFAULT_MAX_HP,
events: [],
syncedJiraTickets: [],
syncedTaskIds: [],
@@ -74,19 +73,38 @@ export function createDefaultCharacter() {
};
}
-export async function getCharacter() {
+// Read the persisted record (no derived fields), creating the default on first access.
+// Mutating paths build on this so they never re-persist a derived age-level.
+async function loadRawCharacter() {
const data = await readJSONFile(CHARACTER_FILE, null);
if (data) return data;
const character = createDefaultCharacter();
- await saveCharacter(character);
+ await ensureDir(PATHS.data);
+ await atomicWrite(CHARACTER_FILE, character);
return character;
}
+// Attach the age-derived read-only fields (`ageYears`, `level`) to a raw record. `level` is
+// null when no birthDate is set, so callers can render a "set your birth date" prompt.
+async function enrichCharacter(raw) {
+ const { birthDate } = await getBirthDate().catch(() => ({ birthDate: null }));
+ const ageYears = ageYearsFromBirthDate(birthDate);
+ return { ...raw, ageYears, level: levelFromAge(ageYears) };
+}
+
+export async function getCharacter() {
+ return enrichCharacter(await loadRawCharacter());
+}
+
export async function saveCharacter(data) {
await ensureDir(PATHS.data);
- data.updatedAt = new Date().toISOString();
- await atomicWrite(CHARACTER_FILE, data);
- return data;
+ // Never persist derived fields — level is age-derived on read (#2673). Stripping them
+ // keeps a stale level off disk and out of the federated character snapshot.
+ const persist = { ...data };
+ for (const field of DERIVED_FIELDS) delete persist[field];
+ persist.updatedAt = new Date().toISOString();
+ await atomicWrite(CHARACTER_FILE, persist);
+ return enrichCharacter(persist);
}
// Persist a freshly-rendered avatar path onto the singleton character. Lets the
@@ -120,13 +138,13 @@ export function rollDice(notation) {
export async function addXP(amount, source, description) {
const character = await getCharacter();
character.xp += amount;
- const leveledUp = recalcLevel(character);
character.events.push(createEvent('xp', description || `Gained ${amount} XP from ${source}`, { xp: amount }));
- await saveCharacter(character);
+ const saved = await saveCharacter(character);
- console.log(`✨ +${amount} XP (${source}) — total ${character.xp} XP, level ${character.level}`);
- return { character, leveledUp, newLevel: character.level };
+ console.log(`✨ +${amount} XP (${source}) — total ${saved.xp} XP, level ${saved.level ?? '—'}`);
+ // xp no longer drives level (level is age-derived, #2673) — an XP gain never levels up.
+ return { character: saved, leveledUp: false, newLevel: saved.level };
}
export async function takeDamage(diceNotation, description) {
@@ -176,8 +194,6 @@ export async function addEvent(event) {
character.hp = Math.max(0, character.hp - roll.total);
}
- const leveledUp = recalcLevel(character);
-
const logEntry = createEvent('custom', event.description, {
xp: event.xp || 0,
damage: roll ? roll.total : 0,
@@ -186,10 +202,10 @@ export async function addEvent(event) {
});
character.events.push(logEntry);
- await saveCharacter(character);
+ const saved = await saveCharacter(character);
console.log(`📝 Custom event: ${event.description}`);
- return { character, event: logEntry, leveledUp };
+ return { character: saved, event: logEntry, leveledUp: false };
}
const delay = ms => new Promise(r => setTimeout(r, ms));
@@ -234,11 +250,10 @@ export async function syncJiraXP() {
}
}
- const leveledUp = recalcLevel(character);
- await saveCharacter(character);
+ const saved = await saveCharacter(character);
console.log(`🎫 Synced ${ticketCount} JIRA tickets for ${totalXP} XP`);
- return { character, ticketCount, totalXP, leveledUp };
+ return { character: saved, ticketCount, totalXP, leveledUp: false };
}
export async function syncTaskXP() {
@@ -260,9 +275,8 @@ export async function syncTaskXP() {
character.events.push(createEvent('xp', `Task: ${task.title || task.description || task.id}`, { xp }));
}
- const leveledUp = recalcLevel(character);
- await saveCharacter(character);
+ const saved = await saveCharacter(character);
console.log(`✅ Synced ${taskCount} tasks for ${totalXP} XP`);
- return { character, taskCount, totalXP, leveledUp };
+ return { character: saved, taskCount, totalXP, leveledUp: false };
}
diff --git a/server/services/character.test.js b/server/services/character.test.js
index b029eaa490..c0d6950c9f 100644
--- a/server/services/character.test.js
+++ b/server/services/character.test.js
@@ -1,8 +1,9 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
// In-memory backing for the character.json read/write so the test exercises the
-// real read-modify-save path without touching disk.
-const store = vi.hoisted(() => ({ value: null }));
+// real read-modify-save path without touching disk. `birthDate` drives the mocked
+// meatspace accessor so age-based level derivation is deterministic.
+const store = vi.hoisted(() => ({ value: null, birthDate: null }));
vi.mock('../lib/fileUtils.js', () => ({
PATHS: { data: '/tmp/portos-test-data' },
@@ -19,10 +20,14 @@ vi.mock('../lib/fileUtils.js', () => ({
}),
}));
-// character.js eagerly imports the jira/cos services at module load; stub them
-// so the unit under test loads without their dependency graphs.
+// character.js eagerly imports the jira/cos/meatspace services at module load; stub them
+// so the unit under test loads without their dependency graphs. meatspace supplies the
+// canonical birthDate that age-based level derives from (#2673).
vi.mock('./jira.js', () => ({}));
vi.mock('./cos.js', () => ({}));
+vi.mock('./meatspace.js', () => ({
+ getBirthDate: vi.fn(async () => ({ birthDate: store.birthDate })),
+}));
vi.mock('fs/promises', () => ({
writeFile: vi.fn(async (_path, contents) => {
@@ -32,9 +37,102 @@ vi.mock('fs/promises', () => ({
import * as characterService from './character.js';
+describe('ageYearsFromBirthDate', () => {
+ it('returns fractional years lived for a valid birthDate', () => {
+ const now = new Date('2026-07-01T00:00:00Z');
+ const age = characterService.ageYearsFromBirthDate('1984-01-01T00:00:00Z', now);
+ expect(age).toBeGreaterThan(42);
+ expect(age).toBeLessThan(43);
+ });
+
+ it('returns null for unset / invalid / future birthDate', () => {
+ const now = new Date('2026-07-01T00:00:00Z');
+ expect(characterService.ageYearsFromBirthDate(null, now)).toBeNull();
+ expect(characterService.ageYearsFromBirthDate('', now)).toBeNull();
+ expect(characterService.ageYearsFromBirthDate('not-a-date', now)).toBeNull();
+ expect(characterService.ageYearsFromBirthDate('2030-01-01', now)).toBeNull();
+ });
+});
+
+describe('levelFromAge', () => {
+ it('floors age years to a level', () => {
+ expect(characterService.levelFromAge(42.9)).toBe(42);
+ expect(characterService.levelFromAge(0.4)).toBe(0);
+ });
+ it('returns null when age is null / NaN', () => {
+ expect(characterService.levelFromAge(null)).toBeNull();
+ expect(characterService.levelFromAge(NaN)).toBeNull();
+ });
+});
+
+describe('getCharacter age-based level', () => {
+ beforeEach(() => {
+ store.value = { name: 'Gandalf', class: 'Wizard', xp: 5000, level: 3, hp: 15, maxHp: 15 };
+ store.birthDate = null;
+ });
+
+ it('derives level = floor(ageYears) from the canonical birthDate, ignoring stored xp/level', async () => {
+ // ~42 years before today → level 42, regardless of the persisted level: 3 / xp: 5000.
+ const birth = new Date();
+ birth.setFullYear(birth.getFullYear() - 42);
+ birth.setDate(birth.getDate() - 30); // safely past the birthday so age is >= 42
+ store.birthDate = birth.toISOString();
+
+ const char = await characterService.getCharacter();
+ expect(char.level).toBe(42);
+ expect(char.ageYears).toBeGreaterThanOrEqual(42);
+ expect(char.xp).toBe(5000); // xp survives as a stat
+ });
+
+ it('returns level = null when no birthDate is set', async () => {
+ store.birthDate = null;
+ const char = await characterService.getCharacter();
+ expect(char.level).toBeNull();
+ expect(char.ageYears).toBeNull();
+ });
+
+ it('loads a legacy character.json (stored xp/level) without error', async () => {
+ store.value = { name: 'Legacy', class: 'Dev', xp: 12345, level: 7, hp: 20, maxHp: 20 };
+ store.birthDate = null;
+ const char = await characterService.getCharacter();
+ expect(char.name).toBe('Legacy');
+ expect(char.level).toBeNull(); // no longer XP-derived
+ expect(char.xp).toBe(12345);
+ });
+});
+
+describe('addXP decoupled from level', () => {
+ beforeEach(() => {
+ store.value = { name: 'Gandalf', class: 'Wizard', xp: 0, hp: 15, maxHp: 15, events: [] };
+ store.birthDate = null;
+ });
+
+ it('accumulates xp but never levels up (level is age-derived)', async () => {
+ const result = await characterService.addXP(100000, 'test', 'big gain');
+ expect(result.leveledUp).toBe(false);
+ expect(result.character.xp).toBe(100000);
+ // No birthDate → derived level stays null; xp does not resurrect a level.
+ expect(result.character.level).toBeNull();
+ });
+
+ it('does not persist a derived level onto disk', async () => {
+ const birth = new Date();
+ birth.setFullYear(birth.getFullYear() - 30);
+ birth.setDate(birth.getDate() - 30);
+ store.birthDate = birth.toISOString();
+
+ await characterService.addXP(50, 'test', 'gain');
+ // The enriched read carries level, but the persisted record must not.
+ expect(store.value.level).toBeUndefined();
+ expect(store.value.ageYears).toBeUndefined();
+ expect(store.value.xp).toBe(50);
+ });
+});
+
describe('character setAvatar', () => {
beforeEach(() => {
- store.value = { name: 'Gandalf', class: 'Wizard', avatarPath: null, xp: 0, level: 1 };
+ store.value = { name: 'Gandalf', class: 'Wizard', avatarPath: null, xp: 0 };
+ store.birthDate = null;
});
it('persists avatarPath onto the existing character and returns it', async () => {
diff --git a/server/services/dataSync.js b/server/services/dataSync.js
index b867a7165e..c407e5fa3f 100644
--- a/server/services/dataSync.js
+++ b/server/services/dataSync.js
@@ -306,12 +306,14 @@ async function applyCharacterRemote(remoteData) {
xp: Math.max(local.xp || 0, remoteData.xp || 0),
hp: scalarSource.hp,
maxHp: scalarSource.maxHp,
- level: Math.max(local.level || 1, remoteData.level || 1),
+ // `level` is age-derived on read (#2673), not persisted — never merge a stale peer level.
events: mergedEvents,
syncedJiraTickets: mergedTickets,
syncedTaskIds: mergedTasks,
updatedAt: remoteTs > localTs ? remoteTs : localTs
};
+ // Drop any legacy persisted `level` (carried through `...local`) — it's derived on read now.
+ delete merged.level;
if (eventsChanged || remoteTs > localTs) {
await atomicWrite(CHARACTER_FILE, merged);