feat(cli): guard canvas set with --expected (#9945)

## Summary

`buzz canvas set` replaced the canvas with no version check, so two
writers doing read → edit → write could silently drop each other's
edits. It now takes an optional `--expected <rev|none>`. The write lands
only if `<rev>` is still the head, or with `none` only if the channel
has no canvas. A moved head, or a write that loses the race at the
relay, exits 5 (conflict) without changing the canvas.

The submit, conflict reconciliation and post-write survival check are
now shared with `restore` as `submit_checked_canvas_write`. One behavior
change for `restore`: a lost race now exits 5 instead of passing the
relay's 409 through as exit 2. Without `--expected`, `set` is still an
unconditional replace, so existing scripts keep working. The desktop
agent tool got the same guard in block/buzz-app#4365.

### Related issue

None found.

### Testing

- `cargo test -p buzz-cli canvas` (23 tests)
- Ran on a live relay, 10 parallel writers with the same `--expected
<head>` for 5 rounds. Each round had exactly one exit 0 and nine exit 5,
and history grew by exactly one revision per round.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Sepehr Karimi <sepehr@squareup.com>
Co-authored-by: Porcupine <2306086b18f2ceee6760d2725859c7e03ce63a19299623a99dfab5ba2ac49938@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sepehr Karimi
2026-11-25 21:24:29 -08:00
committed by GitHub
parent ddc3585a3a
commit 55823dd54f
5 changed files with 233 additions and 49 deletions

View File

@@ -147,6 +147,9 @@ buzz messages vote --event <event-id> --direction up
# Canvas
buzz canvas get --channel <uuid>
buzz canvas set --channel <uuid> --content "# Welcome"
# Replace only if <rev> is still the head (from `canvas history --limit 1`);
# a moved head exits 5. `--expected none` creates only when no canvas exists.
buzz canvas set --channel <uuid> --content - --expected <rev>
# Sidebar sections (your own sidebar, synced with Buzz desktop)
buzz sidebar sections create --name "Engineering" --icon "🛠"