GeezerVison is showing github.com — sweep: eliminate write amplification (whole-table rewrites) in PM Stack, queues, bridge · Issue #14865 · developing-today/code
sweep: eliminate write amplification (whole-table rewrites) in PM Stack, queues, bridge #14865DescriptionFind and eliminate write amplification across the PM Stack, the queues, and the bridge: code paths that rewrite an entire table, object, or collection on every small change.
Known seed: a PM Stack quota path was rewriting the entire table every time. Assume it is not the only one.
Method:
- Grep and read for full-replace writes: whole-table rewrites, delete-all-then-reinsert, read-modify-write of entire collections, KV/D1 writes of complete state blobs per event, and console/aggregator paths that republish full state on a single record change.
- For each finding: file or fix. Fixes replace the full rewrite with incremental writes (per-row upserts, deltas, append-only logs with compaction where a log is the honest shape).
- Record each finding on this issue: location, write volume before/after, and the fix PR or the follow-on issue if the fix is large.
Do not "fix" a finding by slowing the write rate — the write itself is the defect.
Filed by Felix on Drewry's direction (2026-11-24). agent-note:v1 — state: filed; Found via: owner direction.
{
"direct_parent": null,
"links": [],
"lineage": {
"design": null,
"roadmap_item": null,
"priority": null
},
"pm_meta": 1,
"provenance": {
"queue_id": null,
"scheduled_start": null,
"picked_up_at": null,
"work_started_at": null,
"created_at": "2026-11-25T05:27:07Z",
"session_id": null,
"lane": null,
"host": "htch-runtime",
"worktree": null,
"model": null,
"lane_start_issues": [],
"workspace_ref": null,
"auth_subject": "felix",
"stamped_by": "fleet 0.1.0 (native)"
}
}
Acceptance criteria
- An inventory of full-rewrite write paths across the PM Stack, the queues, and the bridge is recorded on this issue: location, and write volume before/after for each finding.
- Each finding is either fixed with incremental writes (per-row upserts, deltas, or append-only logs with compaction where a log is the honest shape) or filed as a linked follow-on issue when the fix is large.
- No finding is closed by slowing the write rate — the write itself is the defect.
- The known seed (a PM Stack quota path rewriting the entire table on every change) is explicitly dispositioned: fixed, or a follow-on issue linked.
Activitydeveloping-today commented on Nov 25, 2026 dezren39 commented on Nov 25, 2026 🤖 Agent note · progress — Xaltha (fleet lane xaltha), hourly work-loop 2026-11-24
dezren39 commented on Nov 25, 2026 Progress: PR #14874 is ready for review. In pm-stack/aggregator/src/metadata-store.ts, an unchanged artifact replay previously wrote 5 rows for a fixture with two links: 1 item update, 2 link deletes, and 2 link inserts. The fix skips unchanged rows and updates only changed indexed links.
Evidence: the SQLite trigger oracle failed on pre-fix commit 01befd9c7a2 as intended (Fleet run developing-today-forks/fleet#45556822444), then passed on merged PR head 74b0d4c88fa with 6 tests, 0 failures, and 32 assertions (Fleet run developing-today-forks/fleet#45557331257).
Next slice, after this PR: make a single comment mutation persist only the changed comment record instead of rewriting the full comments collection in pm-stack/aggregator/src/comments.ts. developing-today-fleet commented on Nov 25, 2026 ContributorAuthor More actions Intake review
Fleet monitor intake pass (protocol §5), 2026-11-25.
- Related: companion program issue program: move PM Stack, queues, and all unblocked services to Workers + D1 (Cloudflare-first) #14866 (the structural Cloudflare move); this sweep is its write-amplification counterpart.
- Still live: verified open this run; merged-PR search returned no PR that explicitly resolves this issue (see notes).
- Notes: Filed by Felix on Drew's direction. A merged-PR search for '14865' returned only unrelated number matches, so the sweep is still live. It already carries priority/critical.
- Risks: Medium: full-replace patterns hide in console/aggregator republish paths as well as obvious delete-all-reinsert code; the method in the body covers both.
- Suggested approach: Grep/read for full-replace writes per the body's method, disposition each finding as fix-or-file, and keep the running record on this issue.
🤖 Agent note · filed
developing-today-fleet commented on Nov 25, 2026 ContributorAuthor More actions 🤖 Agent note · claimed — Felix (fleet lane felix)
developing-today-fleet commented on Nov 25, 2026 ContributorAuthor More actions Coordination note from the #14866 (Cloudflare-first migration) design pass: the overlap is recorded in doc/2026-11-25_design_cloudflare-first-migration.md §7 (PR #14940). Agreed split: #14865 owns write shape; #14866 owns placement. The migration's cutover slices CF-2 (#14942, queue→D1) and CF-5 (#14945, PM read surfaces) carry a gate — no component cuts over while a #14865 finding in its path is open and unfixed; the slice fixes it first or waits and says which on its issue. Findings either programme surfaces in the other's territory get filed on the owning issue, not duplicated. Refs #14865 developing-today-fleet commented on Nov 25, 2026 ContributorAuthor More actions
agent: felix
state: sweep-record
issue: 14865
Write-amplification sweep — findings record (lane felix, 2026-11-25)
Swept: pm-stack aggregator, pm-stack console edge, queue code (fleet-queue), pkgs/message-bridge. Fix PR: #14975 (head 78054eb). Nothing below was fixed by slowing write rates.
| # |
Location |
Before |
After |
| 1 |
pm-stack/aggregator/src/remote-stores.ts — createTursoCommentsRemote.saveAll |
Every comment mutation (add, triage, github-result) upserted all N rows of public.shared_comments — the store's only write path passes its full record set |
Only rows whose content changed ship; a single comment mutation ships 1 row; an unchanged re-save ships 0 statements |
| 2 |
pm-stack/aggregator/src/remote-stores.ts — createTursoActionsRemote.saveAll |
Every action mutation upserted all N rows of public.agg_actions (monotonically growing table) |
Same diffing; one action mutation ships 1 row; createdAt order preserved so self-FK parents land before children |
Both remotes now mirror the activity remote's per-row written-content memory (seeded by loadAll), the pattern established by #14836. The server-side upsert change guard stays as a backstop. Tests: 4 new recording-client oracles in test/store-remote-backends.test.ts. Verification: fleet-command run 45580278324 — full aggregator suite 3471 pass / 22 fail (3493 tests); all 4 new tests pass by name; the 22 failures are pre-existing executor-environment timeouts (the 10 gather-quota tick tests fail 10/10 on unmodified main, baseline run 45581703476; the rest are unnamed ~8s environment-bound tests outside the touched files).
Seed disposition (PM Stack quota path)
The quota paths were audited directly. No whole-table rewrite remains in them: gather-quota.ts writes quota records per record with INSERT OR IGNORE, usage snapshots append with ON CONFLICT DO NOTHING (remote-stores.ts), and quota-current.json is a whole-file snapshot written once per ~5-minute gather tick — a snapshot by nature, not a per-event rewrite. The whole-table rewriting behind the original report was the aggregator store pattern: the #turso-writes investigation (Nov 25, comment block in remote-stores.ts) measured the aggregator at ~1.2M rows/hour because the activity store shipped its whole ingestion file per event. That instance was already fixed on main by #14836; findings 1–2 above were the two remaining instances of the same defect in the same file.
Already fixed before this pass (verified on main)
Follow-ons filed
| # |
Location |
Volume |
| #14958 |
pm-stack/aggregator/src/events.ts — audit-event store rechains + rewrites the whole hot-stream file per appended event |
Whole file per event (quadratic until retention partitions); fix needs an append-only-segment redesign of the hash-chain integrity model |
| #14960 |
pm-stack/console/edge/src/edge.ts — DO whole-array puts: audit log (cap 300) per audit event; acts (cap 30) per act; held/taken/handed per claim change |
Whole array per event; per-id a:<id> keys already exist as the fix pattern |
| #14961 |
pm-stack/console/edge/src/direct.ts — whole gh:index blob rewritten per cache set/delete and per stale-touch read |
Whole index (≤240 entries) per op, including on reads |
Checked and clean
pkgs/message-bridge/worker — per-row Durable Object SQL (INSERT OR REPLACE by key; scoped deletes only).
pkgs/fleet/crates/fleet-queue Turso queue — per-row INSERT/UPDATE with claim predicates.
- Aggregator snapshots store — append-only inserts + rollup compaction (honest shape); decision-events — append-only JSONL; item/notification history — append-only.
agg_store_documents — whole-document upsert per save, but the only consumer is the small aa-last-good document; noted, not a finding.
Noted, not filed
- File-mode (non-Turso) actions/comments/activity stores rewrite their whole local JSON file per mutation. That is the store contract's local fallback shape (single canonical file); the production Turso backend is where row volume costs, and it is fixed above.
developing-today-fleet commented on Nov 25, 2026 ContributorAuthor More actions Sweep complete. Fix PR #14975 merged 2026-11-25T09:09:08Z: the comments and actions Turso remotes now ship only changed rows (whole-table rewrite per mutation eliminated; full record in comment 7157919459). The quota-path seed was already fixed on main by #14836. Remaining findings are filed as follow-ons #14958 (audit-event store), #14960 (console edge DO arrays), #14961 (console edge cache index) and will be enqueued for lane work. Closing the sweep issue; the follow-ons carry the remaining fixes. Refs #14865 developing-today commented on Nov 27, 2026 Shepherd (lane any-n, task 24023, 2026-11-27): PR #14874 merged to `main` ( 6781b44). Pre-merge state verified: non-draft, MERGEABLE/CLEAN, checks pass, zero review findings; diff reviewed (conditional upsert on items + links, trailing-index cleanup, write-audit test with named oracle). Issue auto-closed by the merge.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|