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

docs([audit-remaining-getissue-prechecks-in-pipeline-routes]): remove from PLAN.md and log to changelog

[._.]/ Adam Eivy646e162fe259
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 3f51d72537..cf3d1a2294 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,8 @@
## Changed
+- **[audit-remaining-getissue-prechecks-in-pipeline-routes] Audit of remaining `getIssue` prechecks in `pipeline.js`; music attach/delete routes drop the redundant read.** Followed up on the comic-cover consolidation by tracing each of the 10 sites cited in PLAN.md plus `:1427` found during the audit, so 11 sites total in `server/routes/pipeline.js`. Verdict: **8 stay, 2 drop, 1 keep-but-unbind**. **Drop** at `/issues/:id/stages/audio/music/attach` and `DELETE /issues/:id/stages/audio/music` — the only consumer was `audioStatusAfterMusicChange(issue)` (reads `issue.stages.audio.lines.length`), which now derives from `currentStage` inside `updateStageWithLatest`'s `computeFn` instead. Helper signature changed from `(issue) => …` to `(stage) => …`. **Keep-but-unbind** at `/issues/:id/stages/audio/music/upload` — the precheck must gate `importUploadedTrack` (a filesystem write) so a bad id doesn't orphan an imported file when the subsequent write 404s; the binding is dropped because the status computation now uses the freshest stage too. **Keep** at the other 8 sites because each route consumes issue data the called service can't supply: `extract-audio-lines` / `audio/lines/:lineIdx/render` / `storyboards/extract-scenes` / `comicPages/extract-pages` / `:stageId/extract-canon` all need `issue.seriesId` (or stage-locked guard against a sibling stage); `GET /issues/:id` IS the read; `comicPages/pages/:pageIndex/render` keeps the precheck-only-error-shape pageIndex bounds check (the inline comment explicitly justifies it as "avoids loading the bible context just to error out"); and `auto-run-text` keeps the precheck-only-error-shape sync 404 (the runner's IIFE is fire-and-forget, so without the precheck a bad id returns 200 with a runId that immediately errors out via SSE). Net: per-request `data/issues.json` reads on attach/delete music drop from 2 → 1, and the status computation moves from a stale snapshot to the freshest persisted state (eliminates a small TOCTOU window vs. a concurrent line edit). New tests pin the 404 status AND `PIPELINE_ISSUE_NOT_FOUND` error code for both refactored routes (the precheck-removal equivalence depends on the downstream not changing the error shape). 87/87 pipeline route tests pass; 6152/6152 server tests pass.
+
- **[med-tests-no-direct-tests-for-executetuirun-pty] `executeTuiRun` PTY mechanics now have direct test coverage.** The existing `server/lib/tuiPromptRunner.test.js` only covered the two pure helpers (`cleanTuiResponse`, `resolveTuiResponseText`); the PTY-driven core that orchestrates spawn → ready-watch → paste → completion was entirely unverified. New `describe('executeTuiRun')` block mocks `node-pty` and the runner-service hooks so each completion path can be triggered deterministically from the test: input validation (3 cases), spawn failure wrapping, `registerActiveRun` + `emitRunStarted` shape, provider `envVars` merge + `CLAUDECODE` stripping, and the six completion paths — `idle-complete` (after first response chunk + idle window), `timeout` (exitCode 124), `command-not-found` early-fail probe (exitCode 127), clean `exit` (exitCode 0), `killed` (signal in error message), and non-zero exit with tail-bearing error. `fileUtils` stays real except for `ensureDir` (mocked no-op) so the existing `resolveTuiResponseText` tests keep using real `tryReadFile`. 12 new tests; 29/29 file-level tests pass; 6162/6162 server tests pass. PLAN.md drops the self-deferred `[cover-render-factory-target-binding]` entry alongside — it explicitly read "pick this up when a fifth cover-render variant appears," that trigger hasn't fired, and the entry was confusing `/claim`.
- **[med-importer-server-routes-importer-test-js-no] Pin `ERR_PARTIAL_COMMIT_ISSUES → 422` status mapping in importer route tests.** `server/routes/importer.test.js` previously covered the `ERR_VALIDATION → 400`, `ERR_LOCKED → 409`, and `universeSvc.ERR_NOT_FOUND → 404` entries in `SERVICE_ERROR_STATUS` but not the partial-commit entry that maps `IMPORTER_PARTIAL_COMMIT_ISSUES → 422`. A refactor that dropped the entry would fall through to `asyncHandler`'s generic 500 path, pager-alert on a user-action-recoverable state (universe + series already persisted, only the issue loop rolled back), and strip the `arcAlreadyPersisted` / `skipArcOnRetry` retry signals the client gates the retry-without-arc-overwrite path on — the exact regression `server/routes/importer.js:28-37`'s long comment warns against. New `commit` suite test mocks `commitImport` to reject with `{ code: ERR_PARTIAL_COMMIT_ISSUES, context: { universeId, seriesId, arcAlreadyPersisted, skipArcOnRetry } }`, asserts status 422, asserts `body.code === ERR_PARTIAL_COMMIT_ISSUES`, and asserts the full context object survives `sanitizeContext` and reaches the client. PLAN cited the historical status (`→ 207`); test pins the current implementation (`→ 422`) per the same in-code rationale (207 trips the client `request()` helper's `response.ok === true` branch and mis-toasts the partial commit as a success). 11/11 route tests pass.
diff --git a/PLAN.md b/PLAN.md
index 4d6dd66ede..31a159e203 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -12,8 +12,6 @@ _Nothing currently parked — pick the next item from the Backlog._
### Code quality / dedup (from `/simplify` passes)
-- [ ] [audit-remaining-getissue-prechecks-in-pipeline-routes] **[LOW][EFF]** Audit the remaining `issuesSvc.getIssue(req.params.id).catch((err) => { throw mapServiceError(err); })` precheck pattern at `server/routes/pipeline.js:601, 683, 759, 785, 799, 1239, 1277, 1348, 1580, 1741`. Several of these handlers call services that themselves do `getIssue` internally on the first read (e.g. `generateStage` ~line 1267; `enqueueVisualImage` ~line 1729) — same pattern as the comic-cover routes we just consolidated, where the precheck was a duplicate `data/issues.json` read with no error-mapping difference. For each site, trace the called service to verify whether its first persisted read is `getIssue(id)` (or an equivalent `PIPELINE_ISSUE_NOT_FOUND` raiser) and drop the precheck where it is strictly redundant; leave precheck-only-error-shape cases alone. Surfaced by /simplify reuse-agent during `[drop-redundant-getissue-precheck-comic-cover-render]`; deferred to keep that PR a one-route consolidation.
-
### v2.1.0 pre-release review residue (deferred from main→release multi-agent review, 2026-05-16)
- [ ] [agent-tui-spawn-truncation-warn-parity] **[LOW][AI-DISPATCH]** `server/services/agentTuiSpawning.js:177-179` (and the `rawBuffer` slice at line ~273-274) silently slice the head of the same buffers when they cross `OUTPUT_BUFFER_HEADROOM` / `RAW_BUFFER_HEADROOM`, with no warning and no agent-metadata flag. The companion one-shot runner now sets `outputBufferTruncated` and surfaces it through the run record (see `[med-ai-dispatch-server-lib-tuipromptrunner-js-198]`). Long-running CoS agents using `agentTuiSpawning.js` mostly stream to `output.txt` via `appendAgentOutputLines`, so the buffer overflow here is less load-bearing — but the same warn-once + agent-metadata flag would close the visibility gap. Deferred from `[med-ai-dispatch-server-lib-tuipromptrunner-js-198]` to keep that PR scoped.
diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.js
index c1a1d5895e..6f41de9881 100644
--- a/server/routes/pipeline.test.js
+++ b/server/routes/pipeline.test.js
@@ -1691,13 +1691,17 @@ describe('pipeline routes', () => {
expect(r.status).toBe(400);
});
- it('POST /audio/music/attach 404s when the issue does not exist', async () => {
+ it('POST /audio/music/attach 404s with PIPELINE_ISSUE_NOT_FOUND when the issue does not exist', async () => {
const app = makeApp();
musicLibraryStore.set('shared.mp3', { filename: 'shared.mp3', label: 'shared', sizeBytes: 100, updatedAt: '2026-05-15T00:00:00.000Z' });
const r = await request(app)
.post('/api/pipeline/issues/iss-does-not-exist/stages/audio/music/attach')
.send({ trackFilename: 'shared.mp3' });
expect(r.status).toBe(404);
+ // Pin both status AND code — the precheck-removal equivalence depends
+ // on `updateStageWithLatest` preserving the same error shape the dropped
+ // `getIssue` precheck would have raised.
+ expect(r.body.code).toBe('PIPELINE_ISSUE_NOT_FOUND');
});
it('DELETE /audio/music clears music from the issue without deleting the library entry', async () => {
@@ -1716,12 +1720,13 @@ describe('pipeline routes', () => {
expect(musicLibraryStore.has('shared.mp3')).toBe(true);
});
- it('DELETE /audio/music 404s when the issue does not exist', async () => {
+ it('DELETE /audio/music 404s with PIPELINE_ISSUE_NOT_FOUND when the issue does not exist', async () => {
const app = makeApp();
const r = await request(app)
.delete('/api/pipeline/issues/iss-does-not-exist/stages/audio/music')
.send();
expect(r.status).toBe(404);
+ expect(r.body.code).toBe('PIPELINE_ISSUE_NOT_FOUND');
});
it('DELETE /audio/music-library/:filename removes the file from the library', async () => {