Skip to content

fix(api): move the last stop callers to the cancel route and deprecate the stream stop mode - #7835

Merged
mmabrouk merged 3 commits into
release/v0.127.0from
fix/deprecate-stream-stop-mode
Oct 28, 2026
Merged

mmabrouk merged 3 commits into
release/v0.127.0from
fix/deprecate-stream-stop-mode

Conversation

@mmabrouk

@mmabrouk mmabrouk commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Do not merge into main. This PR waits for the next release branch.

Problem

There are two ways to stop an agent turn. POST /sessions/{session_id}/cancel queues a durable stop, and the runner keeps the partial answer. The older stop mode of POST /sessions/streams/ (a call with no inputs and no force) clears the running owner at once. Since v0.124.0 that made the runner drop the partial answer. #7827 made the old path safe, and we agreed to retire it after external callers get notice.

Our own code still called the old stop mode in two places: the /w tab close and the channel !stop command. The web package also kept two helpers that used it.

Change

  • The /w tab close now calls cancelSessionExecution. This path is still switched off (CLOSE_CANCELS_RUN = false), so nothing changes for users today.
  • The channel !stop command now calls SessionCommandsService.request_cancel, the same service the cancel route uses. Both channel dispatchers (API and worker) get the commands service. No channel offers !stop today, so this is also dormant.
  • Removed the unused web helpers cancelSessionStream and commandSessionStream, their response schema, and their test.
  • The set_session_stream route now has an OpenAPI description that marks the stop mode deprecated. The API reference page carries the same note. Send, steer and attach are not deprecated.
  • The route logs each call in stop mode, so we can count the remaining callers before we remove the mode.

The stop mode itself stays. We remove it one or two releases later.

Closing the /w browser tab does not stop a turn

On staging (v0.125.2), closing the /w browser tab during an answer did not stop the turn. This is expected, and this PR does not change it:

  • Nothing in /w sends a stop when the browser tab closes. The code this PR changes in AgentChatPanel.tsx runs when a user closes a session tab inside the chat, not the browser tab.
  • Even that session-tab stop is switched off today (CLOSE_CANCELS_RUN = false in closeSessionCancel.ts). This PR only changes which route it would call if someone turns it on.
  • A turn that keeps running after the browser tab closes is the right behavior. /m works the same way, and the user sees the finished answer when they come back. So this PR adds no stop on browser-tab close.

Tests

  • Channel command tests now assert request_cancel.
  • Removed the test that a channel stop creates an ownerless session row. The new path creates no row.
  • Kept test_cancel_cancels_pending_interactions.py and the "stream cancel" probe row, because the old route is still public. Both have a note to delete them with the mode.
  • Ran 2600 API unit tests (channels and sessions), 2584 @agenta/entities unit tests, and the @agenta/entities and web/oss type checks. All pass.
  • A Codex review approved the change with no regression found.

Before anyone turns on !stop or the tab-close cancel

These gaps existed before this PR:

  • A redelivered message can stop a later turn, because the call sends no idempotency key.
  • The channel reply says "Stopping the current run" even when nothing runs.
  • The channel path does not check that the installation may act on the session.

Agenta Product Agent added 2 commits October 26, 2026 21:57
…e the stream stop mode

The /w tab close and the channel !stop command stopped a turn through the
stop mode of POST /sessions/streams/. They now send the durable cancel that
POST /sessions/{session_id}/cancel sends. The unused web helpers
cancelSessionStream and commandSessionStream are removed. The API reference
marks the stop mode deprecated, and the route logs each call to it so the
remaining callers can be counted before the mode is removed.
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

📘 Docs preview

Status ✅ Ready
Preview https://pr-7835-agenta-docs-preview.mahmoud-637.workers.dev/docs/
Inspect Actions run
Commit 668b4a43597e3faf8f664a1d761303d9c5517b4e

Pages changed in this pull request

This comment updates in place on every push.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4957b15 and 668b4a4.

