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: pagination on pipeline issues + toolkit runner deleteRun + nav drift

[._.]/ Adam Eivy2b88c563759c
diff --git a/server/index.js b/server/index.js
index 527a20ce58..caab719259 100644
--- a/server/index.js
+++ b/server/index.js
@@ -281,7 +281,18 @@ aiToolkit.services.runner.isRunActive = (runId) => {
if (aiToolkit.services.runner._portosActiveRuns?.has(runId)) return true;
return originalIsRunActive(runId);
};
-console.log('🔧 Patched aiToolkit runner.executeCliRun + stopRun + isRunActive with PortOS CLI variants');
+// Patch deleteRun so that deleting an in-flight PortOS CLI run also kills the
+// child process before removing the on-disk directory. Without this patch,
+// deleteRun only checks the toolkit's internal `activeRuns` map (which is
+// empty for PortOS CLI runs) and silently leaves a zombie child process running.
+const originalDeleteRun = aiToolkit.services.runner.deleteRun.bind(aiToolkit.services.runner);
+aiToolkit.services.runner.deleteRun = async function (runId, ...args) {
+ if (this._portosActiveRuns?.has?.(runId)) {
+ await this.stopRun(runId);
+ }
+ return originalDeleteRun.call(this, runId, ...args);
+};
+console.log('🔧 Patched aiToolkit runner.executeCliRun + stopRun + isRunActive + deleteRun with PortOS CLI variants');
// Note: prompts service is initialized automatically by createAIToolkit()
diff --git a/server/lib/navManifest.js b/server/lib/navManifest.js
index caa189cfff..3301bebb1f 100644
--- a/server/lib/navManifest.js
+++ b/server/lib/navManifest.js
@@ -7,6 +7,7 @@ export const NAV_COMMANDS = [
{ id: 'nav.dashboard', path: '/', label: 'Dashboard', section: 'Main', aliases: ['dashboard', 'home'], keywords: ['overview', 'start'] },
{ id: 'nav.review-hub', path: '/review', label: 'Review Hub', section: 'Main', aliases: ['review', 'review-hub'] },
{ id: 'nav.cybercity', path: '/city', label: 'CyberCity', section: 'Main', aliases: ['city', 'cybercity'], keywords: ['3d', 'visualization'] },
+ { id: 'nav.cybercity.settings', path: '/city/settings', label: 'CyberCity Settings', section: 'Main', aliases: ['city settings', 'cybercity settings', 'city-settings', 'cybercity-config'], keywords: ['cybercity', 'settings', '3d', 'configure'] },
{ id: 'nav.apps', path: '/apps', label: 'Apps', section: 'Main', aliases: ['apps'] },
{ id: 'nav.reference-repos', path: '/reference-repos', label: 'Reference Repos', section: 'Main', aliases: ['reference-repos', 'references', 'reference', 'upstream', 'watch'], keywords: ['upstream', 'reference code', 'borrowed code', 'fork', 'git watch', 'commit watch', 'phosphene'] },
@@ -131,6 +132,7 @@ export const NAV_COMMANDS = [
{ id: 'nav.settings.telegram', path: '/settings/telegram', label: 'Telegram', section: 'Settings', aliases: ['settings-telegram', 'telegram'] },
{ id: 'nav.settings.voice', path: '/settings/voice', label: 'Voice', section: 'Settings', aliases: ['settings-voice', 'voice', 'voice-settings'], keywords: ['mic', 'microphone', 'speech', 'tts', 'whisper', 'kokoro'] },
+ { id: 'nav.ambient', path: '/ambient', label: 'Ambient', section: 'System', aliases: ['ambient', 'ambient-mode', 'ambient mode'], keywords: ['idle', 'background', 'display', 'screensaver', 'fullscreen'] },
{ id: 'nav.data', path: '/data', label: 'Data', section: 'System', aliases: ['data'] },
{ id: 'nav.cos.health', path: '/cos/health', label: 'Health', section: 'System', aliases: ['cos-health'] },
{ id: 'nav.instances', path: '/instances', label: 'Instances', section: 'System', aliases: ['instances'] },
diff --git a/server/routes/pipeline.js b/server/routes/pipeline.js
index d6d27d4c7b..f8a1a25857 100644
--- a/server/routes/pipeline.js
+++ b/server/routes/pipeline.js
@@ -31,6 +31,12 @@ import {
refineImagePixelCap,
PIXEL_CAP_MESSAGE,
} from '../lib/validation.js';
+
+const issuesListQuerySchema = z.object({
+ offset: z.preprocess((v) => (v === undefined ? 0 : Number(v)), z.number().int().min(0)).default(0),
+ limit: z.preprocess((v) => (v === undefined ? 1000 : Number(v)), z.number().int().min(1).max(1000)).default(1000),
+});
+
import * as seriesSvc from '../services/pipeline/series.js';
import * as issuesSvc from '../services/pipeline/issues.js';
import * as seasonsSvc from '../services/pipeline/seasons.js';
@@ -874,7 +880,13 @@ router.get('/series/:id/issues', asyncHandler(async (req, res) => {
// Validate the series exists so a typo returns 404 instead of [] (less
// confusing for the UI).
await seriesSvc.getSeries(req.params.id).catch((err) => { throw mapServiceError(err); });
- res.json(await issuesSvc.listIssues({ seriesId: req.params.id }));
+ const hasPagination = req.query.offset !== undefined || req.query.limit !== undefined;
+ if (hasPagination) {
+ const { offset, limit } = validateRequest(issuesListQuerySchema, req.query);
+ res.json(await issuesSvc.listIssues({ seriesId: req.params.id, offset, limit, paginated: true }));
+ } else {
+ res.json(await issuesSvc.listIssues({ seriesId: req.params.id }));
+ }
}));
router.post('/series/:id/issues', asyncHandler(async (req, res) => {
diff --git a/server/services/pipeline/issues.js b/server/services/pipeline/issues.js
index f970eba562..86530dbd9b 100644
--- a/server/services/pipeline/issues.js
+++ b/server/services/pipeline/issues.js
@@ -331,15 +331,19 @@ async function writeState(state) {
await atomicWrite(statePath(), state);
}
-export async function listIssues({ seriesId = null } = {}) {
+export async function listIssues({ seriesId = null, offset = 0, limit = ISSUES_PER_RESPONSE_MAX, paginated = false } = {}) {
const { issues } = await readState();
const filtered = seriesId ? issues.filter((i) => i.seriesId === seriesId) : issues;
- return [...filtered]
- .sort((a, b) => {
- if (a.seriesId !== b.seriesId) return a.seriesId.localeCompare(b.seriesId);
- return (a.number || 0) - (b.number || 0);
- })
- .slice(0, ISSUES_PER_RESPONSE_MAX);
+ 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 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), total: sorted.length, offset: safeOffset, limit: safeLimit };
+ }
+ return sorted.slice(0, ISSUES_PER_RESPONSE_MAX);
}
/**
diff --git a/server/services/pipeline/issues.test.js b/server/services/pipeline/issues.test.js
index 5734f6650c..140a0c727d 100644
--- a/server/services/pipeline/issues.test.js
+++ b/server/services/pipeline/issues.test.js
@@ -203,6 +203,46 @@ describe('pipeline issues service', () => {
expect(list1.every((i) => i.seriesId === 'ser-1')).toBe(true);
});
+ describe('listIssues pagination', () => {
+ it('returns raw array when paginated is false (legacy default)', async () => {
+ await svc.createIssue({ seriesId: 'ser-1', title: 'A' });
+ await svc.createIssue({ seriesId: 'ser-1', title: 'B' });
+ const result = await svc.listIssues({ seriesId: 'ser-1' });
+ expect(Array.isArray(result)).toBe(true);
+ expect(result).toHaveLength(2);
+ });
+
+ it('returns paginated envelope when paginated:true', async () => {
+ await svc.createIssue({ seriesId: 'ser-1', title: 'A' });
+ await svc.createIssue({ seriesId: 'ser-1', title: 'B' });
+ await svc.createIssue({ seriesId: 'ser-1', title: 'C' });
+ const result = await svc.listIssues({ seriesId: 'ser-1', offset: 0, limit: 2, paginated: true });
+ expect(result.total).toBe(3);
+ expect(result.offset).toBe(0);
+ expect(result.limit).toBe(2);
+ expect(result.items).toHaveLength(2);
+ expect(result.items[0].title).toBe('A');
+ expect(result.items[1].title).toBe('B');
+ });
+
+ it('respects offset when paginated:true', async () => {
+ await svc.createIssue({ seriesId: 'ser-1', title: 'A' });
+ await svc.createIssue({ seriesId: 'ser-1', title: 'B' });
+ await svc.createIssue({ seriesId: 'ser-1', title: 'C' });
+ const result = await svc.listIssues({ seriesId: 'ser-1', offset: 2, limit: 10, paginated: true });
+ expect(result.total).toBe(3);
+ expect(result.items).toHaveLength(1);
+ expect(result.items[0].title).toBe('C');
+ });
+
+ it('offset beyond total returns empty items but correct total', async () => {
+ await svc.createIssue({ seriesId: 'ser-1', title: 'A' });
+ const result = await svc.listIssues({ seriesId: 'ser-1', offset: 100, limit: 10, paginated: true });
+ expect(result.total).toBe(1);
+ expect(result.items).toHaveLength(0);
+ });
+ });
+
describe('listRecentIssues', () => {
it('orders descending by updatedAt across all series', async () => {
const a = await svc.createIssue({ seriesId: 'ser-1', title: 'A' });
@@ -625,4 +665,28 @@ describe('pipeline issues service', () => {
expect(result.reassigned).toBe(3);
});
});
+
+ describe('concurrent write serialization', () => {
+ it('two concurrent writes do not clobber each other — both fields survive in final state', async () => {
+ // This is the key regression test for the queueIssueWrite tail.
+ // If the write queue is bypassed or broken, both calls read the same
+ // pre-write snapshot and the last one to land wins — exactly one of
+ // the two writes is silently dropped.
+ const issue = await svc.createIssue({ seriesId: 'ser-1', title: 'Concurrency target' });
+
+ // Fire two writes concurrently without awaiting individually.
+ // updateStage writes to `idea.output`; updateIssue writes to top-level `status`.
+ // A clobbering race would lose whichever write landed second (its pre-image
+ // read captured an empty idea.output or no status change).
+ await Promise.all([
+ svc.updateStage(issue.id, 'idea', { status: 'ready', output: 'beat sheet content' }),
+ svc.updateIssue(issue.id, { status: 'needs-review' }),
+ ]);
+
+ const final = await svc.getIssue(issue.id);
+ // Both mutations must survive — if either is missing, the write tail is broken.
+ expect(final.stages.idea.output).toBe('beat sheet content');
+ expect(final.status).toBe('needs-review');
+ });
+ });
});