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([conflict-journal-base-hash-prune]): use uncapped listIssueIds in orphan sweep
[._.]/ Adam Eivyf0a82dff6ddc
diff --git a/server/services/pipeline/issues.js b/server/services/pipeline/issues.jsindex 66403f1a78..a744791674 100644--- a/server/services/pipeline/issues.js+++ b/server/services/pipeline/issues.js@@ -555,6 +555,22 @@ export async function listIssues({return sorted.slice(0, ISSUES_PER_RESPONSE_MAX).map(project);}+/**+ * Every live (or, with `includeDeleted`, every) issue id — UNCAPPED.+ *+ * `listIssues` slices at `ISSUES_PER_RESPONSE_MAX` (1000) even unpaginated, so+ * it can't back a "does this id still exist?" membership check: an install with+ * >1000 issues would report ids beyond the cap as missing. Callers that need+ * the complete id set (e.g. the conflict-journal orphan-base-hash sweep, which+ * would otherwise prune a live issue's base hash and silently disable conflict+ * detection for it) use this. Returns ids only — no projection, no history.+ */+export async function listIssueIds({ includeDeleted = false } = {}) {+ const { issues } = await readState();+ const live = includeDeleted ? issues : issues.filter((i) => !i.deleted);+ return live.map((i) => i.id);+}+/*** Recently-updated issues across all series. Sorts the FULL issue set by* `updatedAt` desc before applying `limit` — unlike `listIssues`, whichdiff --git a/server/services/pipeline/issues.test.js b/server/services/pipeline/issues.test.jsindex 31cb054a79..fc972c3acb 100644--- a/server/services/pipeline/issues.test.js+++ b/server/services/pipeline/issues.test.js@@ -991,6 +991,34 @@ describe('pipeline issues service', () => {expect(await svc.pruneTombstonedIssues('nope')).toEqual({ pruned: 0 });});});++ describe('listIssueIds', () => {+ it('returns live ids by default and includes deleted only when asked', async () => {+ const a = await svc.createIssue({ seriesId: 'ser-ids', title: 'A' });+ const b = await svc.createIssue({ seriesId: 'ser-ids', title: 'B' });+ await svc.deleteIssue(b.id);+ const live = await svc.listIssueIds();+ expect(live).toContain(a.id);+ expect(live).not.toContain(b.id);+ const all = await svc.listIssueIds({ includeDeleted: true });+ expect(all).toEqual(expect.arrayContaining([a.id, b.id]));+ });++ it('is uncapped — does not slice at ISSUES_PER_RESPONSE_MAX like listIssues', async () => {+ // Guard the conflict-journal orphan-sweep contract: listIssueIds must+ // return EVERY live id, or the sweep would treat a live issue beyond+ // the cap as orphaned and strip its base hash. Asserted structurally+ // here (cap math) since seeding 1000+ issues is too slow for a unit+ // test: listIssues caps with `.slice(0, ISSUES_PER_RESPONSE_MAX)`,+ // listIssueIds has no slice. We at least confirm a small set round-trips+ // 1:1 (no accidental pagination/limit wired in).+ const ids = [];+ for (let i = 0; i < 5; i++) ids.push((await svc.createIssue({ seriesId: 'ser-uncapped', title: `E${i}` })).id);+ const got = await svc.listIssueIds();+ for (const id of ids) expect(got).toContain(id);+ expect(got.filter((id) => ids.includes(id))).toHaveLength(5);+ });+ });});describe('isStageReady', () => {diff --git a/server/services/sharing/tombstoneGc.js b/server/services/sharing/tombstoneGc.jsindex 7415fde4cb..7e3d56bb1c 100644--- a/server/services/sharing/tombstoneGc.js+++ b/server/services/sharing/tombstoneGc.js@@ -28,39 +28,41 @@import { pruneTombstonedUniverses, listUniverses } from '../universeBuilder.js';import { pruneTombstonedSeries, listSeries } from '../pipeline/series.js';-import { pruneTombstonedIssues, listIssues } from '../pipeline/issues.js';+import { pruneTombstonedIssues, listIssueIds } from '../pipeline/issues.js';import { pruneTombstonedCollections, listCollections } from '../mediaCollections.js';import { pruneOrphanedBaseHashes } from '../../lib/conflictJournal.js';import { listPeerSubscriptions } from './peerSync.js';import { getMinAckAcrossPeers } from './peerTombstoneCursors.js';import { getPeers } from '../instances.js';-// Each kind's live-record lister (default args exclude tombstoned/deleted).+// Each kind's UNCAPPED live-id source (default args exclude tombstoned/deleted).// Used to build the orphan-sweep resolver's per-kind id-sets. A kind absent// from this map is unknown → the resolver keeps its keys (never strips).+// `listIssueIds` (not `listIssues`) because the latter caps at 1000 — a capped+// source would report a live record beyond the cap as missing and the sweep+// would strip its base hash, silently disabling conflict detection for it.const LIVE_ID_LISTERS = Object.freeze({- universe: listUniverses,- series: listSeries,- issue: () => listIssues({}),- mediaCollection: listCollections,+ universe: async () => (await listUniverses()).map((r) => r.id),+ series: async () => (await listSeries()).map((r) => r.id),+ issue: () => listIssueIds(),+ mediaCollection: async () => (await listCollections()).map((r) => r.id),});// Build the `pruneOrphanedBaseHashes` resolver for ONE sweep: load each kind's// live-id Set once on first use (lazily — a sweep with no keys of a given kind// never lists it) and check membership in memory. This collapses what would be-// one record read PER base-hash key into at most one directory listing per kind-// per sweep. Unknown kinds resolve to `true` so the sweep can never strip a key-// it can't authoritatively check (a base hash for a future kind, or a shape-// this version doesn't recognize); a listing that throws also keeps the kind's-// keys (the `pruneOrphanedBaseHashes` resolver-error path is conservative too).+// one record read PER base-hash key into at most one listing per kind per+// sweep. Unknown kinds resolve to `true` so the sweep can never strip a key it+// can't authoritatively check (a base hash for a future kind, or a shape this+// version doesn't recognize); a listing that throws also keeps the kind's keys+// (the `pruneOrphanedBaseHashes` resolver-error path is conservative too).function makeBaseHashKeyResolver() {const idSets = new Map(); // kind → Set<liveId>return async (kind, id) => {const lister = LIVE_ID_LISTERS[kind];if (!lister) return true; // unknown kind → never stripif (!idSets.has(kind)) {- const records = await lister();- idSets.set(kind, new Set(records.map((r) => r.id)));+ idSets.set(kind, new Set(await lister()));}return idSets.get(kind).has(id);};diff --git a/server/services/sharing/tombstoneGc.test.js b/server/services/sharing/tombstoneGc.test.jsindex ebcbd0644e..64b7690fb3 100644--- a/server/services/sharing/tombstoneGc.test.js+++ b/server/services/sharing/tombstoneGc.test.js@@ -14,7 +14,7 @@ vi.mock('../pipeline/series.js', () => ({}));vi.mock('../pipeline/issues.js', () => ({pruneTombstonedIssues: vi.fn().mockResolvedValue({ pruned: 0 }),- listIssues: vi.fn().mockResolvedValue([]),+ listIssueIds: vi.fn().mockResolvedValue([]),}));vi.mock('../mediaCollections.js', () => ({pruneTombstonedCollections: vi.fn().mockResolvedValue({ pruned: 0 }),@@ -40,7 +40,7 @@ import {} from './tombstoneGc.js';import { pruneTombstonedUniverses, listUniverses } from '../universeBuilder.js';import { pruneTombstonedSeries, listSeries } from '../pipeline/series.js';-import { pruneTombstonedIssues, listIssues } from '../pipeline/issues.js';+import { pruneTombstonedIssues, listIssueIds } from '../pipeline/issues.js';import { pruneTombstonedCollections, listCollections } from '../mediaCollections.js';import { pruneOrphanedBaseHashes } from '../../lib/conflictJournal.js';import { listPeerSubscriptions } from './peerSync.js';@@ -125,7 +125,7 @@ describe('sweepTombstones — orphaned base-hash sweep', () => {it('passes a resolver that keeps live records, drops dead ones, keeps unknown kinds, and lists each kind once', async () => {listUniverses.mockResolvedValue([{ id: 'u-live' }]);listSeries.mockResolvedValue([{ id: 's-live' }]);- listIssues.mockResolvedValue([{ id: 'i-live' }]);+ listIssueIds.mockResolvedValue(['i-live']); // already ids, uncappedlistCollections.mockResolvedValue([{ id: 'c-live' }]);// Capture the resolver the sweep hands to pruneOrphanedBaseHashes and drive// it directly — this is the real makeBaseHashKeyResolver closure.