Skip to content

feat(canvas): keep flagged owners' new canvases in a Terse actor - #433

Closed
oliviersm199 wants to merge 5 commits into
doop-design:mainfrom
oliviersm199:canvas-actors-flag
Closed

oliviersm199 wants to merge 5 commits into
doop-design:mainfrom
oliviersm199:canvas-actors-flag

Conversation

@oliviersm199

@oliviersm199 oliviersm199 commented Nov 7, 2026 •

Copy link
Copy Markdown

An A/B rollout of Terse durable actors for a few people, behind a per-user canvas-actors flag. It replaces #187, which moved every canvas's frames off the server. This version keeps main's architecture and changes only where a flagged canvas's frames are saved.

            Browsers, iOS app, agents
                       |
             HTTP + /ws room (unchanged)
                       v
        +------------------------------+
        | Doop server: main's code,    |
        | every canvas in memory       |
        +--------------+---------------+
                       |  persist.saveFrame / deleteFrame
         canvas.frameStore === 'actor'?
             no /                  \ yes
               v                    v
   Postgres frames table      Terse CanvasActor, one per canvas
   (main's path, untouched)   (frames only, SQLite + Drizzle)
                                    ^
                                    |  plain frame edits, sent directly
                          browsers on a flagged canvas

Unflagged canvases run main's code

  • The flag points are one-line checks that act only on a canvas marked frame_store = 'actor':
    • server/db/persist.ts: save, save-now, delete, copies, canvas delete, flush and boot load
    • placeCanvas in store.createCanvas and duplicateCanvas
    • an adopted option on actions.updateFrame
    • api.updateFrame on the client
    • revokeActorAccess wherever store and workspaces change who can open a canvas
  • With TERSE_ACTOR_URL unset, the default, no canvas is ever marked and the server never reads feature_flags. If the flags read fails at boot, every flag stays off and the server still starts.
  • bun run dev and bun run test are unchanged. The edits to main's existing files come to about 300 lines across 16 files, counting docs, CI and lint config. Everything else is in new files.
  • The app stays on zod 3; terse-sdk brings its own zod 4.

How a flagged canvas works

  • Placement. A canvas is marked canvases.frame_store = 'actor' when someone with the flag creates it, or when they copy any canvas. Existing canvases never move.
  • The server stays the hub. It keeps the canvas in memory like any other and saves its frames to the canvas's CanvasActor (src/actor.ts) instead of the frames table. Pages, design history, activity, comments and the room stay where main keeps them.
  • Browser edits. Browsers on a flagged canvas send plain frame edits (name, geometry, HTML, hidden, locked, z) straight to the actor over a WebSocket. The ticket comes from GET /api/canvases/:id/actor and is read-only unless the person can edit. If the direct edit fails, it falls back to the app API. Page moves, sign-off and version-checked saves always go through the API.
  • Folding edits in. The server follows each actor's socket and applies browser edits through actions.updateFrame with adopted, which saves nothing back. HTML the server would complete (library fonts, tokens, escaped markup) goes through as an ordinary edit instead, so the completed HTML is saved back to the actor. So the room, history and activity see them as before, and older clients such as installed iOS apps get frames from the room as on main.
  • Access. Actor sockets are checked only when they open. So every access change (link access, canvas members, workspace moves and deletion, workspace member removal) bumps the actor's access version, retried until the actor confirms. That closes open sockets and voids older tickets.

Turning it on and off

  • bun run flags enable canvas-actors <email>... (also list and disable). The server re-reads the table every 30 seconds.
  • disable stops new canvases from going to actors. Canvases already on an actor stay there.
  • bun run flags move-back <email>... turns the flag off, copies those people's actor canvases into the Postgres frames table as the actor holds them, and clears the mark. Restart the server afterwards. Nothing else needs moving, since pages and history never left Postgres.

Deploy

  • SQL migration 0048 adds feature_flags and a nullable canvases.frame_store, with no backfill. It runs at boot.
  • To enable the flag: create a Terse project (bunx terse-cli init), run bun run deploy:actors, and set TERSE_ACTOR_URL and TERSE_API_KEY on the server. The actor API's WebSocket endpoint has to be reachable from browsers. Then turn the flag on for the testers.
  • Locally, bun run dev:actors starts Doop with a local actor runtime (Bun 1.4.2+).
  • Depends on terse-sdk and terse-cli 0.15.0.

Validation

  • Typecheck, lint, format, docs lint and the generated-client check pass.
  • bun run test (main's suite, with Terse unset): 2,400 passed. secretBox.test.ts fails only on a checkout whose path contains a space, which is unrelated to this change.
  • tests/canvasActors.test.ts, run against a local actor runtime: 11 passed. It covers:
    • an unflagged person's canvas staying in Postgres
    • a flagged person's new canvas getting an actor
    • a browser edit written to the actor reaching the server
    • read-only sockets being refused
    • a removed member's socket closing, and them being refused a new ticket
    • HTML written straight to the actor getting the server's additions, as through the app API
    • a frame's deletion being sent to the actor once
    • a deleted canvas's asset refs being removed, including ones still waiting to be written
    • the server and the actor converging when a browser and the server edit one frame at once
    • reloading the frames from the actor after a restart
    • flags move-back
  • A new CI job, test-actors, runs the generated-client check and that test, and the tests status now requires it.
  • Not yet tried by hand in a browser against a Terse Cloud project.

.gitattributes marks the generated actor client and the migration snapshots as generated, so GitHub collapses them. The hand-written diff is about 2.3k lines, including tests.

@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge, with a non-blocking cleanup issue in actor canvases' asset records.

Findings

  1. P2 Deleted canvases keep asset records ▶

Summary

Adds per-user rollout of actor-held canvas frames while keeping the Doop server and room as the hub.

  • Flagged owners’ new and copied canvases keep their frames in a Terse actor.
  • Operators can choose who gets actor-backed canvases and move them back.
  • The actor runtime can be generated, run locally, deployed, and checked in CI.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Browser[Browser frame edit] --> Actor[CanvasActor]
  Actor --> Adopt[Doop adopts or completes edit]
  Adopt --> Room[Room broadcasts frame]
  Server[Doop frame write] --> Choice{Actor canvas?}
  Choice -->|Yes| Actor
  Choice -->|No| Postgres[Postgres frames]
  Server --> Refs[Postgres asset records]
  Adopt --> Refs
Loading

Reviews (2) · Last reviewed commit: "fix(canvas): address review findings on ..." · Reviewed by Greptile

Comment thread server/actorFrames.ts Resolved
Comment thread server/index.ts Resolved
Comment thread server/actorFrames.ts Resolved
Comment thread server/actorFrames.ts Resolved
Comment thread server/actorFrames.ts Resolved
Comment thread scripts/feature-flags.ts Resolved
Comment thread src/lib/actorFrames.ts Resolved
Comment thread server/actions.ts Resolved
Comment thread server/db/persist.ts Resolved
Comment thread src/lib/actorFrames.ts Resolved
@kgoedecke

Copy link
Copy Markdown
Collaborator

@greptileai

Comment thread server/db/persist.ts
Comment on lines +1237 to +1239
function saveOnActor(f: Frame) {
saveActorFrame(f)
adoptActorFrame(f)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Deleted canvases keep asset records

Actor canvases now write asset_refs, but deleteCanvas still finds their frame IDs through the Postgres frames table. Actor-held frames have no rows there, so deleting the canvas leaves stale asset records until a restart. Pending assetRefTimers can also write records after deletion.

Remove the records using the deleted canvas's frame IDs and cancel those timers. This is a non-blocking bookkeeping issue; current asset serving is unaffected.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 431481e. destroyActorCanvas now returns the IDs of the frames its actor held, and deleteCanvas deletes their asset_refs by those IDs and cancels any ref writes still waiting on their debounce. main's Postgres path is unchanged. While in here: frames restored from an actor that missed the boot read now get their refs too, since the boot rebuild of asset_refs never saw them. Covered by drops a deleted canvas’s asset refs, which fails both without the deletion (kept survives) and without the timer cancel (pending is written after the canvas is gone).

aikins01 pushed a commit to aikins01/doop that referenced this pull request Nov 7, 2026
…sign#433)

* test(browser): bound every UI wait below the test timeout

A wait that never comes true now fails on its own line with the condition
it waited for, instead of the whole test timing out with only its title.
DOOP_TEST_CPU_THROTTLE throttles the page's main thread for chasing a race
locally. Plus a temporary flake-hunt workflow.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test(browser): say what the page did when a link or focus wait never comes true

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test(hunt): temporary trace of FrameView's probe paths

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(canvas): keep a cleared element pick cleared, focus prototype screens once they listen

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test(hunt): drop the temporary FrameView trace

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* ci: drop the temporary flake-hunt workflow

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit e4f9f6c2c19f99ed92e31223e375fe49f6689016)
oliviersm199 and others added 5 commits November 8, 2026 17:08
An A/B rollout of durable actors behind a per-user `canvas-actors` flag
(`feature_flags` table, `bun run flags`). A canvas made or copied by a
flagged owner is marked `frame_store = 'actor'` and saves its frames to its
Terse CanvasActor where main writes the Postgres frames table. Everything
else about it stays main's: the server holds it in memory, and pages,
history, activity and the room are unchanged.

Every other canvas runs main's code. The flag points are one-line checks
in persist.ts, store.ts and api.updateFrame that only act on actor
canvases, and with TERSE_ACTOR_URL unset the flags table is never read.

- browsers on an actor canvas send plain frame edits straight to the
  actor; the server follows the actor's socket and folds them in without
  saving them back
- existing canvases never move; `bun run flags move-back` copies an
  owner's actor canvases back into Postgres
- terse-sdk and terse-cli 0.15.0; the app stays on zod 3
- a CI job runs the end-to-end test against a local actor runtime

Co-authored-by: Cursor <cursoragent@cursor.com>
- a confirmed actor delete is finished, instead of being resent forever;
  shutdown flushes actor and Postgres writes side by side
- every access change (link access, canvas members, workspace moves and
  deletion, workspace member removal) revokes the actor's sockets, retried
  until the actor confirms; tickets read the access version before rights
- browser HTML the server would complete (library fonts, tokens, escaped
  markup) is saved back completed, as through the app API
- the browser bounds connect-and-confirm at 10s and fails only the edits
  of the socket that closed
- boot follows an actor only after reading it, retries a missed snapshot
  until the store has the canvas, and sends restored frames to the room
- a failed canvas or page copy takes its frames off the actor again
- actor frames keep their asset_refs like any frame
- `bun run flags` exits 1 on errors

Co-authored-by: Cursor <cursoragent@cursor.com>
deleteCanvas finds a canvas's asset refs through its frames rows, which a
canvas on an actor never has. Its refs now go by the IDs of the frames its
actor held, and ref writes still waiting on their debounce are cancelled.

Frames restored from an actor that missed the boot read also get their
refs, which the boot rebuild of asset_refs could not see.

Co-authored-by: Cursor <cursoragent@cursor.com>
server/actorFrames.ts imports generated/actors at load, but the final stage
copied only server/ and shared/, so the container crashed on boot with
ERR_MODULE_NOT_FOUND for /app/generated/actors/index.js.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@kgoedecke kgoedecke closed this Nov 19, 2026
congvc-bot-x99 Bot pushed a commit to cheese-work/doop that referenced this pull request Nov 19, 2026
…-6841)

cheese/main carries its own flake fix (doop-design#433) and the ci-policy R1 push-trigger
rule, so the #64 commits are dropped here and the test files take main's
version. Smoke routes gain /api/agent-runners and /api/fonts and follow the
new /api/model-account view.
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