fix(cli): stop reporting backend upload failures as bad API keys - #2955
Draft
posthog-eu[bot] wants to merge 1 commit into
Draft
fix(cli): stop reporting backend upload failures as bad API keys#2955posthog-eu[bot] wants to merge 1 commit into
posthog-eu[bot] wants to merge 1 commit into
Conversation
A transient database failure in `getUserIdFromApikey` returned null, which the files service reported as `400 user_not_found`. The CLI showed users a bad-key message and opened an error-tracking issue for each failure. Backend: - `getUserIdFromApikey` now rethrows a query failure instead of returning null, so a backend blip surfaces as a 500, not a missing user. - `checkWriteAppAccess` returns `401 user_not_found` (was 400), matching how `invalid_apikey` behaves on the same route. CLI: - Add a shared `buildTusUploadError` helper that turns a tus failure into a real Error carrying the HTTP status, backend message, and request id. `uploadTUS` and the delta path (`partial.ts`) both use it, so the delta path no longer rejects the raw tus blob that leaked the URL and per-file object key. - The attached `.status` and the new `user_not_found` marker let `isExpectedUserError` classify the auth failure and skip error tracking. Merging this fix cuts a CLI release that also carries the earlier fixes (#2885, #2933, #2934, #2947) that no released build contains yet. Generated-By: PostHog Code Task-Id: c66eba6b-af49-4627-84ac-2c007ed83bc0
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
|
This was referenced Aug 9, 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.



Summary
capgo bundle uploadare told their API key is bad when the backend hiccups, and every failure opens a new error-tracking issue. The exception fired 126 times across 47 fingerprints from 16 installs in 30 days, still firing on 2026-08-09.getUserIdFromApikeyreturnednullfor any Postgres failure, not just a missing user. The files service then returned400 user_not_found, so a transient database blip reached the user as a bad key. On the CLI, the flattened error carried no status anduser_not_foundwas not an expected-error marker, so it was reported as a crash.Changes
getUserIdFromApikeynull500checkWriteAppAccess400 user_not_found401 user_not_found, matchinginvalid_apikeyon the same routeuploadTUS/ deltapartial.tsErrorvia a sharedbuildTusUploadErrorhelper carrying status, backend message, and request idisExpectedUserErroruser_not_found.status(401) and by a new markerA genuine missing user now returns
401and the CLI treats it as an auth error (no error-tracking issue). A transient database fault now returns500, so users are no longer told to rotate a valid key.Merging this fix also cuts a CLI release that carries the earlier merged fixes (#2885, #2933, #2934, #2947) that no released build contains yet.
Test plan
cd cli && bun run typecheck && bun run lint && bun test/test-posthog-exception.mjs— all pass.test-posthog-exception.mjs: a bareuser_not_foundError and a tus error carrying.status = 401are both classified as expected user errors.oxlintclean on the changed backend files.Screenshots
Not applicable — CLI error-classification and backend status-code change, no visual surface.
Checklist
bun run lint:backend && bun run lint.accordingly.
my tests
Agent context
cli/src/build/request.ts) has a third copy of the tus-error shaping. It belongs to a different command than this symptom, so it was left untouched to keep the change scoped.Created with PostHog Desktop from this inbox report.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.