Skip to content

fix(platform): close eight low-severity reliability leaks and races - #3191

Merged
larryro merged 2 commits into
mainfrom
fix/low-reliability-leaks-races
Sep 4, 2026
Merged

larryro merged 2 commits into
mainfrom
fix/low-reliability-leaks-races

Conversation

@larryro

@larryro larryro commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Eight verified low-severity reliability defects (leaks, races, silent starvation) from the backend
deep-review triage, fixed with the invariant encoded where it belongs (schema or transaction), each
locked by a red-on-base regression test; one finding verified as already fixed.

Per-finding outcome

# Finding Outcome Evidence / fix
1 Abandoned presigned uploads leak blobs forever fixed 0067 intents recorded the blob but the mint-path sweep dropped only the expired row (same in the REST twin). sweepUploadIntents (files/upload-intents.ts) now reclaims the blob of an intent that expired unconsumed and unvouched-for, then the row — on both ledgers; ownsUploadedBlob stamps bound_at_ms (0073) because the document multi-bind and outbound-mail-attachment lanes prove ownership without consuming (an outbound attachment lives only as a storageId in message metadata, so "unconsumed" is not "unbound"). File-backed refs are excluded by an EXISTS guard; a failed delete keeps the row for the next sweep.
2 Captions finalizer can overwrite a user's cancel with completed fixed Both finalizers run file row + RAG job + terminal patch in one tx with the patch CAS'd on indexing (finalizeVideoLinkFile); a lost CAS rolls back and reaps the blob. Mirror race closed too: cancelVideoLink is a CAS on the state the user saw (advances with an in-flight job, leaves a settled one alone).
3 Deadline watchdog fails the run but leaves the sandbox exec running fixed runTaskAgentWatchdog calls sessionCancelExec(run.sessionId, run.execId) (best-effort) after winning the settle and before cancelling the op row — the in-chain deadline cut's seam.
4 Approval gate can mint duplicate pending rows for one operation fixed 0072: partial unique index (org_id, resource_type, resource_id) WHERE resource_type = 'connector_operation' AND status = 'pending' (existing dup pendings closed the review lane's way: rejected + metadata.supersededBy); the gate inserts ON CONFLICT … DO NOTHING and the loser re-reads the winner's record.
5 Sync scan silently starves configs beyond the first 1000 fixed runSyncScanWith (OneDrive + Google Drive) is a keyset walk in id order (the #3167 trigger-scanner idiom), pageSize option for tests.
6 deregisterDomain races concurrent registration without a transaction fixed registerDomain, registerUrlList, deregisterDomain each run as one transaction; removal takes the websites row FOR UPDATE first, so the "last member?" check can never run between a registration's two writes.
7 Agent upsert idempotency lacks a unique index — concurrent runs fork duplicates fixed 0071: partial unique (org_id, external_item_id) WHERE external_item_id IS NOT NULL (existing newer duplicates detached from the key, old key kept in metadata.dedupedExternalItemId; the redundant plain index dropped). upsertAgentDocument, ensureProjectTextDocument and the sync engine's createDocument insert ON CONFLICT … DO NOTHING and refresh the winner's row on a lost race; project-text now brings a trashed twin back in place instead of parking a duplicate key.
8 Custodian-held rows can starve document/chat purge batches forever fixed The custodian filter is part of the candidate SQL on every pass (documents A/B, chat A/B); pass A also gained the created_by IS NULL arm (NULL <> ALL(...) is NULL, so creator-less synced documents never expired under any hold).
9 Per-user bell writes emit org-wide realtime hints already fixed by #3164 (0f5f024da): every write routes through emitBellHint, which passes userId; the outbox narrows on user_id IS NULL OR user_id = $me.

Tests

Unit (vitest server, 8 files / 30 tests — 21 red on the base tree, every file red):
watchdogs, onedrive scan, crawl tx shape, gate claim, agent-write claim, retention SQL filter,
upload-intent stamp + sweep, video finalizer CAS + cancel CAS.

Integration (backend/integration-check.ts), 9 probes — abandoned upload reclaimed while bound and
vouched-for blobs survive (both ledgers, real MinIO); crawl removal racing registration ×8 rounds;
finalizer never overwrites a cancel + reaps the orphan blob; concurrent gate evaluations share one
card; concurrent agent upserts converge on one row; project-text concurrent saves + trashed twin
comes back; 1001 held trashed docs do not starve the unheld one; 1001 sync configs all enqueued;
deadline watchdog cancels the exec (fake spawner records the call).

Verification

  • platform tsc --noEmit: 0 errors; oxlint --type-aware on touched files: clean
  • backend:integration (throwaway tale-db + MinIO, fresh per run): branch 392/394,
    base + probes 383/394 (the 11 base failures = the 9 new probes + the same 2 pre-existing failures the branch shows: blob-ref authority compose and outbound send lane, byte-identical on both trees)

Cross-class discoveries (not in this batch)

  • The harness's 2FA lifecycle probe (#3187) enabled/disabled 2FA on the shared harness cookie;
    Better Auth's two-factor plugin deletes the calling session on both, so every later cookie-based
    probe failed (ERR, 401) and checkAutomations died on a 404 Not Found body — on main too.
    Fixed here in the harness (throwaway session for those calls).
  • blob-ref authority: outbound mail attaches only the sender's uploads answers 403 FORBIDDEN
    instead of 403 attachment_not_owned on main as well — the conversation write gate from #3187
    now refuses before the ownership check; the probe's expectation needs a decision.
  • A retry racing a finalizer at indexing (both at the same status) is not distinguished by the
    status CAS alone; a storage_ref guard would close it (the clone lane has no prior patch to key on).

Squash of the wt-3 batch for rebase onto main; the PR body carries the per-finding record.
getOrCreateProjectFolder looked the folder up, then created it; two concurrent saves into a fresh folder (the project-text panel, two syncs) could both miss the lookup, and the loser's create refused with FOLDER_NAME_TAKEN — one of three concurrent project-text saves answered 400 in the integration check while the documents themselves converged on one row. The loser now re-reads the winner's folder and files into it.
@larryro
larryro force-pushed the fix/low-reliability-leaks-races branch from 3ac4150 to 5d267e2 Compare September 4, 2026 04:00
@larryro
larryro marked this pull request as ready for review September 4, 2026 04:00
@larryro
larryro merged commit 1207791 into main Sep 4, 2026
23 checks passed
@larryro
larryro deleted the fix/low-reliability-leaks-races branch September 4, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant