Repository navigation
fix: an attachment sent as the first message of a new chat renders (M3 regression) #7809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| """The /w pre-create of a new chat, against a running API (M3 regression). | ||
|
|
||
| /w creates a new chat as a project-visible session before its first run, with a header | ||
| call that carries only `visibility` (no name: the chat has no title yet). The header | ||
| route refused that call (422, "no header field to update"), so every first /w send | ||
| failed with "Message wasn't sent". | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from oss.tests.pytest.acceptance.sharing.support import ( | ||
| core_rows, | ||
| new_session_id, | ||
| stream_row, | ||
| ) | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.acceptance, | ||
| pytest.mark.integration, | ||
| pytest.mark.xdist_group("sharing_header_precreate"), | ||
| ] | ||
|
|
||
|
|
||
| def _name(project_id, session_id): | ||
| rows = core_rows( | ||
| "SELECT name FROM session_streams WHERE project_id = $1::uuid " | ||
| "AND session_id = $2", | ||
| project_id, | ||
| session_id, | ||
| ) | ||
| return rows[0]["name"] | ||
|
|
||
|
|
||
| def _put_header(caller, session_id, *, body, visibility=None): | ||
| params = {"session_id": session_id} | ||
| if visibility is not None: | ||
| params["visibility"] = visibility | ||
| return caller("PUT", "/sessions/streams/header", params=params, json=body) | ||
|
|
||
|
|
||
| def test_a_visibility_only_header_creates_a_project_session(sharing_cast): | ||
| alice = sharing_cast["alice"] | ||
| session_id = new_session_id() | ||
|
|
||
| created = _put_header(alice, session_id, body={}, visibility="project") | ||
| assert created.status_code == 200, created.text | ||
| stream = created.json()["stream"] | ||
| assert stream["name"] is None | ||
| row = stream_row(sharing_cast.project_id, session_id) | ||
| assert (row["visibility"], row["owner_user_id"]) == ("project", alice.user_id) | ||
|
|
||
|
|
||
| def test_a_visibility_only_header_leaves_an_existing_session_unchanged(sharing_cast): | ||
| alice = sharing_cast["alice"] | ||
| session_id = new_session_id() | ||
| named = _put_header(alice, session_id, body={"name": "kept"}, visibility="private") | ||
| assert named.status_code == 200, named.text | ||
|
|
||
| again = _put_header(alice, session_id, body={}, visibility="project") | ||
| assert again.status_code == 200, again.text | ||
| # It returns no session data for an existing session (it is checked like a send). | ||
| assert again.json()["stream"] is None | ||
| assert _name(sharing_cast.project_id, session_id) == "kept" | ||
| row = stream_row(sharing_cast.project_id, session_id) | ||
| assert (row["visibility"], row["owner_user_id"]) == ("private", alice.user_id) | ||
|
|
||
|
|
||
| def test_an_empty_header_without_a_visibility_is_still_refused(sharing_cast): | ||
| response = _put_header(sharing_cast["alice"], new_session_id(), body={}) | ||
| assert response.status_code == 422, response.text | ||
|
|
||
|
|
||
| def test_a_member_s_pre_create_on_a_colleague_s_project_chat_changes_nothing( | ||
| sharing_cast, | ||
| ): | ||
| """Bob opens Alice's project chat before its first answer, and his first send | ||
| pre-creates it again: the call needs what a send needs, so it passes and changes | ||
| nothing (Alice stays the owner, her name stays).""" | ||
| alice, bob = sharing_cast["alice"], sharing_cast["bob"] | ||
| session_id = new_session_id() | ||
| created = _put_header( | ||
| alice, session_id, body={"name": "alice's"}, visibility="project" | ||
| ) | ||
| assert created.status_code == 200, created.text | ||
|
|
||
| again = _put_header(bob, session_id, body={}, visibility="project") | ||
| assert again.status_code == 200, again.text | ||
| assert again.json()["stream"] is None | ||
| assert _name(sharing_cast.project_id, session_id) == "alice's" | ||
| row = stream_row(sharing_cast.project_id, session_id) | ||
| assert (row["visibility"], row["owner_user_id"]) == ("project", alice.user_id) | ||
|
|
||
| # A rename still needs the edit right: only Alice renames her chat. | ||
| rename = _put_header(bob, session_id, body={"name": "bob's"}) | ||
| assert rename.status_code == 403, rename.text | ||
|
|
||
|
|
||
| def test_a_pre_create_on_a_hidden_chat_answers_not_found(sharing_cast): | ||
| alice, bob = sharing_cast["alice"], sharing_cast["bob"] | ||
| session_id = new_session_id() | ||
| created = _put_header( | ||
| alice, session_id, body={"name": "mine"}, visibility="private" | ||
| ) | ||
| assert created.status_code == 200, created.text | ||
|
|
||
| hidden = _put_header(bob, session_id, body={}, visibility="project") | ||
| assert hidden.status_code == 404, hidden.text | ||
| row = stream_row(sharing_cast.project_id, session_id) | ||
| assert (row["visibility"], row["owner_user_id"]) == ("private", alice.user_id) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -537,7 +537,7 @@ Callers pass the execution target, never the session's stored references (techni | |
| | Path | Symbol | Change | | ||
| | --- | --- | --- | | ||
| | 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. | | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the existing-session response description. For a visibility-only call on an existing session, |
||
| | P3 trigger claim | `SessionStreamsDAO.claim_trigger_delivery` (`dbs/postgres/sessions/streams/dao.py` ~163) and `TriggerSessionClaimsDAOInterface.claim_trigger_delivery` | new required kwarg `access: AccessPolicy`; the `from_select` column list adds both columns. `on_conflict_do_update` stays tags-only. Caller `TriggersDispatcher._run` passes `initial_policy(principal=<trigger principal>, origin=schedule or subscription, sender_user_id=None, kind=SESSION)`. | | ||
| | P4 heartbeat | `SessionStreamsService.heartbeat(*, project_id, request, runner_verified=False, envelope)` (M2) and `_heartbeat_locked` | new required kwargs `access: AccessPolicy` (used only in the `prior_stream is None` create), `run_admission: RunAdmission`, `admission_envelope: RunEnvelope`, next to M2's `envelope` (which is `None` for Bearer and ApiKey). `_heartbeat_locked` reads `prior_stream` once, at the top, before the supersession check (its branch reuses the row). Then it authorizes: row absent → `admit_turn(session_id=None)`, then insert the row (initial flags, `turn_id`, `access`) before any liveness lock; on `SessionStreamAlreadyExists` read the winning row and authorize it as below before any lock, update or response; row present and verified continuity (`request.is_running`, `request.turn_id == prior_stream.turn_id`, and `get_turn_admission(...)` equals `admission_envelope.authority.principal`; `get_turn_admission` is one `EVAL` of `CURRENT_TURN_ADMISSION_LUA`, which returns and renews the record only while the session's `running` key equals the turn; a Redis error counts as no record) → no check; otherwise → `admit_turn(session_id=request.session_id)` for a running beat, `admit(session_id, agent_artifact_id=None)` for any other beat. After a successful check of a running beat with a `turn_id`, for the row actually used, `record_turn_admission(...)` (a write error is logged; the next beat is checked again) (Redis, NEW `record_turn_admission` and `get_turn_admission` in `dbs/redis/sessions/locks.py` next to `bind_turn`; key per project, session and turn; value the admitted `PrincipalRef`; same TTL as the binding; written only after create-or-conflict is resolved and the used row passed). NEW `forget_turn_admissions(engine, *, project_id, session_id, turn_ids)` deletes the records on the end beat, on displacement (cancel, steer, kill), on handover and on stop; a refused end beat (not running, with a `turn_id`) whose record names the same principal deletes that record too, so a replay of an ended turn is fully checked. A refusal raises before any lock, row write or response. A heartbeat with no envelope answers the canonical 404 before any row read. Router `heartbeat_session_stream` computes `access` and `admission_envelope = request_run_envelope(request)`; it reads no session row. | | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔎 Supported by static analysis
Script executed:
Repository: Agenta-AI/agenta
Length of output: 11103
Script executed:
Repository: Agenta-AI/agenta
Length of output: 5409
Recheck a channel-thread row after the header pre-create.
When
_create_header_rowcreates a row, the DAO can substitute the channel policy if a channel thread already names the session. The method then returns that row without runningrecheck. 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
Committable suggestion