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: address local review findings for YouTube ingest pagination (#8267)
[._.]/ Adam Eivyed9c8c3785f1
diff --git a/client/src/components/brain/YoutubeIngestSettings.jsx b/client/src/components/brain/YoutubeIngestSettings.jsxindex be01fae1ea..6600869a05 100644--- a/client/src/components/brain/YoutubeIngestSettings.jsx+++ b/client/src/components/brain/YoutubeIngestSettings.jsx@@ -41,10 +41,11 @@ export default function YoutubeIngestSettings() {}, []);// Loads 50 records at a time; `usePagedCollection` dedupes by `id`, so each- // record is given one from its `videoId` (the ingest index's own key).+ // record is given one from its `videoId` (the ingest index's own key). A+ // failed fetch must reject rather than resolve empty, or `usePagedCollection`+ // reads it as "no more records" and InfiniteScrollFooter's retry never shows.const fetchIngestsPage = useCallback(async ({ cursor, signal }) => {- const res = await api.getYoutubeIngests({ limit: INGESTS_PAGE_SIZE, cursor, silent: true, signal })- .catch(() => ({ ingests: [] }));+ const res = await api.getYoutubeIngests({ limit: INGESTS_PAGE_SIZE, cursor, silent: true, signal });return {items: (res.ingests || []).map((record) => ({ ...record, id: record.videoId })),nextCursor: res.nextCursor ?? null,@@ -203,7 +204,7 @@ export default function YoutubeIngestSettings() {{saving ? 'Saving…' : 'Save YouTube Settings'}</button>- {(ingests.length > 0 || ingestsPage.loading) && (+ {(ingests.length > 0 || ingestsPage.loading || Boolean(ingestsPage.error)) && (<div className="pt-4 border-t border-port-border"><h4 className="text-sm font-medium text-gray-400 mb-2">Ingested ({ingests.length}{ingestsPage.hasMore ? '+' : ''})diff --git a/client/src/components/brain/YoutubeIngestSettings.test.jsx b/client/src/components/brain/YoutubeIngestSettings.test.jsxindex feacc3cb43..cd67890567 100644--- a/client/src/components/brain/YoutubeIngestSettings.test.jsx+++ b/client/src/components/brain/YoutubeIngestSettings.test.jsx@@ -55,6 +55,17 @@ describe('YoutubeIngestSettings ingest history pagination (#8267)', () => {expect(screen.getByText('Video v1')).toBeInTheDocument();});+ it('surfaces a failed initial fetch as a retryable error instead of a silent empty list', async () => {+ api.getYoutubeIngests.mockRejectedValue(new Error('network down'));++ render(<YoutubeIngestSettings />);++ expect(await screen.findByRole('button', { name: /retry loading/i })).toBeInTheDocument();+ // Not the "nothing ingested yet" silent case: the section header (and its+ // retry) render even though zero records loaded.+ expect(screen.getByText((_, el) => el.tagName === 'H4' && /Ingested \(0/.test(el.textContent))).toBeInTheDocument();+ });+it('removes a forgotten ingest from the loaded page without refetching', async () => {api.getYoutubeIngests.mockResolvedValue({ ingests: [ingest('v1', '2026-01-02T00:00:00.000Z')] });api.deleteYoutubeIngest.mockResolvedValue({ message: 'Ingest removed' });diff --git a/server/lib/README.md b/server/lib/README.mdindex ba2a2ed428..1d5281b3fc 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -414,7 +414,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `ptySpawnDiagnostics.js` | `diagnosePtySpawnFailure(err, {cwd, probeCwd, runtimeProbe})` + `probePtyRuntime(pty, cwd)` and the `PTY_UNAVAILABLE_PREFIX` / `PTY_WORKSPACE_MISSING_PREFIX` markers — turns node-pty’s one opaque `posix_spawn failed: No such file or directory` into a named fault. The executable is already cleared upstream (PATH resolve + `--version` probe), so a throw is either a `cwd` that vanished (cheap `existsSync`) or a PTY layer that cannot fork AT ALL — proven by re-forking a known-good command in a known-good directory; `diagnosed: false` means neither matched, and the caller re-throws rather than inventing a cause. **Retry policy is the caller’s and the two faults differ:** `agentTuiSpawning.js` matches only the PTY-layer prefix, mapping it to the actionable `runner-pty-unavailable` so the task blocks once with the repair, while a reaped workspace falls through to the retrying `spawn-rejected` because the next attempt provisions a fresh worktree. The motivating outage: an `npm ci` inside a CoS worktree emptied the primary checkout’s `server/node_modules` through a symlink, deleting the `spawn-helper` binary node-pty execs on every fork, while the already-loaded binding left the runner process itself looking healthy. || `pythonSetup.js` | Python venv / runner setup helpers. || `vttTranscript.js` | WebVTT/SRT → readable prose. `vttToPlainText(vtt)` (paragraph-joined transcript), `vttToLines(vtt)` (cleaned caption lines), `cleanCaptionLine(line)`. Collapses YouTube auto-captions' rolling repetition and strips inline `<c>`/timestamp markup. Used by the brain YouTube ingest. |-| `youtubeIngestFormat.js` | Pure data transformations for the brain's YouTube ingest (#6015): `parseVideoMetadata(json)` (yt-dlp `--dump-single-json` → the stored metadata shape, incl. the `subtitles`-vs-`automatic_captions` manual-caption signal), `buildIngestNote({meta,url,transcript,tags,agentPrompt,capturedAt})` (the Obsidian note, whose YAML frontmatter the user's own vault queries key on — every interpolated scalar goes through `yamlString`), `buildAgentTaskContext(...)` (the CoS follow-up prompt, including the untrusted-transcript boundary notice), `resolveObsidianPointer({written,vaultId,notePath,prior})` (keeps the prior note pointer when an ATTEMPTED mirror failed, so an evicted note can't be orphaned — #3706), plus `sanitizeFilename`, `formatDuration` (seconds → `h:mm:ss`) and `yamlString`; and the ingest-history cursor pagination (#8267): `compareIngestsDesc(a,b)` (newest-first order, `ingestedAt` desc with `videoId` desc as a deterministic tie-breaker), `encodeIngestCursor(record)`/`decodeIngestCursor(cursor)` (opaque base64url sort-key token; decode returns `null` rather than throwing on anything malformed), and `paginateIngests(sorted, {limit, cursor})` (slices a page starting strictly after the decoded cursor, so records added/removed elsewhere in the index between pages can't repeat or skip a row). No fs/db/childProcess/SSE imports; orchestration and storage stay in `services/youtubeIngest.js`. Surfaced through the barrel as a NAMESPACE export (`youtubeIngestFormat.*`) because `formatDuration` collides with `fileCore.js` and `sanitizeFilename` with `mimeTypes.js`. |+| `youtubeIngestFormat.js` | Pure data transformations for the brain's YouTube ingest (#6015): `parseVideoMetadata(json)` (yt-dlp `--dump-single-json` → the stored metadata shape, incl. the `subtitles`-vs-`automatic_captions` manual-caption signal), `buildIngestNote({meta,url,transcript,tags,agentPrompt,capturedAt})` (the Obsidian note, whose YAML frontmatter the user's own vault queries key on — every interpolated scalar goes through `yamlString`), `buildAgentTaskContext(...)` (the CoS follow-up prompt, including the untrusted-transcript boundary notice), `resolveObsidianPointer({written,vaultId,notePath,prior})` (keeps the prior note pointer when an ATTEMPTED mirror failed, so an evicted note can't be orphaned — #3706), plus `sanitizeFilename`, `formatDuration` (seconds → `h:mm:ss`) and `yamlString`; and the ingest-history cursor pagination (#8267): `compareIngestsDesc(a,b)` (newest-first order, `ingestedAt` desc with `videoId` desc as a deterministic tie-breaker), `decodeIngestCursor(cursor)` (opaque base64url sort-key token; returns `null` rather than throwing on anything malformed), and `paginateIngests(sorted, {limit, cursor})` (slices a page starting strictly after the decoded cursor and mints the opaque `nextCursor` for the last row returned, so records added/removed elsewhere in the index between pages can't repeat or skip a row). No fs/db/childProcess/SSE imports; orchestration and storage stay in `services/youtubeIngest.js`. Surfaced through the barrel as a NAMESPACE export (`youtubeIngestFormat.*`) because `formatDuration` collides with `fileCore.js` and `sanitizeFilename` with `mimeTypes.js`. || `youtubeUrl.js` | Canonical YouTube single-video URL rule (#6014). `YOUTUBE_VIDEO_URL_RE` (accepts `watch`/`shorts`/`live`/`embed` plus the `www.`/`m.`/`music.` hosts, rejects playlists, channels, and `/@handle` feeds), `youtubeVideoIdFromUrl(url)` (alias `youtubeVideoId`), `isYoutubeVideoUrl(url)`, and the shared `YOUTUBE_URL_INVALID_MESSAGE`. Single source for the brain ingest, the Takeout importer, the history scrape, the Music Video track import, and (by re-export) `client/src/lib/youtubeUrl.js`. A pure leaf — the throwing form lives in `youtubeUrlAssert.js`, so importing this can never drag `errorHandler.js` into the browser bundle. || `youtubeUrlAssert.js` | `assertYoutubeVideoUrl(url)` — the throwing form of the `youtubeUrl.js` rule: returns the video id, else throws 400 `YOUTUBE_URL_INVALID`. Separate because it needs `ServerError` (and so Node's `events`), which must stay out of the pure leaf the client re-exports. || `ytdlp.js` | `findYtDlp()` — cached discovery of the `yt-dlp` binary on PATH, mirrors `findFfmpeg()` in `ffmpeg.js`. Used by the track YouTube-import job. `resetYtDlpCache()` drops that cache after an in-place update or a fresh install, so neither needs a server restart to take effect. |diff --git a/server/lib/youtubeIngestFormat.js b/server/lib/youtubeIngestFormat.jsindex 2f94fcd464..8b51c63311 100644--- a/server/lib/youtubeIngestFormat.js+++ b/server/lib/youtubeIngestFormat.js@@ -199,8 +199,12 @@ export function compareIngestsDesc(a, b) {return String(b?.videoId || '').localeCompare(String(a?.videoId || ''));}-/** Opaque continuation token: the sort key of the last record on a page. */-export function encodeIngestCursor(record) {+/**+ * Opaque continuation token: the sort key of the last record on a page.+ * Not exported — only `paginateIngests` below produces one; callers only+ * ever need to decode a cursor they were handed, never mint one directly.+ */+function encodeIngestCursor(record) {const payload = JSON.stringify({ v: INGEST_CURSOR_VERSION, ingestedAt: record.ingestedAt, videoId: record.videoId });return Buffer.from(payload, 'utf8').toString('base64url');}diff --git a/server/lib/youtubeIngestFormat.test.js b/server/lib/youtubeIngestFormat.test.jsindex 0834fa835f..34cf46b556 100644--- a/server/lib/youtubeIngestFormat.test.js+++ b/server/lib/youtubeIngestFormat.test.js@@ -9,7 +9,6 @@ import {buildAgentTaskContext,resolveObsidianPointer,compareIngestsDesc,- encodeIngestCursor,decodeIngestCursor,paginateIngests,} from './youtubeIngestFormat.js';@@ -273,10 +272,11 @@ describe('ingest history cursor pagination (#8267)', () => {]);});- it('round-trips a cursor through encode/decode', () => {- const record = { ingestedAt: '2026-01-02T00:00:00.000Z', videoId: 'ccccccccccc' };- const decoded = decodeIngestCursor(encodeIngestCursor(record));- expect(decoded).toEqual({ ingestedAt: record.ingestedAt, videoId: record.videoId });+ it('round-trips a cursor minted by paginateIngests through decodeIngestCursor', () => {+ const sorted = [...RECORDS].sort(compareIngestsDesc);+ const page = paginateIngests(sorted, { limit: 2 });+ const decoded = decodeIngestCursor(page.nextCursor);+ expect(decoded).toEqual({ ingestedAt: '2026-01-02T00:00:00.000Z', videoId: 'ccccccccccc' });});it('decodeIngestCursor returns null (never throws) on garbage input', () => {