Skip to content

docs(sessions): add PATCH /api/sessions/{sessionId} endpoint and update navigation#200

Merged
sweetmantech merged 12 commits into
mainfrom
docs/patch-session-by-id
May 13, 2026
Merged

docs(sessions): add PATCH /api/sessions/{sessionId} endpoint and update navigation#200
sweetmantech merged 12 commits into
mainfrom
docs/patch-session-by-id

Conversation

@ahmednahima0-beep
Copy link
Copy Markdown
Collaborator

@ahmednahima0-beep ahmednahima0-beep commented May 10, 2026

  • Introduced a new PATCH endpoint for updating session details, allowing renaming or status changes (e.g., archiving).
  • Added detailed request and response schemas for PatchSessionRequest and updated the GetSessionResponse.
  • Updated navigation to include the new PATCH endpoint under the Sessions group in the documentation.

This change enhances the API's functionality by providing a way to modify existing sessions, improving user experience and flexibility.


Summary by cubic

Add docs for PATCH /api/sessions/{sessionId} to rename or archive/unarchive a session. Updated navigation and standardized openapi frontmatter to include the spec path across session pages.

  • New Features
    • PATCH /api/sessions/{sessionId}: optional body (title, status: running|archived, linesAdded, linesRemoved; omitted fields unchanged); returns GetSessionResponse; errors 400/401/403/404/500.

Written for commit 2496fd5. Summary will update on new commits.

Summary by CodeRabbit

  • New Features
    • Added API endpoint to update existing sessions with optional fields, allowing you to modify session title, status (running, completed, failed, archived), and track line additions/removals for better session management.
    • Added complete API documentation for the new session update operation, integrated into the Sessions API reference guide for developer reference.

Review Change Stack

…te navigation

- Introduced a new PATCH endpoint for updating session details, allowing renaming or status changes (e.g., archiving).
- Added detailed request and response schemas for `PatchSessionRequest` and updated the `GetSessionResponse`.
- Updated navigation to include the new PATCH endpoint under the Sessions group in the documentation.

This change enhances the API's functionality by providing a way to modify existing sessions, improving user experience and flexibility.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 10, 2026

📝 Walkthrough

Walkthrough

This PR adds a complete PATCH endpoint for updating sessions. It defines a request schema with optional fields, implements the OpenAPI operation, documents it in MDX, and registers the documentation page in the navigation sidebar.

Changes

Session PATCH Endpoint Documentation

Layer / File(s) Summary
PatchSessionRequest Schema
api-reference/openapi/sessions.json
Defines optional title, optional status (enum: running, completed, failed, archived), and optional linesAdded/linesRemoved (non-negative integers).
PATCH Operation Definition
api-reference/openapi/sessions.json
Adds PATCH /api/sessions/{sessionId} operation that accepts PatchSessionRequest body and returns updated session; documents 200, 400, 401, 403, 404, and 500 responses.
Documentation & Navigation
api-reference/sessions/patch.mdx, docs.json
Creates "Update Session" MDX documentation page referencing the PATCH operation and registers it in Sessions navigation group.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • sweetmantech

Poem

