0048 option C: purge the machine tables — migration 0055 + delete every run read path #126

Merged
chad merged 7 commits from glen/0048-machines-purge into main 2026-10-18 08:19:43 -04:00
Collaborator

Implements approved doc 0048, option C — the machines purge. Contains a destructive migration (0055); it runs on deploy.

What it does

  • Migration 0055_machines_purge.sql: deletes the 12 run conversations (all 2026-10-10 e2e artifacts — the doc's live-DB evidence) with every dependent row across all 11 FK/linkage tables, sweeps ghost mr_… stage sessions from harness_events/harness_runs, and drops machine_runs + machine_stage_runs.
  • Code cuts: /r/[runId] view + run GET API + db/machines.ts deleted; run arms removed from attention (unread is message-based only), organize (purge walk, runStatus/runParent maps), sandboxes/sandbox-view (run lease arm, run sandbox links), reaper (LIVE_STATUSES), child-status (mr_ → not-found), inspect (mr_ targets, dead stage-strip), conversation-href, sidebar-tree, page-context, preview-list, agent-cards; tool descriptions drop mr_ mentions; AGENTS.md's four machine-era notes rewritten.
  • Tests: 777 → 764 — 13 run-scenario tests deleted with the feature (verified none covered surviving behavior); attach tests repointed to a conversation owner, semantics-equivalent.

Verification

  • Migration proven twice independently: by me (seeded worst-case: run + 2 stages + every dependent kind) and by the fresh-eyes review child (rebuilt through the real migrator, re-checked FK coverage against every drizzle FOREIGN KEY declaration, exercised sandbox_attachments separately). Both: zero tables left, zero orphans, clean PRAGMA foreign_key_check, innocent chats untouched.
  • The review found one should-fix, taken: stage sessions with events but no conversations row (the 0036 case) survived the conversation-keyed DELETE — fixed with OR session_id GLOB 'mr_*' (GLOB's _ is literal) and re-proven with a ghost-session test db. Remaining nits are inert historical-render arms (old transcripts' machine wake chips), kept deliberately.
  • Gates: tsc clean, eslint exactly the 2 pre-existing warnings, 764 passed / 13 skipped.

Deploy note: migration 0055 runs on merge via the Forgejo workflow — irreversible, but the 0048 doc records what's lost (12 e2e runs; the one real conversation was "should a solo developer self-host…", one question and answer). Backups exist in data/backups per the reaper's schedule if you ever want the raw rows.

Implemented by claude (first half) + in-thread (migration, remaining cuts, review fixes); reviewed by a fresh child thread with an independent migration proof.

Implements approved doc 0048, option C — the machines purge. **Contains a destructive migration (0055); it runs on deploy.** ## What it does - **Migration `0055_machines_purge.sql`**: deletes the 12 run conversations (all 2026-10-10 e2e artifacts — the doc's live-DB evidence) with every dependent row across all 11 FK/linkage tables, sweeps ghost `mr_…` stage sessions from harness_events/harness_runs, and **drops `machine_runs` + `machine_stage_runs`**. - **Code cuts**: `/r/[runId]` view + run GET API + `db/machines.ts` deleted; run arms removed from attention (unread is message-based only), organize (purge walk, runStatus/runParent maps), sandboxes/sandbox-view (run lease arm, run sandbox links), reaper (`LIVE_STATUSES`), child-status (`mr_` → not-found), inspect (`mr_` targets, dead stage-strip), conversation-href, sidebar-tree, page-context, preview-list, agent-cards; tool descriptions drop `mr_` mentions; AGENTS.md's four machine-era notes rewritten. - **Tests**: 777 → 764 — 13 run-scenario tests deleted with the feature (verified none covered surviving behavior); attach tests repointed to a conversation owner, semantics-equivalent. ## Verification - Migration proven twice independently: by me (seeded worst-case: run + 2 stages + every dependent kind) and by the fresh-eyes review child (rebuilt through the real migrator, re-checked FK coverage against every drizzle `FOREIGN KEY` declaration, exercised `sandbox_attachments` separately). Both: zero tables left, zero orphans, clean `PRAGMA foreign_key_check`, innocent chats untouched. - The review found **one should-fix, taken**: stage sessions with events but no conversations row (the 0036 case) survived the conversation-keyed DELETE — fixed with `OR session_id GLOB 'mr_*'` (GLOB's `_` is literal) and re-proven with a ghost-session test db. Remaining nits are inert historical-render arms (old transcripts' `machine` wake chips), kept deliberately. - Gates: tsc clean, eslint exactly the 2 pre-existing warnings, **764 passed / 13 skipped**. **Deploy note**: migration 0055 runs on merge via the Forgejo workflow — irreversible, but the 0048 doc records what's lost (12 e2e runs; the one real conversation was "should a solo developer self-host…", one question and answer). Backups exist in `data/backups` per the reaper's schedule if you ever want the raw rows. Implemented by claude (first half) + in-thread (migration, remaining cuts, review fixes); reviewed by a fresh child thread with an independent migration proof.
Option C (approved): the 12 historical machine-run conversations are
e2e-test artifacts with no work worth keeping. Delete /r/<runId> and its
API, the /c redirect into it, hrefFor's and the inspect card's run arms,
the sidebar run glyph render, the preview starter-id run href, and "run"
from every kind enum that routed to it (ConversationKind,
PageContextKind, isItemRunning). run-glyph.tsx and isLiveRun stay — still
live for synthetic harness rows.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
db/machines.ts (getRun, listStageRuns, LIVE_STATUSES, getRunBinding,
MachineError) is deleted — every reader is gone:

- lib/child-status.ts: mr_ ids now return the generic null not-found
  (same shape as any other unknown id).
- lib/agent/tools/inspect.ts: inspectTarget drops the stage-visit
  lookup and the run/stage branches (no conversation can carry those
  kinds again); resolveSandboxTarget and ownerWorkDir drop their
  machine_run arms.
- lib/tool-views/inspect.ts: InspectView.machine and inspectName's run
  branch are dead with it.
- lib/sandboxes/reaper.ts: busySandboxIds drops the LIVE_STATUSES
  machine-run guard; boundToSandbox's runs count is now always 0 (the
  only thing that ever populated it).
