Skip to content

fix(server): report blocked location folders as 403 - #60510

Closed
Hona wants to merge 2 commits into
devfrom
location-access-denied
Closed

Hona wants to merge 2 commits into
devfrom
location-access-denied

Conversation

@Hona

@Hona Hona commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Refs #50951, #56479

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When the server cannot read a project folder, every location-scoped request returned 500 with an empty body. A common cause is macOS privacy settings blocking ~/Documents. The app could only show ClientError: UnexpectedStatus: 500. Now the server returns a typed 403 that names the folder.

Response App shows
Before 500, empty body ClientError: UnexpectedStatus: 500
After 403 LocationAccessDeniedError Location access denied: <folder>. On macOS, the message adds where to check.
flowchart LR
  A["lstat folder<br/>EPERM / EACCES"] --> B["FileSystem node<br/>DirectoryAccessDeniedError"]
  B -->|"Instance boot: defect"| C["locationErrors<br/>catchDefect"]
  C --> D["403 LocationAccessDeniedError"]
Loading
  • Boundary only: core already classifies the denial as DirectoryAccessDeniedError, but instance boot keeps it a defect. locationErrors in packages/server/src/location.ts is the one function that every location boundary uses. It now translates that defect, and any other defect is re-raised unchanged.
  • Protocol: adds LocationAccessDeniedError next to LocationNotFoundError on every endpoint and middleware that declares it, then regenerates the client and openapi.json.
  • Message: macOS servers add Check System Settings > Privacy & Security > Files & Folders.
{
  "_tag": "LocationAccessDeniedError",
  "location": { "directory": "/Users/me/Documents/Default Project" },
  "message": "Location access denied: /Users/me/Documents/Default Project. Check System Settings > Privacy & Security > Files & Folders."
}

How did you verify your code works?

  • The missing-folder test in packages/server/test/fetch.test.ts is now a table that also covers an unreadable folder (chmod 000): 403 on location, session and form endpoints, then 200 after the mode is restored. Windows and root skip that case.
  • Locally on Windows, a folder with a full deny ACL makes realpath fail with EPERM, the same code a macOS privacy denial gives. GET /api/model returned 500 with an empty body before this change and 403 LocationAccessDeniedError after it.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none">
  <style>
    .before { opacity: 0; animation: before 4s ease-in-out infinite; }
    .after { animation: after 4s ease-in-out infinite; }
    @keyframes before { 0%, 35% { opacity: 1; } 45%, 100% { opacity: 0; } }
    @keyframes after { 0%, 35% { opacity: 0; } 45%, 100% { opacity: 1; } }
    @media (prefers-reduced-motion: reduce) { .before, .after { animation: none; } }
  </style>
  <rect x="20.5" y="10.5" width="199" height="51" rx="4" stroke="currentColor" stroke-opacity=".35"/>
  <path d="M32 24h7l2 2.5h11V42H32z" fill="currentColor" fill-opacity=".45"/>
  <g class="before">
    <rect x="64" y="29" width="30" height="8" rx="2" fill="currentColor" fill-opacity=".7"/>
  </g>
  <g class="after">
    <rect x="44.5" y="34.5" width="9" height="7" rx="1.5" fill="currentColor" fill-opacity=".9"/>
    <path d="M46.5 34.5v-2a2.5 2.5 0 0 1 5 0v2" stroke="currentColor" stroke-opacity=".9"/>
    <rect x="64" y="22" width="96" height="5" rx="2" fill="currentColor" fill-opacity=".8"/>
    <rect x="64" y="32" width="130" height="3" rx="1.5" fill="currentColor" fill-opacity=".45"/>
    <rect x="64" y="39" width="104" height="3" rx="1.5" fill="currentColor" fill-opacity=".45"/>
  </g>
</svg>

Screenshots / recordings

Not applicable. The app already shows a declared error's message. This PR makes the server send one.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #50951

Public API: adds LocationAccessDeniedError (403) to the protocol, OpenAPI spec and generated client for all location-scoped endpoints (backwards compatible)

Copilot AI balanced review requested due to automatic review settings October 30, 2026 06:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound. I reproduced the empty 500 on the base by running your new unreadable-folder case as a non-root user (root skips it here). With this PR, all four endpoints return 403 LocationAccessDeniedError and recover to 200 once the folder mode is restored. fetch.test.ts passes and tsc -b in packages/server is clean.

Public API (additive, backwards compatible):

  • New LocationAccessDeniedError schema (_tag, location, message, HTTP 403) in @opencode/protocol/errors, openapi.json and the generated client types.
  • 403 is added to the declared errors of every location-scoped endpoint, and to LocationMiddleware and SessionLocationMiddleware in the protocol client. These requests used to fail with an undeclared 500.
  • TypeScript callers that switch exhaustively over an endpoint's error union get one more member to handle.

Non-blocking follow-up: the app (packages/app/src/workspaces/location.tsx) and the TUI (packages/tui/src/context/location.tsx) treat only LocationNotFoundError as final. A 403 is still retried like the old 500, and there is no prompt equivalent to the missing-folder one. Showing the new error there would close the remaining user-facing part of #50951.

Related: #50951

@Hona
Hona enabled auto-merge (squash) October 30, 2026 06:51
@Hona
Hona disabled auto-merge October 30, 2026 06:51

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit only shortens the macOS hint in the LocationAccessDeniedError message, and I have nothing new to flag. I re-ran the missing-folder and unreadable-folder tests in fetch.test.ts as a non-root user, and both pass. The public API is the same as in my last review: LocationAccessDeniedError (403) is added to the protocol, OpenAPI spec and generated client, which is backwards compatible. Only the macOS message text changed.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants