Skip to content

fix: an attachment sent as the first message of a new chat renders (M3 regression) - #7809

Merged
mmabrouk merged 1 commit into
release/v0.125.0from
fix/m3-attachment-first-send
Oct 26, 2026
Merged

mmabrouk merged 1 commit into
release/v0.125.0from
fix/m3-attachment-first-send

Conversation

@mmabrouk

Copy link
Copy Markdown
Member

Ships in v0.125.0. Fixes an M3 regression found by CI after #7791, #7780 and #7789 merged.

Context

In /w, the first message of a new chat was never sent. The composer showed "Message wasn't sent, try again" and no run started. CI caught it with the web acceptance test agent-chat/attach-send-render-reload.spec.ts, which sends an image as the first message. The test fails on #7791, #7780 and #7789 and passes on #7804, which has no M3. Every new /w chat had the problem, not only chats with an attachment; this spec is the only web acceptance test that sends a real first message.

The cause: M3 makes a person's new chat private. To keep /w chats shared with the project, /w creates the session first with a header call that carries only the visibility:

PUT /api/sessions/streams/header?session_id=<id>&visibility=project
body: {}

The header route refused any body without name or description (a rule added earlier so the agent's rename tool cannot send a wrapped body):

422 {"detail":[{"type":"value_error","loc":["body"],"msg":"Value error, no header field to update; send name or description at the top level", ...}]}

So the pre-create failed, and /w never sent the run.

Changes

  • A header call with a visibility and no header field now only creates the session, with the requested visibility. On a session that already exists it changes nothing and returns the row.
  • Without a visibility, a body with no header field is still refused with the same 422. The rename tool cannot set visibility (its path is fixed and the model fills only the body), so its rule does not change.
  • A visibility-only call is checked like a send (RUN_SESSIONS), not like a rename (EDIT_SESSIONS). Without this, a member's first send into a colleague's project chat that has no answer yet would fail with 403. A rename still needs the edit right. A hidden session still answers the not-found body.

Before: PUT header?visibility=project with {} answered 422, and the /w send stopped there.
After: it answers 200. A new session is created as project-visible, owned by the person. An existing session is returned unchanged.

No request is added. The /w pre-create already existed; it now succeeds.

Tests / notes

  • New API acceptance tests in test_header_precreate.py:
    • a visibility-only call creates a project session;
    • on an existing session it changes nothing;
    • an empty body without a visibility is still 422;
    • a member's call on a colleague's project chat passes and changes nothing, and his rename is still 403;
    • a call on a hidden chat answers 404.
      These failed before the fix (the colleague case fails with the old edit check).
  • The failing Playwright spec passes against a local stack with this fix. It fails at the same step as CI (waiting for /invoke) when the old rule is put back.
  • Unit, integration and count tests, and the sharing and sessions acceptance suites pass on OSS and EE. Codex xhigh reviewed the fix.

What to QA

  • /w: open an agent's playground, start a new chat, attach an image and send. The message and the image appear, and the image is still there after a reload.
  • /w: start a new chat and send a text message. It sends; the chat is visible to other project members.
  • Regression: rename a chat in /w and in /m. The name sticks. A project member who is not the owner cannot rename it.

…3 regression)

Every first message of a new /w chat failed with "Message wasn't sent". M3 makes a
person's new chat private, so /w first creates the session with a header call that
carries only visibility=project and an empty body. The header route refused any body
without name or description (422 "no header field to update"), so the pre-create
failed and /w never sent the run. CI saw it in the web acceptance test
agent-chat/attach-send-render-reload.spec.ts.

A header call with a visibility and no header field now only creates the session
with that visibility. It is checked like a send (RUN_SESSIONS), so a member's first
send into a colleague's project chat passes too. On an existing session it changes
nothing and returns no session data (a send right does not include reading it). A
body with no header field and no visibility is still refused with the same 422, and
a rename still needs EDIT_SESSIONS. No request is added.
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

📘 Docs preview

Status ✅ Ready
Preview https://pr-7809-agenta-docs-preview.mahmoud-637.workers.dev/docs/
Inspect Actions run
Commit 6b77659bc58148ff5121d9300db25c5c6099a5c3

This comment updates in place on every push.

@mmabrouk

Copy link
Copy Markdown
Member Author

🤖 The AI agent says:

Verification for 6b77659bc5.

