mirror of
https://github.com/block/buzz.git
synced 2026-11-29 12:42:49 +00:00
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:
@@ -194,6 +194,13 @@ echo "# Canvas from stdin" | buzz canvas set --channel "$CHANNEL_ID" --content -
|
||||
# canvas get
|
||||
buzz canvas get --channel "$CHANNEL_ID"
|
||||
# Expected: raw markdown string, or: null
|
||||
|
||||
# canvas set guarded by the head it read
|
||||
HEAD=$(buzz canvas history --channel "$CHANNEL_ID" --limit 1 | jq -r '.[0].event_id')
|
||||
buzz canvas set --channel "$CHANNEL_ID" --content "# Guarded" --expected "$HEAD" | jq .
|
||||
# Expected: {"event_id":"...","accepted":true,...}
|
||||
buzz canvas set --channel "$CHANNEL_ID" --content "# Stale" --expected "$HEAD"; echo "exit $?"
|
||||
# Expected: {"error":"conflict",...} on stderr, exit 5, canvas unchanged
|
||||
```
|
||||
|
||||
### 6.3 Messages
|
||||
@@ -599,7 +606,7 @@ buzz channels delete --channel "$FORUM_ID" | jq .
|
||||
| 21 | `channels add-member` | ☐ | Needs admin:channels |
|
||||
| 22 | `channels remove-member` | ☐ | Needs admin:channels |
|
||||
| 23 | `canvas get` | ☐ | |
|
||||
| 24 | `canvas set` | ☐ | Direct and stdin |
|
||||
| 24 | `canvas set` | ☐ | Direct, stdin and `--expected` |
|
||||
| 25 | `reactions add` | ☐ | |
|
||||
| 26 | `reactions remove` | ☐ | |
|
||||
| 27 | `reactions get` | ☐ | |
|
||||
|
||||
Reference in New Issue
Block a user