- db/sandboxes.ts, db/sandbox-view.ts: the machine_run arms in
  getLeaseProjectId and ownerLabel/ownerHref (the sandbox page's link
  to a dead /r/ route) fall through to the generic cases.
- db/attention.ts: runUnread, the "run" UnreadThread kind, and the
  settled-at unread join are gone — unread is message-based only now.
- db/organize.ts: deleteConversationForever drops the kind==="run"
  glob cascade (no run rows exist to find); loadSidebar's runStatus/
  runParent maps are gone, so a row's own columns are authoritative
  again; conversationParentEdges drops the machine_runs edge.
- db/projects.ts: the delete cascade no longer nulls machine_runs'
  sandbox columns.
- app/api/previews/route.ts: boundSandbox drops the mr_ branch.
- workflows/chat/tools/core.ts: inspect/sandbox_exec descriptions
  drop every mr_ mention.

Tests updated to match (run-scenario cases deleted, non-run cases
kept): child-status, inspect, organize, preview-context, projects,
sandbox-gc, tool-views-info, chat-ui.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
sandboxForMachineRun and sandboxForHarnessSession's run/stage arms are
dead — no conversation can carry those kinds and machine_runs is gone.
ownerLabel keeps treating historical machine_run owners generically
(the live sandboxes rows still say it; nothing new can create one).
attach-sandbox's AttachTarget drops the machine_run owner kind; the
attach tests exercise the generic machinery via a conversation owner.
Deletes every run/stage conversation with all dependent rows (same
teardown order as deleteConversationForever), then drops machine_runs
and machine_stage_runs. The live data is 12 e2e artifacts from
2026-10-10 (the 0048 doc's live-DB evidence); nothing of value is lost.
schema.ts drops both table definitions; 0054_snapshot's isUnique key
normalizes to match drizzle's current emission.

Proven against a seeded worst-case db (run + 2 stage visits + every
dependent kind): after migrate, both tables gone, zero run/stage
conversations, zero orphan mr_ rows, foreign_key_check clean, and the
innocent chat conversation survives with its message.
AGENTS.md's four machine-era notes rewritten (the 0037 phase 5 'what
remains' list, the thread-group parent edge, loadSidebar's run nesting,
the route-storage historical columns). db/schema.ts's kind comment and
db/harness-calls.ts's one-liner drop their references to the dropped
tables. Full suite green at 764.
child-status's route handler, useChildStatus, ChildStatus.href's doc,
and cancel_run's module comment still described machine runs as a kind
of background child or pointed at the deleted run view. Comment-only —
behavior already changed when 0048 purged the tables.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
fix(db,inspect): review fixes — ghost stage sessions swept, dead arms trimmed (0048)
All checks were successful
deploy / checks (pull_request) Successful in 42s
deploy / deploy (pull_request) Has been skipped
402f753f45
Finding 1 (should-fix): 0055's harness_events/harness_runs DELETEs gain
an OR session_id GLOB 'mr_*' sweep — a stage visit's session id could
exist in harness_events with no conversations row (the 0036-era case),
which the conversation-keyed DELETE missed; GLOB's literal underscore
matches exactly the run-prefixed sessions.

Nit 2: resolveSandboxTarget drops the dead mr_ stage-strip (and its
'or run' error text). Nit 3: ChildStatus.kind loses its producerless
"run" member. The remaining inert arms (runEvent 'machine' chips for
old transcripts, isLiveRun's run case, page-context 'machine') stay —
they render historical rows harmlessly.
chad approved these changes 2026-10-18 08:19:36 -04:00
chad merged commit abebbce175 into main 2026-10-18 08:19:43 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chad/sweatshop-legacy!126
No description provided.