feat(api): add single-session status HTTP endpoint#29244
feat(api): add single-session status HTTP endpoint#29244hemanthreddykoduru wants to merge 6 commits into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: I found a potential duplicate: PR #29165: fix(opencode): expose single session status endpoint This PR appears to be directly related to the current PR #29244. Both are about exposing/adding a single session status endpoint. PR #29165 uses the |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new API route to fetch the status for a single session by ID, complementing the existing “all sessions status” endpoint.
Changes:
- Added
GET /session/:sessionID/statusendpoint definition to the session HTTP API. - Implemented
singleStatushandler and registered it in the session handler group.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts | Adds and wires a singleStatus handler that fetches status for a specific session. |
| packages/opencode/src/server/routes/instance/httpapi/groups/session.ts | Defines the new singleStatus route path and OpenAPI-described endpoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const singleStatus = Effect.fn("SessionHttpApi.singleStatus")(function* (ctx: { params: { sessionID: SessionID } }) { | ||
| yield* requireSession(ctx.params.sessionID) | ||
| return yield* statusSvc.get(ctx.params.sessionID) | ||
| }) | ||
|
|
||
| const requireSession = Effect.fn("SessionHttpApi.requireSession")(function* (sessionID: SessionID) { | ||
| return yield* SessionError.mapStorageNotFound(session.get(sessionID)) | ||
| }) |
| yield* requireSession(ctx.params.sessionID) | ||
| return yield* statusSvc.get(ctx.params.sessionID) |
| HttpApiEndpoint.get("singleStatus", SessionPaths.singleStatus, { | ||
| params: { sessionID: SessionID }, | ||
| query: WorkspaceRoutingQuery, | ||
| success: described(SessionStatus.Info, "Get single session status"), | ||
| error: [HttpApiError.BadRequest, ApiNotFoundError], | ||
| }).annotateMerge( | ||
| OpenApi.annotations({ | ||
| identifier: "session.singleStatus", | ||
| summary: "Get single session status", | ||
| description: "Retrieve the current status of a specific session.", | ||
| }), | ||
| ), |
| }) | ||
|
|
||
| const getStatus = Effect.fn("SessionHttpApi.getStatus")(function* (ctx: { params: { sessionID: SessionID } }) { | ||
| yield* requireSession(ctx.params.sessionID) |
| export const SessionPaths = { | ||
| list: root, | ||
| status: `${root}/status`, | ||
| singleStatus: `${root}/:sessionID/status`, |
| HttpApiEndpoint.get("getStatus", SessionPaths.singleStatus, { | ||
| params: { sessionID: SessionID }, | ||
| query: WorkspaceRoutingQuery, | ||
| success: described(SessionStatus.Info, "Get single session status"), | ||
| error: [HttpApiError.BadRequest, ApiNotFoundError], | ||
| }).annotateMerge( | ||
| OpenApi.annotations({ | ||
| identifier: "session.getStatus", |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
| yield* requireSession(ctx.params.sessionID) | ||
| return yield* statusSvc.get(ctx.params.sessionID) |
There was a problem hiding this comment.
Keeping requireSession intentionally. statusSvc.get() reads from an in-memory Map (via InstanceState.get) and always returns { type: "idle" } for any unknown sessionID — it never fails. Removing requireSession would cause this endpoint to return 200 idle for completely non-existent sessions instead of a proper 404. The two calls serve different purposes: requireSession validates session existence against storage, statusSvc.get reads runtime status from memory.
Issue for this PR
Closes #29166
Type of change
What does this PR do?
SessionStatus.Servicealready had aget(sessionID)method but no dedicated HTTP endpoint. OnlyGET /session/statusexisted (returns all sessions). This addsGET /session/:sessionID/statusthat callsget()directly and returns 404 when the session doesn't exist.How did you verify your code works?
Built locally and confirmed the new route registers correctly in the HTTP API group alongside the other single-session endpoints.
Screenshots / recordings
N/A
Checklist