🐰 A patch endpoint hops into view,
With schemas optional, statuses true,
Line counters track what was changed,
Documentation arranged,
Sessions updated in one swift crew! 📋✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a PATCH endpoint for sessions and updating navigation documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/patch-session-by-id

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@api-reference/openapi/sessions.json`:
- Around line 289-305: The PatchSessionRequest.status schema currently allows
null which conflicts with the Session.status enum; update the OpenAPI spec so
PatchSessionRequest.status matches Session.status by removing the null branch
from the anyOf (i.e., only allow the enum strings
"running","completed","failed","archived"), or alternatively add explicit null
semantics (document what null means and update Session.status/model and any
server-side handling in the Session controller to accept null). Ensure the
change references PatchSessionRequest.status and Session.status so generated
clients and server validation share the same contract.

In `@api-reference/sessions/patch.mdx`:
- Line 3: The frontmatter value uses the spec-file-prefixed form instead of the
required METHOD /path format; update the openapi frontmatter (the openapi: key
in api-reference MDX) to use "PATCH /api/sessions/{sessionId}" (i.e., replace
the current '/api-reference/openapi/sessions.json PATCH
/api/sessions/{sessionId}' entry with the canonical "PATCH
/api/sessions/{sessionId}" string) so it follows the required API-reference
openapi format.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a236a7ad-26d0-46fd-9e31-6850b2ee08c4

📥 Commits

Reviewing files that changed from the base of the PR and between 6c1b84b and 24e39e6.

📒 Files selected for processing (3)
  • api-reference/openapi/sessions.json
  • api-reference/sessions/patch.mdx
  • docs.json

Comment thread api-reference/openapi/sessions.json
Comment thread api-reference/sessions/patch.mdx
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="api-reference/openapi/sessions.json">

<violation number="1" location="api-reference/openapi/sessions.json:290">
P2: `PatchSessionRequest.status` permits values (`completed`, `failed`, `null`) that contradict the endpoint’s documented archive/unarchive behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread api-reference/openapi/sessions.json Outdated
- Modified the `status` field in the session schema to only allow "running" and "archived" as valid states, removing "completed", "failed", and null options.
- Updated the description to clarify the purpose of the `status` field for archiving and unarchiving sessions.

This change streamlines the session status options, enhancing clarity in the API documentation.
…te navigation

- Introduced a new PATCH endpoint for updating session details, allowing renaming or status changes (e.g., archiving).
- Added detailed request and response schemas for `PatchSessionRequest` and updated the `GetSessionResponse`.
- Updated navigation to include the new PATCH endpoint under the Sessions group in the documentation.

This change enhances the API's functionality by providing a way to modify existing sessions, improving user experience and flexibility.
- Modified the `status` field in the session schema to only allow "running" and "archived" as valid states, removing "completed", "failed", and null options.
- Updated the description to clarify the purpose of the `status` field for archiving and unarchiving sessions.

This change streamlines the session status options, enhancing clarity in the API documentation.
@sweetmantech sweetmantech force-pushed the docs/patch-session-by-id branch from cd0acea to 578ad7a Compare May 11, 2026 23:16
@sweetmantech
Copy link
Copy Markdown
Collaborator

Finding: PatchSessionRequest schema needs two changes — and one looks like it should change, but actually shouldn't

Verified against the Supabase migration that owns the schema (recoupable/database/supabase/migrations/20260501000000_open_agents_sessions_and_chats.sql) and the route handler in open-agents (apps/web/app/api/sessions/[sessionId]/route.ts).

1. status enum is incomplete

DB ground truth:

status TEXT NOT NULL DEFAULT 'running'
    CHECK (status IN ('running', 'completed', 'failed', 'archived'))

The route handler accepts all 4 values. The current spec only lists 2. Please add completed and failed:

 "status": {
   "type": "string",
   "enum": [
     "running",
+    "completed",
+    "failed",
     "archived"
   ]
 }

2. Two Patch body fields are missing — but only two, not four

The route's UpdateSessionRequest interface looks like it accepts six fields:

interface UpdateSessionRequest {
  title?: string;
  status?: "running" | "completed" | "failed" | "archived";
  linesAdded?: number;
  linesRemoved?: number;
  prNumber?: number;     // ← looks accepted
  prStatus?: "open" | "merged" | "closed";  // ← looks accepted
}

But the route passes the body straight into Drizzle's .set({ ...data }), and Drizzle silently drops keys that don't map to a column. Cross-checking against the migration:

Field DB column Persists?
title title TEXT NOT NULL
status status TEXT ... CHECK (...)
linesAdded lines_added INTEGER DEFAULT 0
linesRemoved lines_removed INTEGER DEFAULT 0
prNumber no column ✗ silently no-op
prStatus no column ✗ silently no-op

So only linesAdded and linesRemoved should be added to the spec. Documenting prNumber / prStatus would mislead callers — the API accepts them without error, but nothing happens.

(prNumber / prStatus being in the handler interface looks like a separate handler-side bug — not something this docs PR should propagate.)

Suggested final shape

"PatchSessionRequest": {
  "type": "object",
  "description": "All fields are optional. Omitted fields are left unchanged.",
  "properties": {
    "title": {
      "type": "string",
      "description": "New display title for the session (rename)."
    },
    "status": {
      "type": "string",
      "enum": ["running", "completed", "failed", "archived"],
      "description": "Lifecycle status. Use `archived` to archive, `running` to unarchive."
    },
    "linesAdded": {
      "type": "integer",
      "minimum": 0,
      "description": "Lines added across the session's commits — cached for session list display."
    },
    "linesRemoved": {
      "type": "integer",
      "minimum": 0,
      "description": "Lines removed across the session's commits — cached for session list display."
    }
  }
}

Reproduce this independently (prompt for your LLM)

If you want your own coding agent to re-derive these findings before applying them, paste this block. It is self-contained — anyone with bash + grep on the monorepo can run it:

You're investigating whether the docs PR for PATCH /api/sessions/{sessionId} accurately describes the endpoint. Treat the Supabase migration as the ground truth, not the route handler's TypeScript interface.

Steps:

  1. Read the route handler at open-agents/apps/web/app/api/sessions/[sessionId]/route.ts (the PATCH export). Note what its UpdateSessionRequest interface says it accepts.

  2. Read open-agents/apps/web/lib/db/sessions.ts for the updateSession function. Confirm it passes the body straight to Drizzle's .set({ ...data }). Note that Drizzle silently drops keys that don't match a column in the schema — no runtime error, no log line, nothing.

  3. Open recoupable/database/supabase/migrations/ and find the migration that creates the sessions table (grep -rln "CREATE TABLE.*sessions\b" database/supabase/migrations/). This is the canonical column list.

  4. For each field in UpdateSessionRequest, check whether a corresponding column exists in the migration. Note the status column has a CHECK (status IN (...)) constraint — that's the authoritative enum.

  5. Build a 3-column table: field → DB column? → persists?. Anything that's "no column" gets silently no-op'd — the route accepts it but nothing changes.

  6. Report which fields should be added to the docs' PatchSessionRequest schema (the persisted ones only), and which enum values should be in the documented status.

Expected finding: docs should document title, status (4 values), linesAdded, linesRemoved. Do NOT document prNumber / prStatus — those are present in the handler interface but have no DB columns, so they're silent no-ops. That's a separate handler-side bug to flag, not something to propagate into the public contract.

…and updates

- Added new endpoints for listing session chats (`GET /api/sessions/{sessionId}/chats`) and creating a session chat (`POST /api/sessions/{sessionId}/chats`).
- Updated the `requestBody` for the existing session chat creation to make it optional.
- Expanded response schemas to include detailed error handling and descriptions for new endpoints.
- Updated navigation in the documentation to include new chat-related pages.

These changes improve the API's functionality and clarity, providing users with more comprehensive tools for managing session chats.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="api-reference/openapi/sessions.json">

<violation number="1" location="api-reference/openapi/sessions.json:445">
P2: `PatchSessionRequest` exposes `linesAdded`/`linesRemoved` as client-writable fields even though they are documented as cached metrics, which makes the request contract inconsistent and likely incorrect.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

],
"description": "Lifecycle status. Use `archived` to archive, `running` to unarchive."
},
"linesAdded": {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: PatchSessionRequest exposes linesAdded/linesRemoved as client-writable fields even though they are documented as cached metrics, which makes the request contract inconsistent and likely incorrect.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At api-reference/openapi/sessions.json, line 445:

<comment>`PatchSessionRequest` exposes `linesAdded`/`linesRemoved` as client-writable fields even though they are documented as cached metrics, which makes the request contract inconsistent and likely incorrect.</comment>

<file context>
@@ -290,9 +436,85 @@
-            "description": "Set to `\"archived\"` to archive the session or `\"running\"` to unarchive it."
+            "description": "Lifecycle status. Use `archived` to archive, `running` to unarchive."
+          },
+          "linesAdded": {
+            "type": "integer",
+            "minimum": 0,
</file context>

Tip: Review your code locally with the cubic CLI to iterate faster.

…istency

- Enhanced descriptions in the session schema to provide clearer definitions for `status`, `linesAdded`, and `linesRemoved` fields.
- Standardized the `openapi` frontmatter format across multiple session-related documentation files for consistency.

These changes improve the clarity and usability of the API documentation, ensuring users have a better understanding of session management functionalities.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@api-reference/openapi/sessions.json`:
- Around line 613-676: Remove the earlier duplicate OpenAPI schema objects for
ChatSummary, ListSessionChatsResponse, CreateSessionChatRequest, and
CreateSessionChatResponse (the first occurrence of each in components.schemas)
so only the later, more complete definitions remain; locate the duplicate
definitions by their schema names (ChatSummary, ListSessionChatsResponse,
CreateSessionChatRequest, CreateSessionChatResponse) and delete the first block
for each, leaving the richer versions intact.
- Around line 230-374: The OpenAPI spec contains a duplicate path definition for
"/api/sessions/{sessionId}/chats"; remove the first (earlier) definition block
so only the more complete second definition remains, ensuring you delete the
entire JSON object for "/api/sessions/{sessionId}/chats" that appears first and
remove any leftover trailing comma so the resulting JSON is valid; verify the
remaining "/api/sessions/{sessionId}/chats" entry (the later one) contains the
desired GET/POST schemas and responses.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3b57ec95-cfc3-4f11-9532-23479d11709c

📥 Commits

Reviewing files that changed from the base of the PR and between 24e39e6 and 5bf38e7.

📒 Files selected for processing (7)
  • api-reference/openapi/sessions.json
  • api-reference/sessions/create-chat.mdx
  • api-reference/sessions/create.mdx
  • api-reference/sessions/get.mdx
  • api-reference/sessions/list-chats.mdx
  • api-reference/sessions/patch.mdx
  • docs.json
✅ Files skipped from review due to trivial changes (6)
  • api-reference/sessions/list-chats.mdx
  • api-reference/sessions/create-chat.mdx
  • api-reference/sessions/create.mdx
  • api-reference/sessions/get.mdx
  • api-reference/sessions/patch.mdx
  • docs.json

Comment thread api-reference/openapi/sessions.json Outdated
Comment thread api-reference/openapi/sessions.json Outdated
ahmednahima0-beep and others added 2 commits May 13, 2026 00:57
- Deleted the `GET` and `POST` endpoints for listing and creating session chats from the API documentation.
- Removed associated schemas such as `ChatSummary`, `ListSessionChatsResponse`, `CreateSessionChatRequest`, and `CreateSessionChatResponse`.
- This cleanup streamlines the documentation by eliminating outdated references, ensuring users have access to the most current API functionalities.
@sweetmantech
Copy link
Copy Markdown
Collaborator

Confirmed — my earlier finding has been implemented on the current branch. api-reference/openapi/sessions.json now:

  • Lists all 4 status enum values (running, completed, failed, archived) matching the DB CHECK constraint
  • Includes linesAdded and linesRemoved (integer, minimum: 0) on PatchSessionRequest
  • Correctly omits prNumber / prStatus (no DB columns — would have been silent no-ops)

Schema matches the suggested final shape. Thanks for the quick turnaround.

Revised the `openapi` field in multiple session-related documentation files to include the path to the OpenAPI specification. This change enhances clarity and consistency across the API documentation for session management functionalities.
Comment thread api-reference/sessions/create-chat.mdx Outdated
---
title: "Create Session Chat"
openapi: "/api-reference/openapi/sessions.json POST /api/sessions/{sessionId}/chats"
openapi: 'POST /api/sessions/{sessionId}/chats'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing information resolution from this endpoint? The JSON path is important, right?

@sweetmantech sweetmantech merged commit e23dbee into main May 13, 2026
3 checks passed
@sweetmantech sweetmantech deleted the docs/patch-session-by-id branch May 13, 2026 21:48
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.

2 participants