Skip to content

fix(platform): map edge refusals to 4xx, lock skill writers, dedup audio - #3186

Merged
larryro merged 1 commit into
mainfrom
fix/error-mapping-edge-cases
Sep 4, 2026
Merged

larryro merged 1 commit into
mainfrom
fix/error-mapping-edge-cases

Conversation

@larryro

@larryro larryro commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Eight verified medium findings from the backend deep review — legitimate refusals surfacing as 500s, a broken artifact nobody could delete, an upload door minting states the editor forbids, an unlocked writer on an atomic swap, a re-import that detached documents from prune, and a paid transcription run twice for the same bytes. One commit per finding; two verify-only items checked against base.

Base: 019d0a062 (includes #3160 #3161 #3165 #3167). No migration.

Per-finding outcome

# Finding Outcome Evidence / change
1 A malformed skill bundle cannot be deleted through the API fixed deleteSkillForViewer loaded the document first → 422 on the one operation that needs no parsed document. An org admin can now delete an unreadable bundle (and a bundle directory that lost its SKILL.md); members still get SKILL_FORBIDDEN. Mirrored for agents (deleteAgentForCaller), which have no upload lane to repair through at all.
2 Three authoritative zip-refusal codes map to 500 fixed MISSING_SKILL_MD, INVALID_SKILL_MD, FILE_TOO_LARGE were absent from the route's map and fell through as blank 500s. bundle_zip.ts now exports SKILL_BUNDLE_REFUSAL_CODES with a typed refuse(), and ONE SKILL_ERROR_STATUS (domains/skills/errors.ts, over a shared appErrorResponse) is built from it and used by the app route and the REST family.
3 Upload lane mints retired-private skills and arbitrary owners the editor refuses fixed normalizedBundleFiles now takes the bundle being replaced and applies the editor's rules: a new bundle is attributed to its uploader, a replacement keeps its current owner, a declared owner is never honored, and visibility: private is refused unless the replaced bundle already is (SKILL_PRIVATE_RETIRED, which the skills docs already promised for uploads). Decided before the lock so a refusal never holds it.
4 Editor save and delete skip the per-slug writer lock the swap protocol assumes fixed domains/skills/writer-lock.ts — one withSkillWriterLock (the pg advisory xact lock the upload lane took) now wraps the upload write, the app PUT/DELETE and the REST PUT/DELETE, so no door can land between another's aside-rename and commit-rename.
5 REST agents routes surface AGENT_FORBIDDEN and invalid-slug errors as 500 fixed GET/PUT/DELETE /api/v1/agents/:slug now map coded refusals through domains/agents/errors.ts (shared with /api/app/agents): 400 / 403 / 422. DELETE answers 204, or 404 for an absent agent — the deletion semantics the API reference documents and the skills family already had (it answered {deleted:false} 200).
6 Rate-limit hit returns 500 on OneDrive routes; Google twin unthrottled fixed lib/rate-limit-response.ts — rateLimitedResponse (RATE_LIMITED + retryAfterMs + whole-second Retry-After) and chargeOrgRateLimit (the REST door's chargeLane shape). All five OneDrive routes use it; Google Drive gets its own external:google-drive-list/-read buckets (the OneDrive budgets) on list and import.
7 Re-import flips sync ownership metadata, detaching docs from prune fixed Both import_files twins carry a sync-owned document's binding (sourceMode: auto, syncConfigId, and the selection keys the trash lane reads) through a one-time re-import, and a sync import ADOPTS an unchanged document from an earlier one-time import via a new bindDocumentToSync dep (pg: a jsonb merge, never a rewrite). findDocumentByExternalId returns the stored metadata.
8 Re-registering an audio file re-transcribes completed work at full cost fixed Same-ref re-runs were already fenced by the lease's status guard on base, but identical bytes in a NEW blob paid ffmpeg + provider again: findCachedTranscript was hardwired to null and content_hash never written. The engine now hashes the bytes it reads anyway, stamps content_hash, and copies the org's completed transcript on a hit (no compress, no provider call, no ledger write); its pre-check exits on completed; queueTranscription enqueues only when its queued stamp landed. Org-scoped by construction.

Verify-only:

  • Provider credential endpointUrl update skips the https validation — already fixed on base by fix(platform): serve, govern, and bill models as configured #3161: updateCredential refuses a non-https:// patch (provider_credentials/service.ts:461-467).
  • PUT /automations/{name}/triggers accepts triggers that can never fire — mostly fixed by fix(platform): trigger uniqueness, fair scan, idempotent webhooks #3167: assertTriggerValid refuses a schedule without a parseable cron, an unknown IANA zone, and an event without a name (AUTOMATION_TRIGGER_INVALID). Residual, not in this batch: the route still answers 200 for an automation name that does not exist (no existence check, unlike the /projects bind's 404).

Tests

Colocated vitest (all new cases red on base):

  • core/skills/file_actions.test.ts — admin-only delete of a malformed bundle and of a SKILL.md-less directory; 7 normalizedBundleFiles cases (uploader attribution, declared owner ignored, private refused / kept for its owner, replacement keeps owner, byte-for-byte when nothing changes).
  • core/agents/file_actions.test.ts — admin-only delete of a malformed agent.
  • domains/skills/errors.test.ts — every zip refusal code maps to a 4xx; MISSING_SKILL_MD → 400 with the parser's words; unmapped codes still reach the app handler.
  • domains/skills/writer-lock.test.ts — lock key, lock-before-work inside one transaction, rollback on failure.
  • rest/v1-core.test.ts — agents: 403 / 400 / 422, DELETE 204 then 404 (real temp config tree).
  • lib/rate-limit-response.test.ts, domains/onedrive/routes.test.ts, domains/google_drive/routes.test.ts — 429 + Retry-After on every drive route; Google charges its own buckets.
  • core/onedrive/import_files.test.ts, core/google_drive/import_files.test.ts — binding kept on one-time re-import; adoption on sync import; no-op when already bound; manual stays manual.
  • domains/files/transcription.test.ts — queueTranscription enqueues once for a fresh row, nothing otherwise.

Integration harness (backend:integration, real Postgres + MinIO), new probes:

  • library surface: zip refusals answer 400 with the parser’s reason
  • library surface: an admin deletes a malformed skill and agent
  • library surface: upload applies the editor’s owner and sharing rules
  • library surface: editor save and delete wait for the per-slug writer lock (holds the advisory lock in a transaction; PUT and DELETE must wait, then land)
  • REST resources: agent refusals map to 400/403/422/404, never 500
  • drive pickers: a spent budget answers 429 with Retry-After on both providers
  • onedrive re-import keeps the sync binding; sync import adopts a one-time doc (fake Graph, real engine: re-imported file stays bound and is pruned when the source vanishes; one-time doc adopted unchanged)
  • transcription dedup: identical bytes reuse the completed transcript (second blob, same bytes: completed, whisperCalls stays 1, ledger unchanged)

Two fixtures needed distinct bytes once dedup was real: the transcription check's failure step uses an 880 Hz WAV, and the fake yt-dlp renders whis2 at 660 Hz.

Verification

  • Platform tsc --noEmit: clean. oxlint --type-aware on every touched file: clean.
  • backend:integration on fresh throwaway tale-db + MinIO (SANDBOX_LLM_GATEWAY_ADMIN_PASSWORD set):
    • branch: 390 PASS / 0 FAIL (all eight new probes green).
    • base (019d0a062 + this harness): 382 PASS / 8 FAIL — the eight failures are exactly the eight new probes:
      • onedrive re-import … — reimport → manual/null (want auto/cfg) pruned=false; adopt … after=manual/null
      • transcription dedup … — calls=2/1 hashes=null=null ledger=8.4/4.2
      • REST resources: agent refusals … — badSlug=500 forbidden=500 malformed=500 absentDelete=200
      • zip refusals answer 400 … — noSkillMd=500/no-json badFrontmatter=500/no-json
      • an admin deletes a malformed skill and agent — skill=422 gone=false agent=422 gone=false
      • upload applies the editor’s owner and sharing rules — private=200 (installed) owner=user_someone_else
      • editor save and delete wait for the per-slug writer lock — put: landed:200 … delete: landed:200 (wrote straight through)
      • drive pickers: a spent budget answers 429 … — onedrive=500/no-json google=200 (unthrottled)
  • Whole server vitest project: 72 767 passed; the only failures are 2 cases in lib/i18n/messages.test.ts (3 orphan keys such as automations.trigger.enabledBadge) that fail identically on the untouched base tree, plus 3 app/routes/**.test.tsx files that belong to the test:ui project.

Cross-class discoveries (not fixed here)

  • REST PUT /automations/{name}/triggers still accepts an unknown automation name (200) — the /projects bind answers 404; fix(platform): trigger uniqueness, fair scan, idempotent webhooks #3167 territory.
  • Eight more app domains hand-roll the same RateLimitExceededError → 429 mapping in slightly different shapes (folders, files, tasks, projects, knowledge_entries, webdav, …); rateLimitedResponse is the one to converge on.
  • The two import_files.ts twins (OneDrive / Google Drive) are near-verbatim copies; this batch applies the same fix to both rather than unifying them.
  • lib/i18n/messages.test.ts is red on main (3 orphan keys from the automations workbench, e.g. automations.trigger.enabledBadge).

@larryro larryro changed the title fix(platform): map edge refusals to real status codes and fix drive edges fix(platform): map edge refusals to 4xx, lock skill writers, dedup audio Sep 3, 2026
Squash of the wt-3 batch for rebase onto main; the PR body carries the per-finding record.
@larryro
larryro force-pushed the fix/error-mapping-edge-cases branch from 17dad53 to 4e304eb Compare September 4, 2026 03:46
@larryro
larryro marked this pull request as ready for review September 4, 2026 03:46
@larryro
larryro merged commit 7471d98 into main Sep 4, 2026
23 checks passed
@larryro
larryro deleted the fix/error-mapping-edge-cases branch September 4, 2026 03:50
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