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
fix: the self-improvement brief was silently dropped before the agent ever read it
[._.]/ Adam Eivyb3fc9bf2a186
diff --git a/server/services/pipeline/seriesAutopilot/selfImprove.js b/server/services/pipeline/seriesAutopilot/selfImprove.jsindex 5accf4ff0f..ae72fff222 100644--- a/server/services/pipeline/seriesAutopilot/selfImprove.js+++ b/server/services/pipeline/seriesAutopilot/selfImprove.js@@ -30,9 +30,12 @@* `approvalRequired: true`); the autonomy dial for this class of work is the* CoS approval queue, not a per-series checkbox.*- * The signal log is captured passively: `noteSignal` taps the same SSE frames- * the run already broadcasts (`session.js#broadcast`), so a new telemetry frame- * becomes diagnosable evidence with no extra instrumentation.+ * The signal log is captured passively: `state.js#noteSignal`, called from+ * `session.js#broadcast`, retains the same SSE frames the run already emits — so+ * a telemetry frame a future step adds becomes diagnosable evidence with no+ * extra instrumentation. It lives in `state.js` (the run-registry owner) rather+ * than here so this module can import the registry instead of the registry+ * importing the diagnosis.** PRIVACY: the diagnosis prompt asks for a defect report about PortOS's code and* prompts, explicitly NOT about the story — and `shapeDiagnosis` bounds every@@ -136,46 +139,47 @@ export function isFilable(diagnosis) {* Shape the CoS task for a filable diagnosis. Pure, so the dedup key and the* agent-facing brief are testable without a task store.*- * The FIRST LINE is the dedup key (cosTaskStore matches on it, lowercased,+ * `description` is ONE LINE, and that is a hard requirement, not a style choice:+ * `generateTasksMarkdown` writes the description verbatim into a single+ * `- [ ] #id | PRIORITY | <description>` row (only *metadata* values go through+ * `escapeNewlines`). A multi-line description therefore spills its tail into+ * TASKS.md as stray un-parsed lines AND is truncated to its first line on the+ * next read — silently dropping the entire brief, so the agent would receive a+ * defect report with no defect in it. The brief lives in `context`, which is+ * newline-escaped and round-trips intact.+ *+ * That one line is also the dedup key (cosTaskStore matches on it, lowercased,* scoped to the app), so it carries the area AND a slug of the diagnosis itself.* Area alone would be wrong in both directions: it is deliberately NOT* per-series (the defect lives in shared PortOS code, so one open task should* cover it however many series hit it), but keying on the bucket would cap* PortOS at one open task per area forever and silently discard the next,* different `editorial-check` defect — and a task that ends up `blocked` counts- * as a duplicate too, which would mute that area permanently.+ * as a duplicate too, which would mute that area permanently. The slug is the+ * kebab-cased title, so the row stays readable in TASKS.md.*/export function buildSelfImproveTask({ diagnosis, seriesId, seriesName, outcome, outcomeReason, counts }) {const slug = slugify(diagnosis.title);- const lines = [- `Pipeline self-improvement (${diagnosis.area}/${slug}) — Series Autopilot diagnosed a PortOS automation defect`,- '',- `**${diagnosis.title}**`,+ const brief = [+ `Series Autopilot diagnosed a PortOS automation defect: ${diagnosis.title}`,'',diagnosis.problem,'',`Proposed change: ${diagnosis.proposedChange}`,];- if (diagnosis.risks) lines.push('', `Risks / things to be careful of: ${diagnosis.risks}`);- lines.push(+ if (diagnosis.risks) brief.push('', `Risks / things to be careful of: ${diagnosis.risks}`);+ if (diagnosis.evidence.length) {+ brief.push('', 'Evidence from the run telemetry:', ...diagnosis.evidence.map((e) => `- ${e}`));+ }+ brief.push('',- `Diagnosed from an autopilot run that ended \`${outcome}\`${outcomeReason ? ` — ${outcomeReason}` : ''}.`,+ `Diagnosed from an autopilot run on series ${seriesId}${seriesName ? ` ("${seriesName}")` : ''} that ended \`${outcome}\`${outcomeReason ? ` — ${trimToClause(outcomeReason, 500)}` : ''}.`,+ `Signal counts: ${JSON.stringify(counts)}.`,'Confirm the defect in the code before changing anything: this brief is one LLM\'s read of a single run\'s telemetry, not a reproduction.',);- const context = JSON.stringify({- source: 'series-autopilot-self-improve',- seriesId,- seriesName,- outcome,- outcomeReason: trimToClause(outcomeReason, 500),- area: diagnosis.area,- confidence: diagnosis.confidence,- evidence: diagnosis.evidence,- signalCounts: counts,- }).slice(0, 4000);return {- description: lines.join('\n'),- context,+ description: `Pipeline self-improvement (${diagnosis.area}/${slug})`,+ context: brief.join('\n').slice(0, 4000),app: PORTOS_APP_ID,priority: 'MEDIUM',// Always isolated, always via a PR, always approval-gated — see the modulediff --git a/server/services/pipeline/seriesAutopilot/selfImprove.test.js b/server/services/pipeline/seriesAutopilot/selfImprove.test.jsindex ca2da89948..3933ebaf13 100644--- a/server/services/pipeline/seriesAutopilot/selfImprove.test.js+++ b/server/services/pipeline/seriesAutopilot/selfImprove.test.js@@ -199,32 +199,48 @@ describe('buildSelfImproveTask', () => {expect(task.prCompletion).toBe('review-then-merge');});+ it('keeps the description to ONE line so the brief is not silently dropped', () => {+ // generateTasksMarkdown writes the description verbatim into a single+ // "- [ ] #id | PRIORITY | <description>" row and only escapes newlines in+ // METADATA values. A multi-line description spills into TASKS.md as stray+ // lines and is truncated to its first line on the next read — the agent+ // would get a defect report with no defect in it.+ const task = build();+ expect(task.description).not.toContain('\n');+ // The brief itself rides `context`, which IS newline-escaped.+ expect(task.context).toContain(goodDiagnosis.title);+ expect(task.context).toContain(goodDiagnosis.problem);+ expect(task.context).toContain(goodDiagnosis.proposedChange);+ expect(task.context).toContain(goodDiagnosis.evidence[0]);+ });+it('keeps the dedup line stable per defect, not per series', () => {- const firstLine = (t) => t.description.split('\n')[0];const a = build();const b = build({ seriesId: 'series-2', seriesName: 'Another Series', outcome: 'error' });// The defect lives in shared PortOS code — one open task should cover it// however many series hit it, so cosTaskStore's first-line dedup must match.- expect(firstLine(a)).toBe(firstLine(b));- expect(firstLine(a)).toContain('editorial-check');+ expect(a.description).toBe(b.description);+ expect(a.description).toContain('editorial-check');// A different area is different work and must NOT collapse onto it...const otherArea = build({ diagnosis: shapeDiagnosis({ ...goodDiagnosis, area: 'runner' }) });- expect(firstLine(otherArea)).not.toBe(firstLine(a));+ expect(otherArea.description).not.toBe(a.description);// ...and neither must a DIFFERENT defect in the same area. Keying on the// bucket alone would cap PortOS at one open task per area forever and// silently discard every later diagnosis in it.const otherDefect = build({ diagnosis: shapeDiagnosis({ ...goodDiagnosis, title: 'Reverse outline is never refreshed before the checks' }) });- expect(firstLine(otherDefect)).not.toBe(firstLine(a));+ expect(otherDefect.description).not.toBe(a.description);});it('always awaits approval — an LLM diagnosis never dispatches a coding agent on its own', () => {expect(build().approvalRequired).toBe(true);});- it('carries the run provenance in context, not the manuscript', () => {- const ctx = JSON.parse(build().context);- expect(ctx).toMatchObject({ source: 'series-autopilot-self-improve', seriesId: 'series-1', outcome: 'paused', area: 'editorial-check' });- expect(ctx.evidence).toEqual(goodDiagnosis.evidence);+ it('carries the run provenance in the brief', () => {+ const ctx = build().context;+ expect(ctx).toContain('series-1');+ expect(ctx).toContain('Example Series');+ expect(ctx).toContain('paused');+ expect(ctx).toContain('editorialReview: ran out of rounds');});});diff --git a/server/services/pipeline/seriesAutopilot/session.js b/server/services/pipeline/seriesAutopilot/session.jsindex e4acc836f2..ccd36518ab 100644--- a/server/services/pipeline/seriesAutopilot/session.js+++ b/server/services/pipeline/seriesAutopilot/session.js@@ -63,7 +63,8 @@ export function broadcast(seriesId, payload) {// Retain the diagnosable frames for the opt-in self-improvement pass. A single// tap here (rather than instrumenting each step runner) means any telemetry// frame a future step emits is diagnosable evidence for free. No-op unless the- // run opted in — see selfImprove.js#noteSignal.+ // run opted in — see state.js#noteSignal (it lives with the run registry it+ // mutates, which is what keeps selfImprove.js out of this module's imports).noteSignal(run, payload);// Mirror every frame onto the in-process bus (CDO Phase 3, #2185) so a// server-side consumer (CD plan step) sees the same progress/pause/terminal