Repository navigation
fix(apps): limit an app's send on a user session to the turn - #16213
Conversation
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS Rows from any user's restored queue are now left out of auto-titling on every non-app slot. That costs all users, apps or not, to close a narrow app-after-restart case. Not justified as shipped
What this change shipsInventory (9 items) — 8 justifiedIntent: an app with
[FIRST-PRINCIPLES-REVIEWED] afb0d86 Description read[DESCRIPTION-READ] 517db56985e8032d5f7e902ce9b05ab96314905d0b0124118f0fb03086b9f53f That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that every turn-ending path in [DESIGN-REVIEWED] afb0d86 Description read[DESCRIPTION-READ] c75081f393cf20d3d2f03b959820ab89343b1c23448cd7c99cd36d02fed55e52 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
865710e to
c76d06b
Compare
|
|
|
|
|
permissions.sessionApproval lets an app send a turn to a user-owned session through POST /api/chat. The same request could also change the session around that turn: bind an agent onto an agent-less slot, write the persona fields (color_theme, theme_consent, theme_consent_sha), run a harness slash command from the message text, skip the sub-agent hold with steer, supply its own row id, drive the session's auto-title, or keep streaming the user's own queued follow-ups while suppressing the user's dashboard frames. api_chat now derives the caller's access positively (dashboard, owning app, or grant). On the grant path it refuses an agent binding, the persona fields and a harness slash command with 403 app_session_settings_forbidden and an SEL denial before anything is written or queued, using the same predicates as the write sites. The send ignores steer, has its row id minted by the gateway, is echoed to the user's open tabs, and neither the send nor the reply to it starts, counts toward or feeds the session's auto-title or its refresh; a merge of queued messages stops where the turn actor changes. An SSE stream ends at the app's own turn through a turn_end wire frame pushed at the turn's end before the drain or the cycle's end writes anything else, never before a recovery the ending turn queued for itself; the stream skips rows queued for a later turn, and every other reader skips the frame. The grant path re-checks that the slot is still registered, not closing and still a local user session after its off-loop reads. A queued app entry, or one restored from disk, is never classified as a cron or sub-agent event by its text, and the rehydrate refresh-mark rebase counts turns the way the refresh does. An AST pin classifies every body key api_chat reads as turn-only or settings-bearing, so a new key fails until it is classified. The app platform spec, trust model, manifest reference, history spec and dashboard spec describe the narrowed grant.
c76d06b to
afb0d86
Compare
Problem / Motivation
Goal: An app that holds
permissions.sessionApprovalcan send a turn to a user's session and nothing more; it can no longer change that session's settings or read past its own turn.permissions.sessionApprovallets an app send a turn to a user-owned dashboard session throughPOST /api/chat. The same request could also change the session around that turn. It could bind an agent onto an agent-less slot, write the persona fields (color_theme,theme_consent,theme_consent_sha), or run a harness slash command from the message text. It could also skip the sub-agent hold withsteer, supply its own row id, or drive the session's automatic title. And it could keep streaming the user's own queued follow-ups while the user's dashboard frames were suppressed.Why it matters
The grant is described as "send a turn". A session's agent binding, persona consent and title belong to the user, and the user's later turns are theirs. An app with the grant should not be able to change them or read them through its own stream.
Not a goal
POST /api/chat.What changed (motivation → approach → change)
Root cause.
api_chatasked one yes/no question, "may this app use this slot?". After that, every setting the body carried was applied the same way for a dashboard user, the owning app and a grant holder.Approach. The caller's access is now an explicit
SlotAccessvalue:DASHBOARD,OWNER,GRANTorNONE. OnlyDASHBOARDandOWNERmay configure the slot. On theGRANTpath:app_session_settings_forbiddenand an SEL denial is logged. The checks reuse the write sites' predicates (_send_binds_agent,_send_writes_persona) and the runner's ownis_harness_slash_command.steeris ignored and a caller-suppliedmeta.midis dropped.turnActorbecomes a reserved row-meta key. The app's user row is always echoed to the user's open tabs.chat_title._counts_as_user_turn,_titling_messages). The rehydrate refresh-mark rebase uses the same predicate. A queued-message merge stops where the turn actor changes.turnProvenanceRestored. Titling skips that row on a slot no app owns.chat_runner._mark_turn_endpushes aturn_endwire frame at the turn's end, before the drain or the cycle end writes anything. It is not pushed before a recovery that the same turn queued for itself. The recovery carries that turn's own id (recoveryTurnId), so another turn's held retry, or a restored one, still gets the boundary. Only a grant-path SSE reader stops at this frame. That reader also stops at any user row that is not its own gateway-minted row, so a missed boundary fails closed. It skipsqueuedplaceholder rows and never suppresses the user's broadcast. A grant-path reader never blocks the user's SSE broadcast (_has_readerstays false), andresp.prepareruns inside the pending-consumer scope so a failed prepare releases it.The code is in
dashboard/chat_handlers.py,dashboard/chat_runner.py(with itschat_turn/steer_queue.pyowner),dashboard/chat_title.py,dashboard/chat_utils.pyandslot_persistence/restored_metadata.py.POST /api/chatcarrying…agenton an agent-less slotcolor_theme/ consentsteerturn_end🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged
Backwards compatibility
Breaking: on a user session that an app reaches only through
permissions.sessionApproval, a send that names an agent for an agent-less slot, carriescolor_theme, or opens with a harness slash command now gets a 403 instead of being applied. Writer sweep on origin/main @ 21999ee: the dashboard SPA and ChatEmbed use the cookie (DASHBOARD), and an app on its own slot isOWNER, so neither changes. No bundled app sends these fields onto a user session.Reader:
chat_handlers.api_chatSSE loop -- app -- stops atturn_endon the grant path only (test_app_sse_stream_skips_a_row_queued_for_a_later_turn)Reader: dashboard WS / global SSE readers -- chat -- skip the
turn_endframe, which is never a row (test_the_drain_marks_the_turn_end_before_a_successor_turn)Reader:
chat_title._maybe_auto_title/maybe_refresh_title-- chat -- an app row on its own slot still counts (test_the_title_fallback_never_takes_an_apps_text)Tests
Tests are in
test/test_chat_mode_security.py:allowedrow, on agent-bound and agent-less slots.steerignored,middropped, and the echo to the user's tabs.turn_endplacement around recoveries, held notes, synthesis and the cycle end; an older or restored app retry cannot extend a later app's stream.turn_endnever reaches the app.test_every_api_chat_body_key_is_classified, an AST pin, so a new body key fails until it is classified.test_active_turn_session_key,test_dashboard_chatandtest_steer_requeuefakes take the newpredecessor_actorkeyword.Manual verification
N/A. The unit coverage drives
api_chatand the runner drain with real slots.Related Issues
None.
Pattern harvest
Rule candidate: review-prompt
Pattern: a route that authorizes an action with a boolean, then applies every body field the same way for every caller.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)app-kit-platform.md,app-platform-trust-model.md,manifest-reference.md,history.md,learn-cron-dashboard.mdContribution License Agreement
Closes #16642