feat(project): add DELETE /project/:id endpoint (#25004)#25009
Open
georgernstgraf wants to merge 13 commits intoanomalyco:devfrom
Open
feat(project): add DELETE /project/:id endpoint (#25004)#25009georgernstgraf wants to merge 13 commits intoanomalyco:devfrom
georgernstgraf wants to merge 13 commits intoanomalyco:devfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for deleting projects via a new DELETE /project/:projectID endpoint, backed by a new Project.remove(id) service method, and exposed through both the Hono instance routes and the experimental HttpApi surface (for SDK generation). This is intended to let users remove stale projects and rely on DB-level cascading deletes to clean up associated sessions and related data.
Changes:
- Added
Project.remove(id)Effect service method returning{ deleted, sessionsRemoved }. - Added
DELETE /project/:projectIDroute in Hono with OpenAPI metadata (project.delete). - Added matching HttpApi endpoint + handler (
project.delete) and tests covering service + route behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/opencode/src/project/project.ts | Adds remove() implementation and wires it into Project.Service. |
| packages/opencode/src/server/routes/instance/project.ts | Adds Hono DELETE /project/:projectID route + OpenAPI schema. |
| packages/opencode/src/server/routes/instance/httpapi/project.ts | Adds HttpApi delete endpoint and handler mapping to Project.remove. |
| packages/opencode/test/project/project.test.ts | Adds service-level tests for Project.remove. |
| packages/opencode/test/server/httpapi-instance.test.ts | Adds route integration test exercising delete via the Hono bridge. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+469
to
+480
| const existing = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get()) | ||
| if (!existing) throw new Error(`Project not found: ${id}`) | ||
| const sessionsRow = yield* db((d) => | ||
| d | ||
| .select({ count: sql<number>`count(*)` }) | ||
| .from(SessionTable) | ||
| .where(eq(SessionTable.project_id, id)) | ||
| .get(), | ||
| ) | ||
| const sessionsRemoved = sessionsRow?.count ?? 0 | ||
| yield* db((d) => d.delete(ProjectTable).where(eq(ProjectTable.id, id)).run()) | ||
| return { deleted: true, sessionsRemoved } |
| const remove_ = Effect.fn("ProjectHttpApi.remove")(function* (ctx: { | ||
| params: { projectID: ProjectID } | ||
| }) { | ||
| return yield* svc.remove(ctx.params.projectID) |
Comment on lines
+144
to
+153
| await using tmp = await tmpdir({ config: { formatter: false, lsp: false } }) | ||
|
|
||
| const current = await app().request("/project/current", { headers: { "x-opencode-directory": tmp.path } }) | ||
| expect(current.status).toBe(200) | ||
| const project = (await current.json()) as { id: string } | ||
|
|
||
| const response = await app().request(`/project/${project.id}`, { | ||
| method: "DELETE", | ||
| headers: { "x-opencode-directory": tmp.path }, | ||
| }) |
| jsonRequest("ProjectRoutes.delete", c, function* () { | ||
| const projectID = c.req.valid("param").projectID | ||
| const svc = yield* Project.Service | ||
| return yield* svc.remove(projectID) |
Comment on lines
+468
to
+471
| const remove = Effect.fn("Project.remove")(function* (id: ProjectID) { | ||
| const existing = yield* db((d) => d.select().from(ProjectTable).where(eq(ProjectTable.id, id)).get()) | ||
| if (!existing) throw new Error(`Project not found: ${id}`) | ||
| const sessionsRow = yield* db((d) => |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
- Remove TOCTOU window by using delete result changes count instead of a separate existence check - Dispose instance after deleting the current project in both Hono route and HttpApi handler to prevent stale instance cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #25004
Type of change
What does this PR do?
Adds a
DELETE /project/:projectIDendpoint to remove projects and all associated data via cascading foreign keys. Currently, projects can be listed, updated, and created — but never deleted. This leaves stale entries in the database when directories are moved or removed.Changes:
Project.remove(id)— new Effect service method that deletes a project row and returns the count of cascade-deleted sessionsDELETE /project/:projectID— Hono route with OpenAPI annotations (project.delete)DELETE /project/:projectID— HttpApi endpoint for SDK generationThe
sessiontable already hasON DELETE CASCADEonproject_id, so deleting a project row automatically removes all sessions, messages, parts, todos, and session entries.Related issues: #21554 (stale workspace entries), #8083 (manage stored data), #16101 (session lifecycle management).
How did you verify your code works?
Screenshots / recordings
N/A — This is not a UI change.
Checklist