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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): stop fallback context budget loop from appending empty stub headers
[._.]/ Adam Eivy0c02a0128725
diff --git a/server/services/digital-twin-avatar-bio.js b/server/services/digital-twin-avatar-bio.jsindex ce4ca05441..78af8b012b 100644--- a/server/services/digital-twin-avatar-bio.js+++ b/server/services/digital-twin-avatar-bio.js@@ -72,6 +72,11 @@ function buildFallbackSourceContext(sectionLines, sourceDocuments) {const source = sourceDocuments[filename]?.trim();if (!source || remaining <= 0) continue;const content = trimContextToBudget(source, remaining);+ // trimContextToBudget returns '' once the remaining budget can't even fit+ // its own truncation marker — treat that as the budget being exhausted so+ // the rest of the loop stops appending empty stub headers instead of+ // silently no-oping through every remaining filename.+ if (!content) { remaining = 0; continue; }remaining -= content.length;sourceBlocks.push(`### ${filename}\n${content}`);}diff --git a/server/services/digital-twin-avatar-bio.test.js b/server/services/digital-twin-avatar-bio.test.jsindex 898c48e7c7..5dd89ca94b 100644--- a/server/services/digital-twin-avatar-bio.test.js+++ b/server/services/digital-twin-avatar-bio.test.js@@ -251,6 +251,28 @@ describe('polishAvatarBio', () => {expect(prompt).not.toContain('### VALUES.md');});+ it('stops filling the fallback budget once it cannot even fit a truncation marker, instead of appending empty stub headers', async () => {+ // A near-budget-exhausting first document leaves a small positive `remaining`+ // (20 chars) that is still > 0 but below trimContextToBudget's own truncation+ // marker length (44 chars) — regression coverage for the case where that+ // returns '' and the loop must treat the budget as exhausted rather than+ // looping through every remaining filename appending an empty '### file' block.+ DOCS['TECHNICAL.md'] = `# Working Notes\n${'x'.repeat(11963)}`; // trims to exactly 11,980 chars+ DOCS['CREATIVE.md'] = '# Creative Notes\nMakes interactive worlds.';+ DOCS['COGNITIVE.md'] = '# Thinking Notes\nReasons from evidence.';+ getProviderById.mockResolvedValue({ id: 'x', enabled: true });+ callProviderAI.mockResolvedValue({+ text: '## Who I Am\nI am Ada.\n## How I Speak\nDirectly.\n## What I Know\nSystems.',+ });++ await polishAvatarBio({ providerId: 'x', model: 'm' });++ const prompt = callProviderAI.mock.calls[0][2];+ expect(prompt).toContain('### TECHNICAL.md');+ expect(prompt).not.toContain('### CREATIVE.md');+ expect(prompt).not.toContain('### COGNITIVE.md');+ });+it('never sends a disabled document through the raw Markdown fallback', async () => {DOCS['TECHNICAL.md'] = '# Private Notes\nDo not share this technical detail.';DOCS['CREATIVE.md'] = '# Creative Notes\nMakes interactive worlds.';