Skip to content

fix(workspaces): return 404 for missing workspace files - #857

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixworkspaces-return-404-for-missing-53d844
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixworkspaces-return-404-for-missing-53d844

Conversation

@posthog

@posthog posthog Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • A user who opens a deleted or stale workspace file gets a 500 PREVIEW_LOAD_FAILED instead of a not-found state. Each request also captures an exception in error tracking.
  • requireActiveWorkspaceItemRow throws a plain Error when the row does not exist. The preview and content routes catch only WorkspaceForbiddenError, so the not-found case goes to apiFailure.

Origin

  • Error tracking: issue
  • First signal: 2026-10-13
  • Inbox report: open
  • Likely cause: c869ac8
  • Task started by: auto-start, after the report was rated P3 and ready to fix

Changes

  • A typed WorkspaceItemNotFoundError replaces the plain Error in requireActiveWorkspaceItemRow. The message stays the same, so other callers see no change.
  • The file preview and file content routes map this error to a 404, next to the 403 branch. A 404 does not go through apiFailure, so it captures no exception.
Route Before After
GET …/files/$itemId/preview (missing item) 500 PREVIEW_LOAD_FAILED + exception 404 PREVIEW_NOT_FOUND
GET …/files/$itemId/content (missing item) 500 FILE_LOAD_FAILED + exception 404 FILE_NOT_FOUND

The 404 codes are the same codes that these routes already return when the stored object is missing.

Testing

  • New workspace-file-routes.test.ts: both routes return 404 and record no operational failure. Without the route change, both tests fail with a 500.
  • vp check (format, lint, types): pass.
  • vp test --run --project=node src/features/workspaces: 81 files, 365 tests pass.
  • Skipped: the workers test project and vp build. The change does not touch Durable Object code or the build.

Agent context

  • The deleted item or stale tab cause is a hypothesis. The event does not show which case it was.
  • Other callers of requireActiveWorkspaceItemRow (server functions, AI tools) still treat the error as a generic failure. I did not change them, to keep this PR focused on the reported routes.

Closes #856
Refs #733


Created with PostHog Desktop from this inbox report.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

requireActiveWorkspaceItemRow now throws a typed WorkspaceItemNotFoundError. The file preview and file content routes map it to a 404, so a request for a deleted item does not capture an exception or return a 500.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: 0aa3d0b8-dd54-49d4-9c4c-239fb752b47b
@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d199208-2861-470b-b26c-7c5ebb7ebc6b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit b95c6ce.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Error

0 participants