Repository navigation
fix: an attachment sent as the first message of a new chat renders (M3 regression) - #7809
Conversation
…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.
📘 Docs preview
This comment updates in place on every push. |
|
🤖 The AI agent says: Verification for How I found the cause: I read the Playwright trace of the failing CI run on #7789 (job 121327788503). The upload Results on a local stack:
Codex xhigh reviewed the fix in 3 rounds:
|
📝 Summary
Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 2

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Agenta-AI/agenta
- Branch: fix/m3-attachment-first-send
- File: .coderabbit.yaml
- Commit: 6b77659
- Layers: Repository YAML (base), Organization UI (inherited)
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e1862cf1-8d0c-43cf-a8db-833475948020
Files selected for processing: 6-
api/oss/src/apis/fastapi/sessions/router.pyapi/oss/src/core/sessions/streams/dtos.pyapi/oss/src/core/sessions/streams/service.pyapi/oss/tests/pytest/acceptance/sharing/test_header_precreate.pyapi/oss/tests/pytest/unit/sessions/test_stream_header_merge.pydocs/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.
-
| created = await self._create_row( | ||
| project_id=project_id, | ||
| user_id=user_id, | ||
| stream=SessionStreamCreate(session_id=session_id, access=access), | ||
| ) |
There was a problem hiding this comment.
🔎 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 changecreated = 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. | |
There was a problem hiding this comment.
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.
Railway Preview Environment
PR closed or converted to draft. Environment absence verified; retained storage requires separate provider accounting. Post |
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:
The header route refused any body without
nameordescription(a rule added earlier so the agent's rename tool cannot send a wrapped body):So the pre-create failed, and /w never sent the run.
Changes
visibilityand 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.visibility, a body with no header field is still refused with the same 422. The rename tool cannot setvisibility(its path is fixed and the model fills only the body), so its rule does not change.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=projectwith{}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
test_header_precreate.py:These failed before the fix (the colleague case fails with the old edit check).
/invoke) when the old rule is put back.What to QA