refactor(opencode): serve control docs from HttpApi source - #1398
Conversation
📝 WalkthroughWalkthroughExtracts a new ChangesControl OpenAPI document builder extraction
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts (1)
124-124: ⚡ Quick winNormalize
/docfailures throughcontrolFailurelike the other control handlers.Line 124 only maps success; rejected promises/defects from
controlOpenApi()won’t use the local error response mapping.Suggested patch
.handleRaw("doc", () => - Effect.promise(() => controlOpenApi()).pipe(Effect.map((document) => HttpServerResponse.jsonUnsafe(document))), + Effect.promise(() => controlOpenApi()).pipe( + Effect.map((document) => HttpServerResponse.jsonUnsafe(document)), + Effect.catch(controlFailure), + Effect.catchDefect(controlFailure), + ), )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts` at line 124, The effect pipeline starting with Effect.promise(() => controlOpenApi()) only maps successful responses using Effect.map to return HttpServerResponse.jsonUnsafe(document), but lacks error handling for rejected promises or defects. Add error handling to the effect pipeline (using catchAll or similar approach) that maps failures through the controlFailure function, consistent with how other control handlers normalize error responses, ensuring all failure cases are processed through the same error response mapping.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts`:
- Line 124: The effect pipeline starting with Effect.promise(() =>
controlOpenApi()) only maps successful responses using Effect.map to return
HttpServerResponse.jsonUnsafe(document), but lacks error handling for rejected
promises or defects. Add error handling to the effect pipeline (using catchAll
or similar approach) that maps failures through the controlFailure function,
consistent with how other control handlers normalize error responses, ensuring
all failure cases are processed through the same error response mapping.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8c0e259d-9872-4d9a-ad65-ab8a8560c04b
📒 Files selected for processing (7)
packages/opencode/src/server/control-openapi.tspackages/opencode/src/server/global-openapi-schema.tspackages/opencode/src/server/instance/global.tspackages/opencode/src/server/routes/instance/httpapi/handlers/control.tspackages/opencode/src/server/server.tspackages/opencode/test/server/control-routes.test.tspackages/opencode/test/server/production-boundary.test.ts
Summary
Move the production
/docOpenAPI source onto an HttpApi-owned builder for the control-plane document.Why
The production HttpApi
/dochandler still generated its response by callingControlPlaneRoutes().request("/doc"), which pulled the legacy Hono control route tree back into the production documentation path. This keeps the existing HTTP contract while making the production/docpath independent from that legacy route tree.Related to #936
Related Issue
Related to #936
Human Review Status
Pending
Review Focus
Please focus on the production
/docimport boundary, especially that the handler now callscontrolOpenApi()from a module that does not import the legacy Hono route tree, and thatServer.openapi()remains the only lazy entry point for the legacy spec-generation module.Risk Notes
/docmetadata, global SSE paths, schema refs, and stale/questionexclusion.How To Verify
Screenshots or Recordings
Not applicable: no visible UI changes.
Checklist
bug,enhancement,task,documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.app,ui,platform,harness,ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.P0,P1,P2,P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.Pending,Approved by @<reviewer>, orNot required: <reason>(default isPending; "not required" is restricted to bot-authored low-risk PRs).dev, and my PR title and commit messages use Conventional Commits in English.Summary by CodeRabbit
Refactor
Tests