How I found the cause: I read the Playwright trace of the failing CI run on #7789 (job 121327788503). The upload POST /sessions/attachments answered 200. The next request, PUT /sessions/streams/header?visibility=project with body {}, answered 422 "no header field to update". No /invoke request followed, and the composer showed "Message wasn't sent".

Results on a local stack:

  • agent-chat/attach-send-render-reload.spec.ts: it fails at the same step as CI (waiting for /invoke) when the old rule is put back. It passes with the fix: twice in clean runs, plus one run that timed out on a slow page reload after the send had already rendered.
  • test_header_precreate.py (5 cases): passes on OSS and EE. Before the fix it failed; the colleague case fails with the old edit check.
  • Unit: OSS 1474 passed, EE 2436 passed. Integration and count tests: OSS 217 passed, EE 217 passed.
  • Sharing and sessions acceptance: OSS 93 passed, EE 149 passed. One upload test timed out under box load (about 40). It passed when rerun alone on both editions.

Codex xhigh reviewed the fix in 3 rounds:

  • Round 1 found that a member's pre-create on a colleague's project chat was refused with 403. Fixed: the call is now checked with RUN_SESSIONS.
  • Round 2 found that the call returned an existing session's data to a role that can send but not view. Fixed: it now returns no data for an existing session.
  • Round 3: no blocking issue.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Summary

Summary by CodeRabbit

  • New Features
    • Visibility-only requests can now pre-create sessions without changing existing sessions.
  • Bug Fixes
    • Empty header requests without visibility continue to return a validation error. Session permissions are checked according to whether a request creates a session or edits its header.
  • Documentation
    • Clarified when visibility-only requests create sessions and when empty requests are rejected.

The header endpoint now accepts visibility-only requests to create sessions. It uses RUN_SESSIONS for requests without header fields and EDIT_SESSIONS for requests with them. Existing session rows remain unchanged for visibility-only requests.

Changes: Session Header Pre-creation

Layer / File(s) Summary
Header request handling
api/oss/src/core/sessions/streams/dtos.py, api/oss/src/apis/fastapi/sessions/router.py
SessionStreamHeaderEdit now reports whether either header field was supplied. The endpoint accepts a request without header fields when visibility is provided, returns 422 when it is absent, and selects the authorization action based on header-field presence.
Session creation and validation
api/oss/src/core/sessions/streams/service.py, api/oss/tests/pytest/acceptance/sharing/test_header_precreate.py, api/oss/tests/pytest/unit/sessions/test_stream_header_merge.py, docs/design/sharing-program/interfaces/m3/interfaces.md
The service creates a session row for a visibility-only request when no row exists. If a row already exists, it leaves that row unchanged. Tests and interface documentation cover these outcomes and related authorization cases.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant set_session_stream_header
  participant SessionStreamsService.set_header
  participant _create_header_row
  Caller->>set_session_stream_header: Send visibility-only request
  set_session_stream_header->>SessionStreamsService.set_header: Pass session and access policy
  SessionStreamsService.set_header->>_create_header_row: Create row when header fields are absent
  _create_header_row-->>SessionStreamsService.set_header: Return created row or None for existing row
  SessionStreamsService.set_header-->>set_session_stream_header: Return result
  set_session_stream_header-->>Caller: Return response
Loading
Merge Risk: Low · up to 6b776

