Repository navigation
fix(platform): map edge refusals to 4xx, lock skill writers, dedup audio - #3186
Merged
Merged
Conversation
Squash of the wt-3 batch for rebase onto main; the PR body carries the per-finding record.
larryro
force-pushed
the
fix/error-mapping-edge-cases
branch
from
September 4, 2026 03:46
17dad53 to
4e304eb
Compare
larryro
marked this pull request as ready for review
September 4, 2026 03:46
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
deleteSkillForViewerloaded 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 itsSKILL.md); members still getSKILL_FORBIDDEN. Mirrored for agents (deleteAgentForCaller), which have no upload lane to repair through at all.MISSING_SKILL_MD,INVALID_SKILL_MD,FILE_TOO_LARGEwere absent from the route's map and fell through as blank 500s.bundle_zip.tsnow exportsSKILL_BUNDLE_REFUSAL_CODESwith a typedrefuse(), and ONESKILL_ERROR_STATUS(domains/skills/errors.ts, over a sharedappErrorResponse) is built from it and used by the app route and the REST family.normalizedBundleFilesnow 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 declaredowneris never honored, andvisibility: privateis 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.domains/skills/writer-lock.ts— onewithSkillWriterLock(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.GET/PUT/DELETE /api/v1/agents/:slugnow map coded refusals throughdomains/agents/errors.ts(shared with/api/app/agents): 400 / 403 / 422.DELETEanswers 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).lib/rate-limit-response.ts—rateLimitedResponse(RATE_LIMITED+retryAfterMs+ whole-secondRetry-After) andchargeOrgRateLimit(the REST door'schargeLaneshape). All five OneDrive routes use it; Google Drive gets its ownexternal:google-drive-list/-readbuckets (the OneDrive budgets) on list and import.import_filestwins 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 newbindDocumentToSyncdep (pg: a jsonb merge, never a rewrite).findDocumentByExternalIdreturns the stored metadata.findCachedTranscriptwas hardwired to null andcontent_hashnever written. The engine now hashes the bytes it reads anyway, stampscontent_hash, and copies the org's completed transcript on a hit (no compress, no provider call, no ledger write); its pre-check exits oncompleted;queueTranscriptionenqueues only when itsqueuedstamp landed. Org-scoped by construction.Verify-only:
endpointUrlupdate skips the https validation — already fixed on base by fix(platform): serve, govern, and bill models as configured #3161:updateCredentialrefuses a non-https://patch (provider_credentials/service.ts:461-467).assertTriggerValidrefuses 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/projectsbind'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 aSKILL.md-less directory; 7normalizedBundleFilescases (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-Afteron 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—queueTranscriptionenqueues 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 reasonlibrary surface: an admin deletes a malformed skill and agentlibrary surface: upload applies the editor’s owner and sharing ruleslibrary 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 500drive pickers: a spent budget answers 429 with Retry-After on both providersonedrive 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,whisperCallsstays 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
whis2at 660 Hz.Verification
tsc --noEmit: clean.oxlint --type-awareon every touched file: clean.backend:integrationon fresh throwaway tale-db + MinIO (SANDBOX_LLM_GATEWAY_ADMIN_PASSWORDset):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/nulltranscription dedup …—calls=2/1 hashes=null=null ledger=8.4/4.2REST resources: agent refusals …—badSlug=500 forbidden=500 malformed=500 absentDelete=200zip refusals answer 400 …—noSkillMd=500/no-json badFrontmatter=500/no-jsonan admin deletes a malformed skill and agent—skill=422 gone=false agent=422 gone=falseupload applies the editor’s owner and sharing rules—private=200 (installed) owner=user_someone_elseeditor 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)servervitest project: 72 767 passed; the only failures are 2 cases inlib/i18n/messages.test.ts(3 orphan keys such asautomations.trigger.enabledBadge) that fail identically on the untouched base tree, plus 3app/routes/**.test.tsxfiles that belong to thetest:uiproject.Cross-class discoveries (not fixed here)
PUT /automations/{name}/triggersstill accepts an unknown automation name (200) — the/projectsbind answers 404; fix(platform): trigger uniqueness, fair scan, idempotent webhooks #3167 territory.RateLimitExceededError → 429mapping in slightly different shapes (folders,files,tasks,projects,knowledge_entries,webdav, …);rateLimitedResponseis the one to converge on.import_files.tstwins (OneDrive / Google Drive) are near-verbatim copies; this batch applies the same fix to both rather than unifying them.lib/i18n/messages.test.tsis red onmain(3 orphan keys from the automations workbench, e.g.automations.trigger.enabledBadge).