Repository navigation
[3617 by Claude Opus 5.5] API: JSON errors for malformed bodies and unknown routes, bounded /api/activity paging, basic security headers - #3635
Conversation
…ected existing suites pass, except three suites that fail here for environment reasons and fail the same way with the old code.
What changed, by issue point
1. Bad request bodies and other errors return JSON. A new module, `packages/api/apiErrorBoundary.ts`, does three things:
- An error handler right after the JSON parser in `server.ts` answers 400 (`INVALID_JSON`, or `INVALID_REQUEST_BODY` for a body that won't decompress), 413 (`PAYLOAD_TOO_LARGE`) and 415 (`UNSUPPORTED_MEDIA_TYPE`) before authentication.
- It replaces Express's HTML final handler for the whole app. That covers unhandled errors (500 `INTERNAL_ERROR`, logged on the server only) and errors from the 7 MB archive parser and file uploads.
- No response contains a message, stack or file path from the original error, whatever `NODE_ENV` is.
2. Unknown routes return a JSON 404 (`NOT_FOUND`). I hooked this into Express's final handler rather than adding a last route, because the MCP browser routes under `/mcp` are mounted after startup and a catch-all would have blocked them.
3. `/api/activity` paging is validated. `limit` must be 1–200 (default 50) and `offset` a non-negative integer; anything else, including an empty value, is 400 `INVALID_PAGINATION`.
4. GitHub `branches`/`workflows` routes check owner and repo names. Invalid ones, including `..`, `.` and encoded slashes, get 400 `INVALID_REPOSITORY`.
5. `/api/agent-definitions/templates` works. The alias is now registered before `/:id`, so `templates` is no longer read as an id.
6. Headers:
- `X-Powered-By` is off.
- Every response has `X-Content-Type-Options: nosniff`.
- `Access-Control-Allow-Credentials` is only sent when the request has an allowed `Origin`; the CORS origin rules themselves are unchanged.
- Every 401 gets `WWW-Authenticate: Bearer`, unless the handler set its own (MCP keeps its `resource_metadata` challenge).
7. Unknown task ids return 404 `TASK_NOT_FOUND` from `history`, `live-details` and `file-changes`. A task counts as known if it has a task row, a history row, live worker state or a queued job (new helper `routes/taskExistence.ts`). This check only runs when nothing else was found, so normal requests make no extra queries.
Web UI and CLI
- The web UI already shows the error message when a task fails to load, and the CLI `task` commands already handle 404.
- One CLI change: `implement` polling now keeps waiting for up to 60 s if a just-accepted task isn't known yet, instead of stopping on the first 404.
OpenAPI and changelog: I added the new 404s to the task route docs and regenerated the spec, which also picks up the templates alias. `gen:openapi:check` passes. I added an entry under Fixed in `CHANGELOG.md`.
Tests
- New: `apiErrorBoundaryServer.test.ts` runs every point against the real server wiring; it fails against the old `server.ts`. `apiErrorBoundary.test.ts` and `apiTaskNotFound.test.ts` are unit tests for the helpers and task routes.
- Updated: `agentDefinitionRoutes`, `openapiRouteCoverage` and `openapiResponseConformance` asserted the old behaviour (no templates alias; 200 with empty history for an unknown task). I changed them to expect the new behaviour.
- Unrelated failures: `extensionServerStartup` (symlink module resolution), `taskFollowupDestination` and `mcpWorkflows` (follow-up comment posting) fail here and fail the same way with the old source files swapped back in.
- `file-changes` is covered only by the unit test. In the full-server test it hangs, because core's file-changes cache read tries to reach Redis, which isn't running in this container.
The `/api/mcp` endpoint's own error responses are still `{ "error": "INVALID_REQUEST" }` with no `code`, because an existing test pins that exact shape. The MCP consent pages also still return their intentional HTML 403s.
This is an API-only change with nothing visual, so I made no previews.
|
/ultrafix goal=8 max=6 |
|
🔄 Ultrafix loop started (goal: 8/10, max cycles: 6) First action:
|
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
|
🔀 Resolved merge conflicts from Conflicting Files
Resolution SummaryI resolved the merge conflict. What the conflict was about: The two sides disagreed only on the
How I resolved it: Neither set of numbers is right for the merged code, because each counts only one side's changes. This file is generated from the route sources, so I regenerated it with Why: Regenerating means the file matches the merged sources exactly. Apart from the counts, the regenerated file is identical to the merged text with the markers removed. The generated client types ( Checks:
🤖 Resolution Details
System-triggered merge conflict resolution |
…-5-5-api-json-errors-for-malfo-20261117-0149-myt Automatically resolved merge conflicts after merging target branch into PR branch. Resolved conflicts in: - docs/static/openapi/propr-api.yaml PR: #3635 Model: Claude Opus 5.5
|
CI failed: Full Test Suite Shard 2/4 Please investigate and fix this CI failure.
Failure evidence
|
|
✅ Applied the requested follow-up changes in commit a0aa067 Summary of ChangesI fixed the Shard 2/4 failure: the new test file Cause: All four of its tests passed in CI. But the file imports Fix: I added the same cleanup to this file: an Verification, using the same runner CI uses (
I only ran this one file, not the full Shard 2/4. One of my runs failed to start because the container's disk was full; it passed once space freed up. There was nothing visual in this change, so I made no previews. Review digestRisk-tiered paths
Validation evidence
Diff size: 1 file changed, +4/−1 lines 🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
|
CI failed: Run Full Test Suite Please investigate and fix this CI failure.
Failure evidence
|
…api/test/apiErrorBoundary.test.ts` never exited, so the runner killed it at its 180 s limit. I fixed the Shard 2/4 failure: the new test file `packages/api/test/apiErrorBoundary.test.ts` never exited, so the runner killed it at its 180 s limit. **Cause:** All four of its tests passed in CI. But the file imports `routes/queueRoutes.js` and `routes/githubRoutes.js`, and importing those opens core's SQLite connection. Nothing closed that connection, so the test process stayed alive until the runner killed it. The other two new API suites already close it in an `after` hook. **Fix:** I added the same cleanup to this file: an `after` hook that imports `@propr/core` and calls `closeConnection()`. No production code changed. **Verification**, using the same runner CI uses (`scripts/run-test-suite.mjs`): - Old file: timed out after 180 s, the same failure as CI. - New file: passes in 2.7 s, 4 of 4 tests. - ESLint on the file reports no warnings. I only ran this one file, not the full Shard 2/4. One of my runs failed to start because the container's disk was full; it passed once space freed up. There was nothing visual in this change, so I made no previews. PR: #3635 Comment by: @propr-dev[bot] (ID: 6937287824) Model: Claude Opus 5.5
|
CI failed: Validate unsigned darwin-x64 package Please investigate and fix this CI failure.
Failure evidence
|
|
CI failed: Finalize unsigned validation checksums Please investigate and fix this CI failure.
Failure evidence
|
|
✅ Applied the requested follow-up changes in commit 3f1a4fd Summary of ChangesI fixed the failing Validate unsigned darwin-x64 package check by giving one timing-sensitive desktop test more time. The cause wasn't this PR, which doesn't touch the desktop app; the test file is the same on What failed: one test out of 1,444, The change (only in that test file):
Checks:
These runs were on Linux. Whether the macOS job passes will show on the next CI run. Review digestRisk-tiered paths
Validation evidence
Diff size: 1 file changed, +11/−5 lines 🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
…* check by giving one timing-sensitive desktop test more time. The cause wasn't this PR, which doesn't touch the desktop app; the test file is the same on `main`. I fixed the failing **Validate unsigned darwin-x64 package** check by giving one timing-sensitive desktop test more time. The cause wasn't this PR, which doesn't touch the desktop app; the test file is the same on `main`. **What failed:** one test out of 1,444, `nonzero exit escalates against a TERM-ignoring descendant before releasing the guard` in `apps/desktop/scripts/run-bounded-darwin-command.test.mjs`. In that test, a child process starts a second Node process and waits for it to write its process id to a file. Then it exits with code 23. If the file doesn't appear in time, it exits with 24 instead. The wait was only 1 second, and the busy macOS runner took longer than that to start the second process. The CI log shows the process ended with a non-zero exit but not with 23, which matches. **The change** (only in that test file): - The wait for the file is now 10 seconds, and the overall time limit for the run is now 20 seconds (was 2). The test still checks the same things: the run fails with exit code 23, and the second process, which ignores the normal stop signal, still gets killed. - The single pass/fail check became separate assertions, so a future failure shows the actual exit code (24 means the file never appeared) instead of "validation function returned false". **Checks:** - With the wait set to 0, the test fails with `expected: 23, actual: 24`, the same failure as in CI. - With the fix, all 14 tests in the file pass. These runs were on Linux. Whether the macOS job passes will show on the next CI run. PR: #3635 Comment by: @propr-dev[bot] (ID: 6937758726) Model: Claude Opus 5.5
|
❌ ProPR could not start on the follow-up The ProPR worker refused the job because the disk that holds its working copies is nearly full. Nothing was changed on this pull request. Once space has been freed on the worker host, post the command again. |
|
CI failed: Full Test Suite Shard 2/4 Please investigate and fix this CI failure.
Failure evidence
|
|
✅ Applied the requested follow-up changes in commit 540b80b Processed 2 comments:
Summary of ChangesI made the failing Shard 2/4 test wait properly, but I couldn't make the original failure happen here, so I haven't shown that this change prevents it. Shard 2/4. The failing test is The problem is a race in the test:
The test's last step, which checks that the listeners are gone, has the same race in reverse: the effect cleanup may not have run yet. The fix is in That file passes all 9 tests. The whole Settings page folder passed 297 of 297 tests in each of 3 runs, and lint with zero warnings is clean on the file. Finalize unsigned validation checksums. That failure is on the older commit Review digestRisk-tiered paths
Validation evidence
Diff size: 1 file changed, +4/−1 lines 🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
…dn't make the original failure happen here, so I haven't shown that this change prevents it.
I made the failing Shard 2/4 test wait properly, but I couldn't make the original failure happen here, so I haven't shown that this change prevents it.
**Shard 2/4.** The failing test is `AgentExtensionsOAuth.test.tsx`, a Settings UI test. This PR doesn't touch that file or the code it tests, which are the same on `main`. The test clicks Reconnect, waits for the "Finish signing in…" notice, then fires a window `focus` event and expects one more library read.
The problem is a race in the test:
- React adds the focus listener in an effect that runs just after the notice appears.
- On a busy CI runner, that effect may not have run yet when the test fires `focus`.
- With no listener, nothing happens, so the test sees 1 read instead of 2. That is the reported "expected 1 to be 2".
The test's last step, which checks that the listeners are gone, has the same race in reverse: the effect cleanup may not have run yet.
The fix is in `propr-ui/src/pages/SettingsPage/AgentExtensionsOAuth.test.tsx`. Before each of those two `focus` events, the test now runs `await act(async () => {})`, which makes React finish pending effects. What the test checks is unchanged, and the app code is untouched.
That file passes all 9 tests. The whole Settings page folder passed 297 of 297 tests in each of 3 runs, and lint with zero warnings is clean on the file.
**Finalize unsigned validation checksums.** That failure is on the older commit `a0aa067`. It only reports that the unsigned packaging job failed, which was the darwin-x64 check, and the latest commit `3f1a4fd` already fixed that. I made no change for it.
PR: #3635
Comment by: @propr-dev[bot] (ID: 6938161878)
Comment by: @propr-dev[bot] (ID: 6937760542)
Model: Claude Opus 5.5
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationReady to merge based on the supplied diff and context. The PR addresses API error consistency, input validation, compatibility routing, and unknown-task responses with focused helpers and integration coverage. Current-head checks report 35 passed, none failed or pending. ✅ Safe error responses — The boundary returns fixed JSON messages, removes stale response headers on errors, and keeps internal error details server-side. ✅ Correct route ordering — The templates alias precedes ✅ Preserved response contracts — The changes retain existing MCP authentication challenges and distinguish unknown tasks from tasks represented in persisted, live, or queued state. This was a static review of the supplied code; no commands or tests were run. Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S1: 🟢 Isolate task existence fixturesIn S2: 🟢 Cover CLI polling graceAdd focused coverage for the new grace period in ScoreThe implementation satisfies the reviewed scope without a verified regression, and all current-head checks are successful. Coverage is substantial, with a few optional boundary cases worth adding. Score: 9/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
…n item 5. I left out one part of item 5: the `AI`/`llm-*` labels being applied twice when a PR is created. That should be named in the PR description. The new test file `test/botCommentText.test.ts` passes (16 tests, using the quoted examples as inputs), and so do the existing suites that touch these comments. Lint and typecheck are clean. No file under `src/jobs` gains locking, Redis keys or queue logic. 1. Failed or invalid review comments (`reviewCommentFormatter.ts`, new `reviewCompletionComment.ts`) - Invalid output: "⚠️ Review output was invalid." now gives one of three reasons: - the review output could not be parsed. - the reviewer returned no text. - the review cited files the PR doesn't change. - Invalid output, continued: these comments drop the "Next step: /fix" block and carry the `error="true"` marker. - Provider failure: "❌ Review failed." is always followed by a sentence. An empty error gives "The provider call failed without an error message." - Parent comment: "Posted N reviews" no longer counts error reviews, and failed links are marked "(failed)". It now also says "Posted 0 reviews" instead of "Posted 0 review". The hidden marker that tracks whether a run failed still follows the provider result, so nothing about scheduling changes. 2. Failure comments - PR follow-up failures now open with a plain cause, such as "Provider authentication failed." or "The agent process stopped unexpectedly.", and link to the task. - Comment IDs: "Comment ID: 0" is gone. Real comment IDs keep their `✓` receipts, because polling reads them. - Removed text: "Please check the logs for more details." is gone. - Issue failure comments get the same cause line. - Upstream HTML page titles become the status code, e.g. "403 Attention Required! | Cloudflare" → "HTTP 403". GitHub HTML error pages are reported by status only. - Completion reports no longer show the `<synthetic>` model line, or the token and cost lines when no tokens were used. 3. PR bodies (`logFiles.ts`): the "Detailed Logs" block and the "Latest Conversation Messages" block are replaced by one "View task" link. Log files are still written on the worker. Existing PR bodies are not touched. 4. CI-failure comment: "Commit:" now links to the commit, and a separate "Run:" line links to the job run. 5. Labels and ids - Task ids: the `-undefined-` came from comments with no `updated_at`. The revision id now uses the body digest alone in that case. - `AI` with `AI-done`: the current code already removes `AI` when it adds `AI-done`; a test pins this. The closed issues I checked that kept both (#3512, #3529) were labelled on Nov 13 and show a different label order from this code. My guess is that the running instance was on an older build. - Left out — double labels at PR creation: on #3632 and #3635 the bot applied `AI` and `llm-*` twice, about a second apart. The only label call has a retry delay of at least 2 seconds and isn't reached by the fallback path, so the second call probably comes from a duplicate run. Fixing that is not a text change. To fit the 400-line lint limit I removed a duplicate `sanitizeErrorMessage` from `errorHandlers.ts` (it now imports the shared one) and moved link-building into small helpers. I updated a few existing tests: some used placeholder review text that is now invalid output, and one checked for the conversation preview that was removed. No previews were made, since this only changes comment text.
…, drop internal paths and debug blocks (text only) (#3676) 1. Failed or invalid review comments (`reviewCommentFormatter.ts`, new `reviewCompletionComment.ts`) - Invalid output: "⚠️ Review output was invalid." now gives one of three reasons: - the review output could not be parsed. - the reviewer returned no text. - the review cited files the PR doesn't change. - Invalid output, continued: these comments drop the "Next step: /fix" block and carry the `error="true"` marker. - Provider failure: "❌ Review failed." is always followed by a sentence. An empty error gives "The provider call failed without an error message." - Parent comment: "Posted N reviews" no longer counts error reviews, and failed links are marked "(failed)". It now also says "Posted 0 reviews" instead of "Posted 0 review". The hidden marker that tracks whether a run failed still follows the provider result, so nothing about scheduling changes. 2. Failure comments - PR follow-up failures now open with a plain cause, such as "Provider authentication failed." or "The agent process stopped unexpectedly.", and link to the task. - Comment IDs: "Comment ID: 0" is gone. Real comment IDs keep their `✓` receipts, because polling reads them. - Removed text: "Please check the logs for more details." is gone. - Issue failure comments get the same cause line. - Upstream HTML page titles become the status code, e.g. "403 Attention Required! | Cloudflare" → "HTTP 403". GitHub HTML error pages are reported by status only. - Completion reports no longer show the `<synthetic>` model line, or the token and cost lines when no tokens were used. 3. PR bodies (`logFiles.ts`): the "Detailed Logs" block and the "Latest Conversation Messages" block are replaced by one "View task" link. Log files are still written on the worker. Existing PR bodies are not touched. 4. CI-failure comment: "Commit:" now links to the commit, and a separate "Run:" line links to the job run. 5. Labels and ids - Task ids: the `-undefined-` came from comments with no `updated_at`. The revision id now uses the body digest alone in that case. - `AI` with `AI-done`: the current code already removes `AI` when it adds `AI-done`; a test pins this. The closed issues I checked that kept both (#3512, #3529) were labelled on Nov 13 and show a different label order from this code. My guess is that the running instance was on an older build. - Left out — double labels at PR creation: on #3632 and #3635 the bot applied `AI` and `llm-*` twice, about a second apart. The only label call has a retry delay of at least 2 seconds and isn't reached by the fallback path, so the second call probably comes from a duplicate run. Fixing that is not a text change. To fit the 400-line lint limit I removed a duplicate `sanitizeErrorMessage` from `errorHandlers.ts` (it now imports the shared one) and moved link-building into small helpers. I updated a few existing tests: some used placeholder review text that is now invalid output, and one checked for the conversation preview that was removed. No previews were made, since this only changes comment text. Co-authored-by: propr-dev[bot] <1316198+propr-dev[bot]@users.noreply.github.com>
AI Implementation Summary
Closes #3617
Branch:
3617/claude-opus-5-5-api-json-errors-for-malfo-20261117-0149-mytCommits: ✅ Changes committed (4606293)
AI Processing Completed
Execution Details:
Summary:
I've implemented all seven points of #3617. The new tests and the affected existing suites pass, except three suites that fail here for environment reasons and fail the same way with the old code.
What changed, by issue point
packages/api/apiErrorBoundary.ts, does three things:server.tsanswers 400 (INVALID_JSON, orINVALID_REQUEST_BODYfor a body that won't decompress), 413 (PAYLOAD_TOO_LARGE) and 415 (UNSUPPORTED_MEDIA_TYPE) before authentication.INTERNAL_ERROR, logged on the server only) and errors from the 7 MB archive parser and file uploads.NODE_ENVis.NOT_FOUND). I hooked this into Express's final handler rather than adding a last route, because the MCP browser routes under/mcpare mounted after startup and a catch-all would have blocked them./api/activitypaging is validated.limitmust be 1–200 (default 50) andoffseta non-negative integer; anything else, including an empty value, is 400INVALID_PAGINATION.branches/workflowsroutes check owner and repo names. Invalid ones, including..,.and encoded slashes, get 400INVALID_REPOSITORY./api/agent-definitions/templatesworks. The alias is now registered before/:id, sotemplatesis no longer read as an id.X-Powered-Byis off.X-Content-Type-Options: nosniff.Access-Control-Allow-Credentialsis only sent when the request has an allowedOrigin; the CORS origin rules themselves are unchanged.WWW-Authenticate: Bearer, unless the handler set its own (MCP keeps itsresource_metadatachallenge).TASK_NOT_FOUNDfromhistory,live-detailsandfile-changes. A task counts as known if it has a task row, a history row, live worker state or a queued job (new helperroutes/taskExistence.ts). This check only runs when nothing else was found, so normal requests make no extra queries.Web UI and CLI
taskcommands already handle 404.implementpolling now keeps waiting for up to 60 s if a just-accepted task isn't known yet, instead of stopping on the first 404.OpenAPI and changelog: I added the new 404s to the task route docs and regenerated the spec, which also picks up the templates alias.
gen:openapi:checkpasses. I added an entry under Fixed inCHANGELOG.md.Tests
apiErrorBoundaryServer.test.tsruns every point against the real server wiring; it fails against the oldserver.ts.apiErrorBoundary.test.tsandapiTaskNotFound.test.tsare unit tests for the helpers and task routes.agentDefinitionRoutes,openapiRouteCoverageandopenapiResponseConformanceasserted the old behaviour (no templates alias; 200 with empty history for an unknown task). I changed them to expect the new behaviour.extensionServerStartup(symlink module resolution),taskFollowupDestinationandmcpWorkflows(follow-up comment posting) fail here and fail the same way with the old source files swapped back in.file-changesis covered only by the unit test. In the full-server test it hangs, because core's file-changes cache read tries to reach Redis, which isn't running in this container.The
/api/mcpendpoint's own error responses are still{ "error": "INVALID_REQUEST" }with nocode, because an existing test pins that exact shape. The MCP consent pages also still return their intentional HTML 403s.This is an API-only change with nothing visual, so I made no previews.
Review digest
Risk-tiered paths
packages/api/apiErrorBoundary.ts(added, +133/−0)packages/api/mcp/tools.ts(+1/−1)packages/api/openapi/routeDocsTasks.ts(+10/−2)packages/api/routeRegistry.ts(+2/−0)packages/api/routes/fileChangesRoutes.ts(+11/−0)packages/api/routes/githubRoutes.ts(+15/−4)packages/api/routes/liveDetailsRoutes.ts(+4/−1)packages/api/routes/queueRoutes.ts(+28/−2)packages/api/routes/taskExistence.ts(added, +33/−0)packages/api/routes/taskHistoryRoutes.ts(+5/−1)packages/api/server.ts(+12/−3)packages/cli/src/commands/implementCommands.ts(+16/−1)CHANGELOG.md(+15/−0)docs/static/openapi/propr-api.yaml(+32/−5)packages/api/test/agentDefinitionRoutes.test.ts(+5/−6)packages/api/test/apiErrorBoundary.test.ts(added, +74/−0)packages/api/test/apiErrorBoundaryServer.test.ts(added, +146/−0)packages/api/test/apiTaskNotFound.test.ts(added, +101/−0)packages/api/test/openapiResponseConformance.test.ts(+7/−4)packages/api/test/openapiRouteCoverage.test.ts(+1/−6)Validation evidence
Diff size: 20 files changed, +651/−36 lines
Detailed Logs:
6071e916-e9c0-46ea-988e-83b39a24c8ddLog files stored at:
/usr/src/app/logs/executions/issue-3617-2026-11-17T03-04-19-894Z-conversation.json/usr/src/app/logs/executions/issue-3617-2026-11-17T03-04-19-894Z-output.txtLatest Conversation Messages
This PR was created automatically by ProPR after processing issue #3617.
💡 Need changes?
Comment on this PR to request refinements — the AI agent monitors comments and will update the implementation based on your feedback. Keep iterating until you're satisfied!