Skip to content

fix(canvas): set_canvas reports whether the audience reaches the session that asked (#2577) - #2603

Merged
vybe merged 3 commits into
devfrom
fix/2577-canvas-audience-visibility
Sep 9, 2026
Merged

vybe merged 3 commits into
devfrom
fix/2577-canvas-audience-visibility

Conversation

@dolho

@dolho dolho commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The bug is not the default — it is a success indistinguishable from one the user can see. An agent in a public-link session wrote with the default operator, got success: true with the canvas echoed back, saw it in list_canvases, and the person who asked saw nothing. Neither side had the audience→surface mapping, because it appears nowhere in the tool contract.

So the write answers the question. PUT /{name}/canvas/{id} now returns CanvasWriteResult — Canvas plus visible_to_requester and visibility_note — resolved off the stored row (normalize_audience defaults closed, so a verdict about the requested value could describe a canvas that does not exist). list/get keep the narrower Canvas: they answer about a canvas, not about a requester.

This is the issue's option (1), plus (3) as the note. Option (2) is deliberately not implemented — see below.

Two properties are load-bearing

  1. Three-state, not a boolean. Widening to roster publishes to everyone the agent is shared with, so a wrong false costs an over-share and "could not tell" has to stay distinguishable from "no" (bug: Workspace roster lists agents with no container (DB-sourced roster vs Docker-as-truth) #2196). A write with no execution_id, or one whose stamp does not resolve to this agent, answers null — resolve_and_validate_execution is already fail-open, so an unverified stamp arrives as "no claim" for free.
  2. The trigger sets are allow-lists, named individually rather than derived by subtraction, so a label invented tomorrow makes no claim instead of being adopted into the confident branch.

The narrowing that self-review forced

My first cut treated every triggered_by="public" turn as "the reader is on the Workspace page, which shows roster only". A Workspace turn carries that same label — told apart from a public link only by source_channel="portal" — and the two are not the same audience:

client_portal/agent_page.py::canvas_audience_for(is_platform=True) -> None   # no narrowing

A signed-in operator working in the Workspace reads every audience, operator included. The rule would have told them their own canvas was invisible and pushed them to republish it to the whole roster — the exact over-share property (1) exists to prevent, on the most ordinary Workspace path there is.

The row records the client's email, never whether that email is a platform principal, so the honest answer for a portal turn is no answer. The confident branch is public-link and paid turns only.

Channel turns are silent too, for a different reason: no canvas renders inside Slack/Telegram/WhatsApp/VoIP, so false would be true and would advise a widening that still does not put it in front of them.

Why not option (2), the context-aware default

In a public-link session the requester is one anonymous visitor while roster is everyone the agent is shared with — defaulting there would publish to the whole roster because one visitor asked. That is the issue's own objection to the blanket default, surviving the narrowing. The agent widens explicitly, told exactly why, which keeps a real visibility change a decision someone makes rather than a default that happens.

Tests

test_2577_canvas_visibility_hint.py (42) — the reported bug, the operator side, every refuse-to-guess arm, the portal exclusion both ways, and a source guard that visibility_for_canvas actually threads source_channel through (the pure rule can be right while the glue silently re-opens the hole, and every pure test would still pass).

Backend unit suite: 14411 passed; the 15 failures are the pre-existing ::ffff: IPv4-mapped class, reproduced byte-identically on clean origin/dev.

Fixes #2577

🤖 Generated with Claude Code

https://claude.ai/code/session_01CdxGmvuKuqaWJZ6pKUgaUJ

…rove (#2577)

Self-review of my own rule, before it shipped, and it was wrong in the
direction the whole design exists to avoid.

`_ROSTER_SIDE_TRIGGERS = {public, paid}` treated every `triggered_by="public"`
turn as "the reader is on the Workspace page, which shows roster only". A
Workspace turn carries that label too — it is told apart from a public link
only by `source_channel="portal"` — and the two are NOT the same audience:

    client_portal/agent_page.py::canvas_audience_for(is_platform=True) -> None

None means no narrowing, so a signed-in OPERATOR working in the Workspace reads
every audience, `operator` included. The rule would have told them their own
canvas was invisible and pushed them to republish it to the whole roster: the
exact over-share the three-state verdict was built to prevent, on the most
ordinary Workspace path there is.

The row records the client's email, never whether that email is a platform
principal, so the honest answer for a portal turn is no answer. The confident
branch is now public-link and paid turns only — doors that render no canvas at
all and cannot be the platform-principal case — and the set is renamed
`_NO_OPERATOR_SURFACE_TRIGGERS` for what it actually means. The reported bug is
a public-link turn, so it stays covered.

The note stops asserting "the person who asked will not see it" in the
abstract and says what is true of that door: a public link and a paid call
render no canvas, and Agent Detail is not open to them.

Tests: the portal exclusion is pinned both ways, plus a source guard that
`visibility_for_canvas` actually threads `source_channel` through — the pure
rule can be right while the glue silently re-opens the hole, and every pure
test would still pass.

Related to #2577
@vybe

vybe commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

merge-train: ejected — the fix is a no-op. services/canvas_service.py:233 reads (canvas or {}).get("execution_id"), but the dict the router passes in is the return of db.upsert_agent_canvas, whose key is updated_by_execution_id (db/canvas.py:238). So execution_id is always None and visibility_for_canvas answers (None, None) on every write — #2577 is still unfixed. The 42 tests pass because they drive the pure rule and a source guard, never visibility_for_canvas with a stored row. Fix the key and add a test that goes through the shape upsert_agent_canvas returns. Also note this conflicts with #2619 in the canvas router/service, so land this first and let #2619 re-merge. Rides the next train once fixed.

dolho and others added 2 commits September 9, 2026 11:14
…es (#2577)

Review of #2603 found the fix inert. `visibility_for_canvas` took its
execution id from `canvas["execution_id"]`, a key no canvas dict has ever
had: `db.upsert_agent_canvas`'s return and both read builders
(`_row_to_summary`, `_row_to_full`) all name it `updated_by_execution_id`.
So the wrapper returned `(None, None)` on every write and `set_canvas`
answered exactly as it did before the feature.

The 42 tests stayed green because they drive the pure rule
(`canvas_visibility`) and a source guard — nothing put a stored row through
the wrapper that joins them.

Adds three that do: the stored shape reaching a real verdict, a rename guard
that fails at the key rather than as a silent return to no-claim, and the
no-execution-id row still making no claim.

Related to #2577

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bd71qsYbFodvofba8P69eP
@vybe

vybe commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-09-09): not on this train — same finding as the 2026-09-08 eject, head 8537e33 is unchanged. src/backend/services/canvas_service.py:233 reads canvas.get("execution_id") but the dict is the return of db.upsert_agent_canvas, whose key is updated_by_execution_id (src/backend/db/canvas.py:238), so visibility_for_canvas always returns (None, None) and resolve_and_validate_execution is never called (reproduced: patched it to a public-link execution, called 0×). The one-token fix is mechanical, but the regression test that has to come with it (feed visibility_for_canvas the literal upsert return dict and assert visible is False) is yours to write — the current suite passes on the dead branch. Please also change Related to #2577 to Fixes #2577. Rides the next train once fixed; land it before #2619 re-merges the canvas router/service.

@dolho

dolho commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

You were right, and the diagnosis was exact — fixed in 2f7809b8, dev merged.

services/canvas_service.py read canvas["execution_id"]; the key every canvas dict carries is updated_by_execution_id (db.upsert_agent_canvas's return, _row_to_summary and _row_to_full all name it that). So visibility_for_canvas answered (None, None) on every write and set_canvas behaved exactly as it did before the feature.

The reason the 42 tests could not see it is worth stating, because it is the shape of the bug rather than a gap in coverage: they drive the pure rule (canvas_visibility) and a source guard, and nothing put a stored row through the wrapper that joins them. Three tests now do:

  • the stored shape — key for key, as upsert_agent_canvas returns it — reaching a real verdict;
  • a rename guard asserting the key the service reads is the key the db layer writes, so a rename on either side fails there, with the reason, rather than as a silent return to no-claim;
  • a row with no execution id still making no claim (with the resolver stubbed to raise, so a regression cannot pass by accident).

Also noted on the ordering: this conflicts with #2619 in the canvas router/service, so it lands first and #2619 re-merges. #2619's own two blockers (the 0058 head fork and the inert CANVAS_MAX_PER_AGENT) are fixed on that branch already.

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

merge-train (2026-09-09): validated at lane B — /validate-pr + call-trace review clean (producer and consumer both use updated_by_execution_id), 45 new + 76 existing canvas tests pass, mcp-server tsc clean. Body patched to Fixes #2577. Below the train floor, so merged individually.

@vybe
vybe merged commit a873ae4 into dev Sep 9, 2026
28 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.

2 participants