A narrow channel-session metadata exposure remains possible, and the documented response is misleading. Correct both before merge or explicitly accept the bounded risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 files. (1 skipped: … 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 accurately identifies the M3 regression addressed by the changes. The session header pre-creation fix enables the first message, including attachments, to send and render in a new chat.
Description check Passed The description clearly explains the 422 failure, the visibility-only session creation behavior, permission checks, unchanged existing-session behavior, tests, and QA steps. It is directly related to …
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: Description check

Explanation

The description clearly explains the 422 failure, the visibility-only session creation behavior, permission checks, unchanged existing-session behavior, tests, and QA steps. It is directly related to the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 37.50% which is insufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 5 files. (1 skipped: 1 unsupported.)

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.

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

Actionable comments posted: 2


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between a2cc36a and 6b77659.

Files selected for processing: 6
  • api/oss/src/apis/fastapi/sessions/router.py
  • api/oss/src/core/sessions/streams/dtos.py
  • api/oss/src/core/sessions/streams/service.py
  • api/oss/tests/pytest/acceptance/sharing/test_header_precreate.py
  • api/oss/tests/pytest/unit/sessions/test_stream_header_merge.py
  • docs/design/sharing-program/interfaces/m3/interfaces.md

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

Comment on lines +1375 to +1379
created = await self._create_row(
project_id=project_id,
user_id=user_id,
stream=SessionStreamCreate(session_id=session_id, access=access),
)

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.

Minor · Security & Privacy · Quick win

🔎 Supported by static analysis

Script executed:

#!/bin/bash
# Inspect the policy substitution and the channel-session RUN decision.
ast-grep outline api/oss/src/dbs/postgres/sessions/streams/dao.py --match create
ast-grep outline api/oss/src/core/sharing/service.py --items all --match 'created_session_access|check_resource|decide'
rg -n -C 5 'has_channel_thread|created_session_access|CHANNEL_SESSION|RUN_SESSIONS' api/oss/src/core/sharing api/oss/src/dbs/postgres/sessions/streams/dao.py

Repository: Agenta-AI/agenta

Length of output: 11103


Script executed:

rg -n -F -e '_create_header_row' -e 'has_channel_thread' -e 'set_header' -e '_create_row' -e 'recheck' -- api/oss/src/core/sessions/streams/service.py || test "$?" -eq 1
rg -n -C 25 -F -e 'async def _create_header_row' -- api/oss/src/core/sessions/streams/service.py || test "$?" -eq 1
rg -n -A 14 -F -e 'def _project_members_send' -- api/oss/src/core/sharing/service.py || test "$?" -eq 1

Repository: Agenta-AI/agenta

Length of output: 5409


Recheck a channel-thread row after the header pre-create.

When _create_header_row creates a row, the DAO can substitute the channel policy if a channel thread already names the session. The method then returns that row without running recheck. The send and heartbeat create paths run the check on the created row in this case. The header path does not. A project member who passes the initial check can therefore receive a channel-session row that the channel RUN rule would refuse. Add the same check after a successful create:

🔒 Suggested fix
--- "a/api/oss/src/core/sessions/streams/service.py"
+++ "b/api/oss/src/core/sessions/streams/service.py"
@@ -1372,11 +1372,13 @@
         does not include reading the session (one that a concurrent first touch created
         is still checked first, so a hidden one answers like a hidden one)."""
         try:
             created = await self._create_row(
                 project_id=project_id,
                 user_id=user_id,
                 stream=SessionStreamCreate(session_id=session_id, access=access),
             )
+            if recheck is not None and getattr(created, "has_channel_thread", None) is True:
+                await recheck()
         except SessionStreamAlreadyExists:
             if recheck is not None and session_was_missing(
                 project_id=project_id, session_id=session_id
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
created = await self._create_row(
project_id=project_id,
user_id=user_id,
stream=SessionStreamCreate(session_id=session_id, access=access),
)
created = await self._create_row(
project_id=project_id,
user_id=user_id,
stream=SessionStreamCreate(session_id=session_id, access=access),
)
if recheck is not None and getattr(created, "has_channel_thread", None) is True:
await recheck()

| --- | --- | --- |
| P1 turn start | `SessionStreamsService._start_turn` (`core/sessions/streams/service.py` ~1131) and `command(...)` | new required kwarg `access: AccessPolicy`. Callers: router `set_session_stream`, `core/channels/commands.py` (channel session, passes `OWNERLESS_PROJECT_POLICY`). |
| P2 rename before the first turn | `SessionStreamsService.set_header` create arm (~978) | new required kwarg `access: AccessPolicy`, used only in the create arm. The `SessionStreamAlreadyExists` arm writes no access field. |
| P2 rename before the first turn | `SessionStreamsService.set_header` create arm (~978) | new required kwarg `access: AccessPolicy`, used only in the create arm. The `SessionStreamAlreadyExists` arm writes no access field. A header call with a `visibility` and no header field only creates the session (the /w pre-create of a new chat; an existing row is returned unchanged). Without a `visibility`, a body with no header field is refused with 422, as before. |

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.

Minor · Data Integrity & Integration · Quick win

Correct the existing-session response description.

For a visibility-only call on an existing session, set_header returns None. The response therefore contains stream: null; it does not return the unchanged row. State that the row remains unchanged and no session data is returned.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Railway Preview Environment

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

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 merged commit ee28b2a into release/v0.125.0 Oct 26, 2026
72 of 74 checks passed
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.

1 participant