Skip to content

fix(server): reject requests for missing project directories - #43844

Open
shijiatongxue wants to merge 2 commits into
anomalyco:devfrom
shijiatongxue:fix/reject-missing-project-directory
Open

fix(server): reject requests for missing project directories#43844
shijiatongxue wants to merge 2 commits into
anomalyco:devfrom
shijiatongxue:fix/reject-missing-project-directory

Conversation

@shijiatongxue

@shijiatongxue shijiatongxue commented Aug 21, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #39471

Type of change

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

What does this PR do?

When a saved project directory has been deleted or moved, the instance HTTP middleware now checks the decoded project directory before loading the instance context.

If the directory is missing, the server returns the declared 404 NotFoundError JSON response instead of allowing the request to complete silently without an assistant response. The regression test covers GET /path and POST /session/:sessionID/prompt_async.

How did you verify your code works?

  • Targeted regression test passed: bun test test/server/httpapi-instance.test.ts -t "rejects instance requests for missing project directories" — 1 pass, 0 fail.
  • Full repository typecheck passed: bun run typecheck — 30 successful tasks.
  • The full httpapi-instance.test.ts file had one unrelated 5-second timeout in emits a sync fence header for fixed-workspace mutations; the new regression test passed.
  • Built and manually exercised the desktop dev app.
  • git diff --check passed.
  • Pre-push typecheck passed. Bun 1.4.0 emitted only a version-difference warning against the repository's expected 1.3.14.

Screenshots

Online version reproduction

Fixed version result

Checklist

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

@shijiatongxue
shijiatongxue force-pushed the fix/reject-missing-project-directory branch 3 times, most recently from 1e14ba0 to e1f6e9c Compare August 21, 2026 09:20
@shijiatongxue
shijiatongxue marked this pull request as ready for review August 21, 2026 09:27
@Enough1122

Copy link
Copy Markdown

AI code review — automated review for reference; please use your judgment.

  • packages/opencode/src/server/routes/instance/httpapi/middleware/instance-context.ts:29 — the fs.isDir pre-check adds a filesystem stat to every instance-routed request on the hot path. Alternative worth considering: let store.load fail and map its not-found error to this 404 response, keeping the happy path syscall-free. Non-blocking.
  • instance-context.ts:28 — TOCTOU window between isDir and store.load: harmless today since load surfaces its own error, but the two checks can disagree (symlink swapped out between them). Fine as-is; just be aware.
  • instance-context.ts:26 — make sure isDir sees the same path notion store.load uses (relative dirs, symlink resolution, Windows case-insensitivity); if load canonicalizes differently the pre-check could 404 a directory load would accept.
  • Returning HttpServerResponse.jsonUnsafe(notFound(...)) manually must keep matching the declared 404 error schema exactly — the regression test pins the {name, data:{message}} body, which is good protection against schema drift.
  • Test covers GET and POST prompt_async with exact-body assertions. No blocking issues found.

@shijiatongxue
shijiatongxue force-pushed the fix/reject-missing-project-directory branch from e1f6e9c to 85c0c0c Compare August 21, 2026 22:20
@shijiatongxue

Copy link
Copy Markdown
Author

Following up on the review above. This response is also AI-generated.

I kept the fs.isDir check intentionally. InstanceStore.load may return a cached context after the directory is deleted, and a missing child can resolve through an ancestor repository rather than fail. Therefore, letting store.load handle the not-found case would not cover the regression. I added a regression test for the cached-instance/deleted-directory case and documented the reasoning. The extra stat remains a deliberate correctness trade-off on this request path.

Implemented in commit 3b364d447.

@shijiatongxue
shijiatongxue force-pushed the fix/reject-missing-project-directory branch from 3b364d4 to 1d80c83 Compare August 22, 2026 05:49
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.

Desktop silently returns an empty response when the saved project directory no longer exists

2 participants