Files selected for processing: 9
  • api/entrypoints/routers.py
  • api/entrypoints/worker_queues.py
  • api/oss/src/apis/fastapi/sessions/router.py
  • api/oss/src/core/channels/commands.py
  • api/oss/src/tasks/asyncio/channels/inbox.py
  • api/oss/tests/pytest/integration/channels/test_channels_composition_seam.py
  • api/oss/tests/pytest/unit/channels/test_channels_commands.py
  • api/oss/tests/pytest/unit/sessions/test_cancel_cancels_pending_interactions.py
  • api/oss/tests/pytest/unit/sessions/test_insert_paths_require_access.py
Files with no reviewable changes: 1
  • api/oss/tests/pytest/unit/sessions/test_insert_paths_require_access.py
Files skipped from review as they are similar to previous changes: 1
  • api/oss/tests/pytest/unit/sessions/test_cancel_cancels_pending_interactions.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Updates
    • Stopping a run with !stop or closing an eligible chat now uses the session cancellation flow.
  • Documentation
    • The stream endpoint’s stop mode is marked deprecated. Use the session cancellation endpoint to stop a running turn.
    • The stream endpoint documentation clarifies how it sends, steers, or attaches to a turn.

Channel !stop now requests cancellation through SessionCommandsService. The web chat panel uses cancelSessionExecution, and the stream-command and stream-cancellation client APIs are removed. The stream endpoint documents its deprecated stop mode and logs requests that derive cancel mode.

Changes: Session cancellation and stream stop mode

