| 1 | # Delegated semantic deck editing |
| 2 | |
| 3 | Status: specification and final source independently approved by a separate |
| 4 | GPT-6 Astra agent, 2026-11-01, with the machine contract clarification below. |
| 5 | Validation is recorded below. |
| 6 | Author: GPT-6 Astra, 2026-11-01. Paul authorized everyday editing APIs through |
| 7 | the suite's existing API, CLI and MCP connection. This extends the approved |
| 8 | 2026-10-25 agent-access design. Its identity, namespace, privacy, roster and |
| 9 | response-emission rules remain binding, and existing v1 contracts are unchanged. |
| 10 | |
| 11 | ## Contract |
| 12 | |
| 13 | Add `slides_update_deck`, scope `slides:write`, readOnly false, idempotent true. |
| 14 | HTTP, CLI and MCP use the same team-independent descriptor. All five fields |
| 15 | below are required; unknown top-level fields are refused. |
| 16 | |
| 17 | ```json |
| 18 | { |
| 19 | "team": "team-id", |
| 20 | "sqid": "k7m2xq9dwb", |
| 21 | "expected_revision": "12", |
| 22 | "client_id": "1dc98332-7165-43c5-8f98-9546f10146a8", |
| 23 | "ops": [ |
| 24 | {"op":"set_notes","id":"abcdefghijkl","markdown":"Discuss the revised estimate."}, |
| 25 | {"op":"add_slide","layout":"flow","template":"title-body"} |
| 26 | ] |
| 27 | } |
| 28 | ``` |
| 29 | |
| 30 | Sqid retains the exact existing ten-character alphabet and revision retains |
| 31 | the canonical nonnegative decimal string of `Deck.Seq`, at most MaxInt64. |
| 32 | Signs, leading zeros, fractions and overflow are invalid. A new edit must |
| 33 | leave room for one sequence increment. The UUID is nonzero canonical |
| 34 | lowercase hyphenated form. Team is 1–128 characters and must equal the |
| 35 | configured instance team. Accept 1–100 ordered semantic operations, at most |
| 36 | 1 MiB for the whole request. Reject malformed Unicode and duplicate JSON |
| 37 | object keys before decoding op fragments; retain raw numbers and the semantic |
| 38 | distinction between absent keys and null. |
| 39 | |
| 40 | Allowed operation names are `set_meta`, `add_slide`, `remove_slide`, |
| 41 | `move_slide`, `duplicate_slide`, `set_slide`, `set_notes`, `add_block`, |
| 42 | `remove_block`, `move_block`, `set_block`, `set_text` and `set_phone`. |
| 43 | Their fields, references, markdown, rich text, fractional coordinates and |
| 44 | ordering are the existing canonical operation vocabulary in `docs/api.md` |
| 45 | and `core/src/ops.rs`, with no second Go operation interpreter. The exported |
| 46 | descriptor exposes concrete argument fields and types for every supported op, |
| 47 | using per-operation `oneOf` or an equivalent machine schema, so API, CLI and |
| 48 | MCP callers can discover the contract without external documentation. The core |
| 49 | validates operation-specific types, fields and cross-operation references. |
| 50 | The envelope limit and op count are enforced before calling the engine. |
| 51 | Asset registration/removal, upload, export, presentation, sharing and deck |
| 52 | deletion are outside this slice. Existing registered images can still be |
| 53 | referenced by ordinary block operations under their current validation. |
| 54 | |
| 55 | Missing slide/block IDs are minted through existing `mintOpIDs`, including |
| 56 | duplicate-slide block identities. Caller-supplied IDs retain native semantics. |
| 57 | The caller can provide its own IDs when later operations in the same batch |
| 58 | need to refer to newly added objects. No raw Yjs updates or whole-deck JSON |
| 59 | replacement are accepted. |
| 60 | |
| 61 | Success is a small acknowledgement: |
| 62 | |
| 63 | ```json |
| 64 | {"sqid":"k7m2xq9dwb","revision":"13","url":"https://slides.example/d/k7m2xq9dwb","ids":{"1":"mnopqrstuvwx"}} |
| 65 | ``` |
| 66 | |
| 67 | All four fields are required. `ids` is the existing native operation-index |
| 68 | map for server-minted slide/block IDs; duplicate-slide child block identities |
| 69 | are discoverable by reading the resulting deck, as on the existing drive API. |
| 70 | `revision` is the immutable sequence committed by this mutation. A completed |
| 71 | retry returns the same revision and IDs even after later browser edits. It |
| 72 | does not return a stale deck body; `slides_get_deck` gives current content and |
| 73 | revision. Existing create responses keep their current-revision semantics. |
| 74 | Bound the encoded result before commit to the existing 1 MiB result maximum. |
| 75 | |
| 76 | `conflict` means stale expected revision for a new mutation or a reused client |
| 77 | UUID with a different target, expected revision or ordered operation payload. |
| 78 | Current access is checked before disclosing conflict. A stale request never |
| 79 | automatically rebases against a newer deck. The caller reads again and chooses |
| 80 | a fresh UUID for its revised intent. Core refusal is `invalid`; storage, |
| 81 | deadline or engine execution failures are unavailable, not partial success. |
| 82 | Missing/inaccessible decks and other authority failures use existing codes. |
| 83 | |
| 84 | ## Native authority and response boundary |
| 85 | |
| 86 | Only creation requires creator membership; do not treat every slides:write |
| 87 | operation as create. Document editing follows the app's existing deck write |
| 88 | authority: a person who can reach a deck through the native owner/team/grant |
| 89 | seam may edit its document, as `apiOps` does. No new viewer/editor distinction |
| 90 | is invented. Existing independent deck grants survive NotMember or Unknown; |
| 91 | owner/team-rung reach requires Member from the single captured Access. |
| 92 | |
| 93 | At writer reservation and before commit, including completed retries, |
| 94 | reverify the original delegation verifier and unchanged principal fields, |
| 95 | resolve the keyed Home link on the transaction through `ResolveOn`, compare |
| 96 | stable local person ID and address, and recheck live deck reach on that same |
| 97 | transaction. The team write guard wraps the entire mutation/receipt decision. |
| 98 | No outer-pool lookup, HomeOnly fallback, automatic provisioning or roster |
| 99 | network request runs under the writer. A missing or expired required lease |
| 100 | fails closed; an independent current grant is checked on the transaction. |
| 101 | |
| 102 | Remember the exact deck for existing before-header and per-chunk identity, |
| 103 | delegation, live deck and roster checks. Preserve the standing-lease socket |
| 104 | deadline clamp. Loss of authority during emission aborts it; a committed but |
| 105 | unacknowledged edit is recovered through its stable retry UUID. |
| 106 | |
| 107 | ## One canonical edit transaction |
| 108 | |
| 109 | Use the existing semantic engine, op ID minting, `metaRowUpdates`, |
| 110 | `applyOpsOn`, core shape check and canonical projection parser. Do not call |
| 111 | the legacy `applyAgentOps` retry loop: it intentionally retries a busy deck |
| 112 | at its new sequence, which violates this operation's explicit precondition. |
| 113 | |
| 114 | Reserve the SQLite writer using the existing immutable namespace marker. |
| 115 | Recheck local authority, read any existing receipt, then read the current |
| 116 | deck row and compare its sequence to expected_revision. Open a fresh owned |
| 117 | core handle whose snapshot and ordered log reads use the caller's transaction |
| 118 | at that exact sequence; factor a transaction-aware `openDeck` seam if needed. |
| 119 | Never call the outer-pool reader while holding the writer. All handles are |
| 120 | closed/discarded after either commit or rollback. |
| 121 | |
| 122 | For a new request, mint missing IDs on a copy of its op fragments, preserving |
| 123 | the original request for fingerprinting. Apply the batch once through the |
| 124 | canonical engine; require both `Handle.Check` of shared-type structure and |
| 125 | `deck.Parse` of `Handle.JSON` before commit. The app's transaction encloses |
| 126 | the update-log insert, optimistic sequence bump, any deck-row metadata, |
| 127 | actor attribution, receipt and final authority check. If the existing helper |
| 128 | performs inserts before shape checking, these stay inside the uncommitted |
| 129 | transaction and any failed check rolls all of them back. The resulting deck |
| 130 | must also fit the existing 1 MiB canonical get result bound, so this editing |
| 131 | surface cannot successfully create a deck its read operation cannot return. |
| 132 | |
| 133 | Preserve fractional z/box values by retaining raw op JSON and the canonical |
| 134 | JSON projection; never round-trip through the simplified typed Deck struct |
| 135 | as the source of persisted content. All order changes go through the engine's |
| 136 | identity-preserving order keys. Both required checks remain independent gates. |
| 137 | Only after commit publish the new sequence and attempt a native snapshot. |
| 138 | Replays publish nothing and create no extra log entry or actor attribution. |
| 139 | |
| 140 | ## Durable retry and attribution |
| 141 | |
| 142 | Add a separate additive edit-receipt table. Its unique HMAC coordinate binds |
| 143 | operation name, both authority issuers, team, subject, delegated client and |
| 144 | client UUID. The payload HMAC binds sqid, expected revision and ordered |
| 145 | operation content before server-generated IDs. Object key order and harmless |
| 146 | JSON whitespace do not change the fingerprint: canonicalize recursively with |
| 147 | exact JSON numbers, without float64 conversion; number spelling may remain |
| 148 | significant and is documented as requiring an exact semantic retry payload. |
| 149 | Absent and null remain different. No plaintext markdown or op payload is |
| 150 | persisted in the receipt or logged. |
| 151 | |
| 152 | Persist the target deck ID, applied sequence and a sealed acknowledgement |
| 153 | containing the stable returned ID map under a receipt-specific purpose. Use |
| 154 | the existing sealed connection attribution and connection actor on the update |
| 155 | row. The immutable namespace marker's no-adoption checks include new edit |
| 156 | receipts as well as creation receipts and attribution. Marker, receipt, |
| 157 | attribution and content share one transaction and key/issuer/team continuity. |
| 158 | |
| 159 | A matching completed receipt is returned only after current resource and |
| 160 | writer authority checks, before checking expected_revision against the now |
| 161 | current deck. This is why a retry after later changes is safe. Changed payload |
| 162 | conflicts. Concurrent identical submissions commit one batch and return one |
| 163 | stable acknowledgement. A failed write leaves no receipt or generated IDs |
| 164 | claiming a committed result. Recreated app and reopened database must replay |
| 165 | the same applied revision and IDs without rerunning the semantic engine. |
| 166 | |
| 167 | ## Review and validation gates |
| 168 | |
| 169 | Independent highest-capability spec approval precedes implementation and |
| 170 | independent source/evidence review follows. Required gates: |
| 171 | |
| 172 | - Real Home grant/gateway/MCP create-read-edit-read, including text, notes, |
| 173 | slide/block reorder, add/duplicate/remove, metadata and fractional canvas |
| 174 | coordinates. Compare native `openDeck`, the canonical JSON read operation |
| 175 | and browser-rendered HTML from the same state. |
| 176 | - Two concurrent edits from one sequence: one commit, one conflict; exact |
| 177 | duplicate retry after a later native edit and after app restart preserves |
| 178 | that later edit and returns original generated IDs and applied sequence. |
| 179 | - Invalid later op, malformed rich text, missing reference and columns-cycle |
| 180 | rejection leave no partial updates. Independently exercise shape and |
| 181 | projection gates, not merely core input parsing. |
| 182 | - SQL failures at update insert, metadata update, attribution and receipt |
| 183 | persistence roll back sequence, log, metadata and acknowledgement. A |
| 184 | fresh open reads the old deck; no seq publication or snapshot precedes |
| 185 | commit. Completed retries do not apply another op batch. |
| 186 | - Initial/final revocation, unlink, binding corruption, live deck/grant loss |
| 187 | and roster lease expiry, including direct-domain completed-retry tests |
| 188 | independent of emission. Independent granted access under Unknown and |
| 189 | NotMember remains supported; create still requires current membership. |
| 190 | - Exact JSON numbers, null/absence, strict Unicode/duplicate keys, revision |
| 191 | limits, unknown operation names and 100-op/1 MiB bounds. Verify sealed |
| 192 | acknowledgement/attribution and no plaintext content in receipt storage. |
| 193 | - Add the delegated path to the enumerated team-write lapse test. Effective |
| 194 | runtime-failing mutants separately skip revision comparison, completed |
| 195 | receipt payload checking, final writer guard, live transactional reach, |
| 196 | one canonical shape gate and receipt atomicity. |
| 197 | - Restore all mutants; run focused race tests and the full pinned |
| 198 | `.amadan/ci.d/10-gate` (canonical wasm rebuild/cmp, Rust/JS, Go and migrations) |
| 199 | on the final tree. A fast `make ci` alone does not replace this gate. |
| 200 | |
| 201 | This additive operation carries no canary, main-merge or deployment approval. |
| 202 | |
| 203 | ## Independent review record |
| 204 | |
| 205 | On 2026-11-01 a separate GPT-6 Astra agent approved this specification before |
| 206 | implementation, then independently reviewed the final source and selected |
| 207 | adversarial mutations. Final source approval covers this bounded editing |
| 208 | operation and its native transaction/authority integration. It does not approve |
| 209 | main merge, canary behavior or deployment. |
| 210 | |
| 211 | Eight selected mutants failed at runtime: missing revision check, ignored |
| 212 | completed receipt, missing final writer check, new IDs returned on replay, |
| 213 | omitted shared-type shape check, omitted projection parsing, float64 receipt |
| 214 | fingerprints, and ignored receipt persistence failure. Every original was |
| 215 | restored. The exported operation contract contains concrete schemas for all |
| 216 | thirteen allowed semantic operations; the canonical engine remains authoritative. |
| 217 | |
| 218 | Final restored-tree canonical gate passed on 2026-11-01: |
| 219 | `TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 ./.amadan/ci.d/10-gate`. This includes |
| 220 | Rust formatting/clippy/tests, canonical WASM rebuild and byte comparison, |
| 221 | JavaScript tests/vectors/bundle checks, and Go vet/formatting/tests/migrations |
| 222 | and credits. The short temporary directory avoids the macOS Unix-socket path |
| 223 | limit in the existing shutdown test; no application behavior or test was |
| 224 | changed for that environment constraint. |
| 225 | |
| 226 | The final focused race check also passed (313.173s): |
| 227 | `GOMAXPROCS=2 TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 go test -race |
| 228 | ./internal/slides -run |
| 229 | 'TestAgentDeckEdit|TestAgentGatewayToRealSlides|TestAgentTeamSlidesMembership' |
| 230 | -count=1 -timeout 1200s`. It covers the editing boundary, native semantic |
| 231 | parity, real HTTPS CLI/MCP edit/read/retry, and retained roster behavior. |
| 232 | |