Skip to content

Revert "fix(agents): reuse Tembo sessions for follow-up changes (#345)" - #356

Open
ryw wants to merge 1 commit into
mainfrom
revert-cap-session-reuse
Open

Revert "fix(agents): reuse Tembo sessions for follow-up changes (#345)"#356
ryw wants to merge 1 commit into
mainfrom
revert-cap-session-reuse

Conversation

@ryw

@ryw ryw commented Jul 31, 2026

Copy link
Copy Markdown
Member

Reverts #345. Fixes #351.

#345 sends follow-up agent changes to POST /session/:id/message on CAP. That endpoint is in the dashboard auth realm (user JWTs) and rejects API keys outright ("Unauthorized - Invalid token"), and no message endpoint exists under /public-api at all — the public session router exposes only create/list/search (verified against tembo/monorepo apps/api/src/server/routes/public-api/task.ts). So every follow-up change on an agent with an existing session 401s, for every user and every key.

TAS maps CAP 401/403 to "Tembo rejected the API key (it may have been rotated or revoked)", which misdiagnosed the problem in #351 and sent the reporter rotating keys.

Reverting restores the pre-#345 behavior (a new CAP session per change), which works. Session reuse can come back once CAP exposes a public-API message endpoint — tracked as TEM-8013; re-land #345 on top of it then.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 31, 2026 17:30
import { afterEach, describe, expect, it, vi } from "vitest";

import { dispatchTemboTask, validateTemboApiKey } from "@/lib/cap-api";
import { validateTemboApiKey } from "./cap-api";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This drops the last test that proves createTemboTask posts to /public-api/session/create with the expected payload, but that helper is still the shared path for new-agent, chat-edit, run-improve, and API requests. Can we keep a small create-path test here so future endpoint/payload regressions are caught without reintroducing the deleted resume behavior?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR reverts the prior change that attempted to reuse Tembo CAP sessions for follow-up agent edits, restoring the earlier behavior of creating a fresh CAP session per change to avoid unauthorized requests against non-public endpoints.

Changes:

  • Remove CAP “resume existing session” plumbing (DB lookup + /session/:id/message dispatch) and always create tasks via /public-api/session/create.
  • Update agent-change request flows (chat, run improvements, API v1) to call createTemboTask directly.
  • Revert documentation/changelog text that described session reuse, and update the generated in-app docs bundle accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
web/src/lib/improvements-api.ts Removes DB helper used to find the latest CAP task for session reuse.
web/src/lib/cap-api.ts Drops resume/dispatch logic and keeps a single “create task” CAP client path.
web/src/lib/api-v1/actions.ts Removes session reuse lookup and switches task dispatch to createTemboTask.
web/src/app/[workspace]/agents/[agent]/chat/actions.ts Removes reuse lookup and always creates a new CAP task for chat-to-edit.
web/src/app/[workspace]/agents/[agent]/runs/[runId]/actions.ts Removes reuse lookup and always creates a new CAP task for run improvements.
web/src/lib/cap-api.test.ts Removes dispatch/resume tests; retains validation coverage for API key checks.
docs/src/content/docs/agent-lifecycle.md Removes documentation describing follow-up edits reusing Tembo sessions.
docs/src/content/docs/changelog.md Removes changelog entry describing session reuse as a fixed behavior.
web/src/lib/docs-content.ts Regenerates the in-app docs bundle to match the updated markdown docs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kevine824-alt

Copy link
Copy Markdown

BLOCKER - Still experiencing same issue when trying to edit/create agent.

image

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.

Unable to create/update agents

3 participants