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([strip-stage-runhistory-from-list-payloads]): address codex review — keep listIssues default full-shape

[._.]/ Adam Eivyc8e8478b9d4f
diff --git a/server/routes/pipeline.js b/server/routes/pipeline.js
index 17b7f076e7..e5b3e8965d 100644
--- a/server/routes/pipeline.js
+++ b/server/routes/pipeline.js
@@ -881,11 +881,14 @@ router.get('/series/:id/issues', asyncHandler(async (req, res) => {
// confusing for the UI).
await seriesSvc.getSeries(req.params.id).catch((err) => { throw mapServiceError(err); });
const hasPagination = req.query.offset !== undefined || req.query.limit !== undefined;
+ // List endpoints strip per-stage runHistory; the UI never renders it on
+ // these views and a maxed-out issue can otherwise ship ~12MB of payload.
+ // Detail reads (`GET /issues/:id`) stay on the full shape.
if (hasPagination) {
const { offset, limit } = validateRequest(issuesListQuerySchema, req.query);
- res.json(await issuesSvc.listIssues({ seriesId: req.params.id, offset, limit, paginated: true }));
+ res.json(await issuesSvc.listIssues({ seriesId: req.params.id, offset, limit, paginated: true, withHistory: false }));
} else {
- res.json(await issuesSvc.listIssues({ seriesId: req.params.id }));
+ res.json(await issuesSvc.listIssues({ seriesId: req.params.id, withHistory: false }));
}
}));
@@ -1233,7 +1236,10 @@ router.get('/issues/recent', asyncHandler(async (req, res) => {
// via the route but clamps to 1 in the service). Pass through and let
// listRecentIssues coerce.
const [issues, series] = await Promise.all([
- issuesSvc.listRecentIssues({ limit: req.query.limit }),
+ // The route's projection below drops `stages` entirely, but pass
+ // withHistory: false anyway so the service stays light on a sidebar
+ // refresh and the contract matches `GET /series/:id/issues`.
+ issuesSvc.listRecentIssues({ limit: req.query.limit, withHistory: false }),
seriesSvc.listSeries(),
]);
const seriesById = new Map(series.map((s) => [s.id, s.name]));
diff --git a/server/services/pipeline/issues.js b/server/services/pipeline/issues.js
index 68190df9a9..b62e8736ab 100644
--- a/server/services/pipeline/issues.js
+++ b/server/services/pipeline/issues.js
@@ -218,13 +218,14 @@ export function snapshotRunHistory(prevStage, patch, stageId) {
return [snapshot, ...dedupedPrior].slice(0, STAGE_RUN_HISTORY_MAX);
}
-// Strip per-stage `runHistory` from a sanitized issue so list endpoints don't
-// ship the full version history on every read. Text stages can hold up to
-// STAGE_RUN_HISTORY_MAX (5) entries × ~600KB each, so a maxed-out issue is
-// ~12MB of payload the sidebar + per-series list never render. Detail reads
-// (`getIssue`, `GET /api/pipeline/issues/:id`) stay on the full shape; no
-// current caller of `listIssues` / `listRecentIssues` reads `stage.runHistory`
-// off a list result. Future callers that need history must use `getIssue`.
+// Strip per-stage `runHistory` from a sanitized issue so list-shaped
+// endpoints can opt out of shipping each stage's full version history. Text
+// stages can hold up to STAGE_RUN_HISTORY_MAX (5) entries × ~600KB each, so
+// a maxed-out issue is ~12MB of payload that the sidebar + per-series list
+// never render. Opt-in via `withHistory: false` on `listIssues` /
+// `listRecentIssues` — the default is full-shape because internal callers
+// (notably `exportSeries`) round-trip every stored field through the bucket
+// export, and dropping history there would lose it on the receiving peer.
const stripRunHistoryFromIssue = (issue) => {
if (!issue || typeof issue !== 'object' || !issue.stages) return issue;
const strippedStages = {};
@@ -423,24 +424,31 @@ async function writeState(state) {
await atomicWrite(statePath(), state);
}
-export async function listIssues({ seriesId = null, offset = 0, limit = ISSUES_PER_RESPONSE_MAX, paginated = false } = {}) {
+export async function listIssues({
+ seriesId = null,
+ offset = 0,
+ limit = ISSUES_PER_RESPONSE_MAX,
+ paginated = false,
+ withHistory = true,
+} = {}) {
const { issues } = await readState();
const filtered = seriesId ? issues.filter((i) => i.seriesId === seriesId) : issues;
const sorted = [...filtered].sort((a, b) => {
if (a.seriesId !== b.seriesId) return a.seriesId.localeCompare(b.seriesId);
return (a.number || 0) - (b.number || 0);
});
+ const project = withHistory ? (i) => i : stripRunHistoryFromIssue;
const safeLimit = Math.min(Math.max(1, limit), ISSUES_PER_RESPONSE_MAX);
const safeOffset = Math.max(0, offset);
if (paginated) {
return {
- items: sorted.slice(safeOffset, safeOffset + safeLimit).map(stripRunHistoryFromIssue),
+ items: sorted.slice(safeOffset, safeOffset + safeLimit).map(project),
total: sorted.length,
offset: safeOffset,
limit: safeLimit,
};
}
- return sorted.slice(0, ISSUES_PER_RESPONSE_MAX).map(stripRunHistoryFromIssue);
+ return sorted.slice(0, ISSUES_PER_RESPONSE_MAX).map(project);
}
/**
@@ -451,7 +459,7 @@ export async function listIssues({ seriesId = null, offset = 0, limit = ISSUES_P
* beyond 1000, so the sidebar's recent-issues view needs this dedicated
* helper.
*/
-export async function listRecentIssues({ limit = 10 } = {}) {
+export async function listRecentIssues({ limit = 10, withHistory = true } = {}) {
const { issues } = await readState();
// Coerce in two passes so non-finite inputs ('abc', undefined) fall to
// the default rather than letting JS's `0 || 10` short-circuit return
@@ -459,10 +467,11 @@ export async function listRecentIssues({ limit = 10 } = {}) {
const raw = Number(limit);
const fallback = Number.isFinite(raw) ? Math.floor(raw) : 10;
const clamped = Math.max(1, Math.min(50, fallback));
+ const project = withHistory ? (i) => i : stripRunHistoryFromIssue;
return [...issues]
.sort((a, b) => (b.updatedAt || '').localeCompare(a.updatedAt || ''))
.slice(0, clamped)
- .map(stripRunHistoryFromIssue);
+ .map(project);
}
export async function getIssue(id) {
diff --git a/server/services/pipeline/issues.test.js b/server/services/pipeline/issues.test.js
index d8ef8da7a7..ef4edbe76a 100644
--- a/server/services/pipeline/issues.test.js
+++ b/server/services/pipeline/issues.test.js
@@ -441,11 +441,14 @@ describe('pipeline issues service', () => {
});
});
- describe('list endpoints strip runHistory', () => {
+ describe('list endpoints opt into runHistory strip', () => {
// List payloads (sidebar, per-series list) never render runHistory,
- // and each text stage can hold up to 5 × ~600KB entries. Strip them
- // so a maxed-out issue doesn't ship ~12MB per read. Detail reads
- // (`getIssue`) must keep the full shape so the diff modal still works.
+ // and each text stage can hold up to 5 × ~600KB entries. Routes
+ // pass `withHistory: false` so a maxed-out issue doesn't ship ~12MB
+ // per read. The default stays `true` because `exportSeries` (and
+ // other internal callers) round-trip the full record into bucket
+ // exports; defaulting to strip would silently lose history on
+ // receiving peers. Detail reads (`getIssue`) keep the full shape.
const seedWithHistory = async () => {
const i = await svc.createIssue({ seriesId: 'ser-1', title: 'With history' });
await svc.updateStage(i.id, 'idea', { status: 'ready', input: 'seed', output: 'v1', lastRunId: 'r1' });
@@ -453,27 +456,44 @@ describe('pipeline issues service', () => {
return i;
};
- it('listIssues returns empty runHistory even when history is persisted', async () => {
+ it('listIssues default preserves runHistory (regression guard for exportSeries)', async () => {
await seedWithHistory();
const list = await svc.listIssues({ seriesId: 'ser-1' });
expect(list).toHaveLength(1);
+ expect(list[0].stages.idea.runHistory).toHaveLength(1);
+ expect(list[0].stages.idea.runHistory[0].runId).toBe('r1');
+ });
+
+ it('listIssues withHistory:false strips runHistory but keeps active stage fields', async () => {
+ await seedWithHistory();
+ const list = await svc.listIssues({ seriesId: 'ser-1', withHistory: false });
+ expect(list).toHaveLength(1);
expect(list[0].stages.idea.runHistory).toEqual([]);
- // Active stage fields still survive the strip.
+ // Active stage fields survive the strip.
expect(list[0].stages.idea.output).toBe('v2');
expect(list[0].stages.idea.lastRunId).toBe('r2');
});
- it('listIssues paginated:true strips runHistory from items', async () => {
+ it('listIssues paginated + withHistory:false strips runHistory from items', async () => {
await seedWithHistory();
- const result = await svc.listIssues({ seriesId: 'ser-1', offset: 0, limit: 10, paginated: true });
+ const result = await svc.listIssues({
+ seriesId: 'ser-1', offset: 0, limit: 10, paginated: true, withHistory: false,
+ });
expect(result.items).toHaveLength(1);
expect(result.items[0].stages.idea.runHistory).toEqual([]);
});
- it('listRecentIssues strips runHistory', async () => {
+ it('listRecentIssues default preserves runHistory', async () => {
await seedWithHistory();
const recent = await svc.listRecentIssues({ limit: 10 });
expect(recent).toHaveLength(1);
+ expect(recent[0].stages.idea.runHistory).toHaveLength(1);
+ });
+
+ it('listRecentIssues withHistory:false strips runHistory', async () => {
+ await seedWithHistory();
+ const recent = await svc.listRecentIssues({ limit: 10, withHistory: false });
+ expect(recent).toHaveLength(1);
expect(recent[0].stages.idea.runHistory).toEqual([]);
});