Layer / File(s) Summary
Channel stop dispatch and service wiring
api/oss/src/core/channels/commands.py, api/oss/src/tasks/asyncio/channels/inbox.py, api/entrypoints/routers.py, api/entrypoints/worker_queues.py, api/oss/tests/pytest/integration/channels/*, api/oss/tests/pytest/unit/channels/*, api/oss/tests/pytest/unit/sessions/test_insert_paths_require_access.py
Channel !stop calls SessionCommandsService.request_cancel with project, user, and session IDs. Startup configures the service with the direct control-delivery adapter and passes it to InboxDispatcher. Related tests use the commands service; the ownerless-policy channel test is removed.
Web client cancellation API
web/oss/src/components/AgentChatSlice/AgentChatPanel.tsx, web/packages/agenta-entities/src/session/api/api.ts, web/packages/agenta-entities/src/session/core/schema.ts, web/packages/agenta-entities/src/session/index.ts, web/packages/agenta-entities/tests/unit/session-cancel-stream.test.ts
The chat panel calls cancelSessionExecution when its existing close-time condition is met. The stream-command and stream-cancellation APIs, response schema and exports, and cancellation API test suite are removed.
Deprecated stream stop mode documentation and logging
api/oss/src/apis/fastapi/sessions/router.py, docs/docs/reference/api/set-session-stream.api.mdx, api/oss/tests/pytest/acceptance/sharing/test_private_session_probe.py, api/oss/tests/pytest/unit/sessions/test_cancel_cancels_pending_interactions.py
The endpoint and API documentation describe the deprecated stop condition and direct callers to the cancel endpoint. The route logs project and session IDs when the derived command mode is cancel. Related test comments identify the deprecated mode.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InboxDispatcher
  participant dispatch_command
  participant SessionCommandsService
  InboxDispatcher->>dispatch_command: Dispatch channel command
  dispatch_command->>SessionCommandsService: request_cancel(project_id, user_id, session_id)
Loading

Possibly related issues

  • Agenta-AI/agenta issue 7131: The PR changes the channel !stop cancellation call, but does not change inbox deduplication or add an idempotency key.
  • Agenta-AI/agenta issue 7760: The PR moves channel and web stop callers to cancellation APIs, but does not change runner-side delivery for unscoped runs.
Merge Risk: Minimal · up to 668b4

Legacy stream stop remains available, and built-in channels do not offer !stop. No merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: the last stop callers move to the cancel route, and the stream stop mode is deprecated. The raw summary confirms the channel !stop path, the web helper removal, and th…
Description check Passed The description states the problem, the change, and the scope. It covers the /w tab close and channel !stop callers, the removed web helpers, the deprecation notes, the logging, the tests run, and the…
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.
Full details: Title check

Explanation

The title names the main change: the last stop callers move to the cancel route, and the stream stop mode is deprecated. The raw summary confirms the channel !stop path, the web helper removal, and the OpenAPI deprecation note. The title uses the 'fix(api)' prefix, which fits a deprecation-and-reroute change, and it is 91 characters, slightly long but still specific.

Full details: Description check

Explanation

The description states the problem, the change, and the scope. It covers the /w tab close and channel !stop callers, the removed web helpers, the deprecation notes, the logging, the tests run, and the known gaps. The description is detailed and clearly related to the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 9 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Website preview

Preview URL: https://pr-7835-agenta-website-preview.mahmoud-637.workers.dev

Built from 668b4a43597e3faf8f664a1d761303d9c5517b4e. This comment updates in place on every push.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments: 1
web/oss/src/components/AgentChatSlice/AgentChatPanel.tsx: 1

123-123: Trivial · Data Integrity & Integration · Quick win

Bind close-time cancellation to the observed execution.

When enabled, this call sends neither expectedExecutionId nor idempotencyKey. The endpoint then resolves the current eligible execution. A delayed close request can cancel a later execution that started before the request arrives. Pass the session's tracked execution ID and a stable key for close retries, or keep this path disabled until those values are available.


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between dd43c87 and 4957b15.

Files selected for processing: 16
  • api/entrypoints/routers.py
  • api/entrypoints/worker_queues.py
  • api/oss/src/apis/fastapi/sessions/router.py
  • api/oss/src/core/channels/commands.py
  • api/oss/src/tasks/asyncio/channels/inbox.py
  • api/oss/tests/pytest/acceptance/sharing/test_private_session_probe.py
  • api/oss/tests/pytest/integration/channels/test_channels_composition_seam.py
  • api/oss/tests/pytest/unit/channels/test_channels_commands.py
  • api/oss/tests/pytest/unit/sessions/test_cancel_cancels_pending_interactions.py
  • api/oss/tests/pytest/unit/sessions/test_insert_paths_require_access.py
  • docs/docs/reference/api/set-session-stream.api.mdx
  • web/oss/src/components/AgentChatSlice/AgentChatPanel.tsx
  • web/packages/agenta-entities/src/session/api/api.ts
  • web/packages/agenta-entities/src/session/core/schema.ts
  • web/packages/agenta-entities/src/session/index.ts
  • web/packages/agenta-entities/tests/unit/session-cancel-stream.test.ts
Files with no reviewable changes: 4
  • web/packages/agenta-entities/tests/unit/session-cancel-stream.test.ts
  • web/packages/agenta-entities/src/session/core/schema.ts
  • web/packages/agenta-entities/src/session/index.ts
  • web/packages/agenta-entities/src/session/api/api.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Item Value
Status stopped
Commit 668b4a43597e3faf8f664a1d761303d9c5517b4e
Manual expiry (UTC) Not granted
CI deadline (UTC) Not granted
Workflow https://github.com/Agenta-AI/agenta/actions/runs/40693845028

PR closed or converted to draft. Environment absence verified; retained storage requires separate provider accounting.

Post /preview as a new comment to request a one-hour preview. Repeating it while active does not extend the hour.
Preview data is disposable. Expiry is enforced by the next successful cleanup sweep, not an exact timer.
Environment deletion stops its compute. Provider-retained storage and permanent services may still be billed.

@mmabrouk
mmabrouk changed the base branch from release/v0.125.2 to main October 27, 2026 07:47
@mmabrouk
mmabrouk changed the base branch from main to release/v0.127.0 October 28, 2026 13:06
@mmabrouk mmabrouk added lgtm This PR has been approved by a maintainer merge queue In the release merge queue; an agent is landing it labels Oct 28, 2026
@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says: About the CodeRabbit nitpick on AgentChatPanel.tsx line 123 (close-time cancel sends no expectedExecutionId or idempotencyKey): we are not fixing this in this PR. The close-time cancel is switched off (CLOSE_CANCELS_RUN = false), so the call never runs today. The PR body already lists this gap under "Before anyone turns on !stop or the tab-close cancel". Whoever turns that path on must pass the tracked execution id and a stable key first.

@mmabrouk
mmabrouk merged commit 6187f95 into release/v0.127.0 Oct 28, 2026
83 of 84 checks passed
@mmabrouk mmabrouk removed the merge queue In the release merge queue; an agent is landing it label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant