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: read an absent learning store as a fresh install, not a broken read (#2700)

[._.]/ Adam Eivy4aed6f3d7d40
diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.js b/server/services/autonomousJobs/layeredIntelligenceHooks.js
index c3e038c163..03167d67d4 100644
--- a/server/services/autonomousJobs/layeredIntelligenceHooks.js
+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.js
@@ -337,6 +337,15 @@ export async function buildTaskInput({ app } = {}) {
// `existingIssues` is passed as null on a FAILED tracker read: readIssues returns
// `[]` in that case, which would otherwise tell selfEval "you have filed nothing"
// and license a duplicate re-file off a blind read.
+ //
+ // Scope: `trackerReadFailed` is only ever set by the forge and jira branches. The
+ // `plan` branch cannot distinguish an unreadable PLAN.md from an absent one, so it
+ // reports `[]` either way — but for a plan tracker that is honest rather than
+ // blind: the downstream isProposalDuplicate guard reads the same empty list, so
+ // selfEval's "nothing is currently suppressed" correctly describes what filing
+ // will actually do. Do NOT "fix" this by marking a missing PLAN.md as a failed
+ // read: an app with no PLAN.md yet genuinely has nothing filed, and suppressing
+ // its proposals would park the loop on every such app permanently.
let selfEvalReport = ''
if (config.sources?.selfEval) {
selfEvalReport = computeSelfEvalSummary({
diff --git a/server/services/layeredIntelligence.js b/server/services/layeredIntelligence.js
index b0372a4e36..8fcf814f8e 100644
--- a/server/services/layeredIntelligence.js
+++ b/server/services/layeredIntelligence.js
@@ -731,6 +731,11 @@ export function computeSelfEvalSummary({
}
// --- Signal 3: is the LI machinery itself healthy? --------------------------
+ // Deliberately GLOBAL, not per-app: the learning store keys LI runs by task type
+ // alone, so this bucket aggregates the loop's runs across every app. That is the
+ // right scope for the question being asked — "is the LI machinery working?" is a
+ // property of the shared loop, not of the app it happens to be pointed at — and
+ // it mirrors the cosMetrics source, which is likewise install-wide.
let taskSignal = false;
let liDegraded = false;
if (!liTaskStats?.read) {
@@ -1159,7 +1164,15 @@ export async function gatherSources(app, config, { cosPath = PATHS.cos, trustShe
* "healthy loop with no history" (or vice versa) — the sentinel rule.
*/
export async function readLiTaskMetrics({ cosPath = PATHS.cos } = {}) {
- const learning = await readJSONFile(join(cosPath, 'learning.json'), null);
+ const file = join(cosPath, 'learning.json');
+ // An ABSENT store is a fresh install, not a broken read: learning.json is created
+ // lazily on the first recorded task outcome. readJSONFile returns its default for
+ // ENOENT, I/O errors, and parse failures ALIKE, so leaning on it alone would tell
+ // every fresh install "your learning store could not be read" when the truth is
+ // "nothing has run here yet" — the exact conflation this function exists to
+ // prevent, just inverted. Check existence first so the two stay distinct.
+ if (!existsSync(file)) return { read: true, metrics: null };
+ const learning = await readJSONFile(file, null);
const byTaskType = learning?.byTaskType;
if (!byTaskType || typeof byTaskType !== 'object' || Array.isArray(byTaskType)) {
return { read: false, metrics: null };
diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.js
index ea61f24277..8eb8dfa228 100644
--- a/server/services/layeredIntelligence.test.js
+++ b/server/services/layeredIntelligence.test.js
@@ -843,7 +843,14 @@ describe('readLiTaskMetrics (#2700)', () => {
beforeEach(async () => { dir = await mkdtemp(join(tmpdir(), 'lil-selfeval-')); });
afterEach(async () => { await rm(dir, { recursive: true, force: true }); });
- it('reports read:false when the learning store is missing', async () => {
+ it('treats an ABSENT store as a fresh install (read:true), not a broken read', async () => {
+ // learning.json is created lazily on the first recorded outcome — a fresh
+ // install must be told "no LI runs recorded yet", never "your store is broken".
+ expect(await readLiTaskMetrics({ cosPath: dir })).toEqual({ read: true, metrics: null });
+ });
+
+ it('reports read:false when the store exists but is unparseable', async () => {
+ await writeFile(join(dir, 'learning.json'), '{ not json');
expect(await readLiTaskMetrics({ cosPath: dir })).toEqual({ read: false, metrics: null });
});