| 1 | # Delegated spreadsheet operations |
| 2 | |
| 3 | Status: approved by GPT-6 Astra after independent design review against |
| 4 | baseline 6d700d6. Source review, tests, CI and deployed verification remain |
| 5 | separate gates. Paul requested |
| 6 | suite-wide API, CLI and MCP access after browser permission, authorized a |
| 7 | transport owned by Oficina until Rastrillo converges, and selected CLI, Paseo, |
| 8 | ChatGPT and Claude as the first clients. |
| 9 | |
| 10 | ## Authority and transport |
| 11 | |
| 12 | Opt in with SHEETS_AGENT_ISSUER and SHEETS_AGENT_TEAM alongside Home. Validate |
| 13 | complete configuration before storage. An online verifier checks a short-lived |
| 14 | app-audience credential for this exact origin plus /api/v1. Introspection's |
| 15 | identity_issuer must exactly match configured Home.Issuer before resolving its |
| 16 | opaque subject through the existing connection bridge to an existing member. |
| 17 | No EnsureMember, address matching, synthetic browser cookie or local agent key. |
| 18 | Recheck current admission and sheet grants for every operation. Grant admission |
| 19 | alone never grants create authority. Existing explicit-grant/team-role semantics |
| 20 | remain authoritative; preserve roleFor precedence in new error-returning authority and tab-ownership |
| 21 | helpers, and use grant-scoped queries, never scope.Owned. The existing boolean |
| 22 | helpers erase storage errors and cannot satisfy the unavailable contract. |
| 23 | Revoked delegation, unlinked identities and lost applicable permission refuse. |
| 24 | |
| 25 | The shared Oficina registry defines identical HTTP, CLI and MCP contracts. |
| 26 | Bearer routes are separate from browser CSRF/session routes. Sanitized errors |
| 27 | contain no values, formulas, sheet titles or tab names. Unknown or inaccessible |
| 28 | items both return 404; infrastructure failure returns unavailable, not empty |
| 29 | results. Request bodies are at most 1 MiB; every encoded result is at most 1 MiB, with |
| 30 | an explicit oversize failure and no partial success. Metadata enumeration is |
| 31 | bounded before decryption/materialization: list returns sheet metadata only; |
| 32 | tab discovery is a separate bounded sheets_list_tabs (sheets:read) operation (default 20, |
| 33 | maximum 100, ascending exact ID cursor) on one currently readable sheet. |
| 34 | |
| 35 | ## First operations |
| 36 | |
| 37 | - sheets_list (sheets:read): live/non-filling permitted sheets, default 20 and |
| 38 | maximum 100 per page, descending numeric ID cursor decoded exactly. Return |
| 39 | canonical decimal ID strings, title and URL. Decode sealed titles/names |
| 40 | through store helpers and fail if opening fails. A grant join filters before |
| 41 | pagination; guests see only explicitly granted sheets. |
| 42 | - sheets_get_range (sheets:read): one tab, integer start row/column and height/ |
| 43 | width, at most 500 cells. Return coordinates, raw input, calculated display |
| 44 | value/error, and the tab revision as a decimal string. Read from a single |
| 45 | current handle while its mutex is held so values and revision are coherent. |
| 46 | A content-bearing result larger than 1 MiB fails explicitly without truncation. |
| 47 | - sheets_create (sheets:write): nonzero UUID client_id, title, first tab name, |
| 48 | and up to 500 unique cell coordinates/raw inputs, within existing row/column, |
| 49 | raw-input, total-cell and calculation limits. Accept the same formulas and |
| 50 | value rules as the browser. The response contains the sheet/tab identifiers, |
| 51 | member URL, and a current coherent snapshot revision. This is Handle.Version's |
| 52 | next-stamp watermark, matching range reads, not SetBatch.Report.Version's last |
| 53 | assigned stamp; a retry after a browser edit returns the current watermark. It sends no invitation. |
| 54 | |
| 55 | This initial creation path supports a populated budget or table directly. |
| 56 | Editing existing sheets, formatting, extra tabs, comments, sharing and import/ |
| 57 | export are later capability slices. Editing will require a reviewed revision |
| 58 | precondition and guarded SetBatch transaction, rather than optimistic read then |
| 59 | unconditional write. These omissions remain visible in the capability matrix. |
| 60 | |
| 61 | ## Atomic creation and retries |
| 62 | |
| 63 | Refactor the existing newSheet creation service only as needed to reuse its |
| 64 | sealed title/tab name and owner grant invariants inside an outer transaction. |
| 65 | A receipt insertion first takes SQLite's writer reservation. Recheck the |
| 66 | existing local operator and current create membership inside that transaction. |
| 67 | Create metadata, first tab, owner grant, cells through the existing parser/ |
| 68 | calculation/store machinery, attribution and receipt in that same transaction. |
| 69 | Add an unregistered transaction-local handle constructor: store.Open currently |
| 70 | registers a handle and must not be used with tx. Discard this transaction handle |
| 71 | on both success and failure; it retains tx and must never be cached even after |
| 72 | commit. If needed, open a fresh canonical app-DB handle after commit. A rollback |
| 73 | must not leave in-memory phantom cells. |
| 74 | Reuse SetBatch's parser, calculator, shape limits and version assignment. All |
| 75 | raw values, calculated strings, titles and tab names remain sealed on disk. |
| 76 | |
| 77 | Receipt coordinates use a purpose-separated HMAC over an unambiguous encoding |
| 78 | of identity_issuer, delegation issuer, Home subject, OAuth client, selected team |
| 79 | and UUID. Attribution uses the same authority namespace. Payload fingerprint uses |
| 80 | a separate HMAC over canonical typed title/tab/cells, sorted by coordinate so |
| 81 | cell ordering alone does not change meaning. Only digests and sheet ID enter |
| 82 | receipts. Persist a keyed marker at first enablement and verify on startup and |
| 83 | before each agent write; the marker also binds identity issuer, delegation |
| 84 | issuer and configured team. A changed key or authority configuration refuses |
| 85 | writes until explicit operator migration. Never reset the marker to make old retries appear new. |
| 86 | |
| 87 | Identical retries recheck current authority and return the existing sheet; |
| 88 | changed input conflicts. A deleted sheet is never recreated. A retry after a |
| 89 | browser cell edit returns the existing sheet without applying initial values |
| 90 | again. Client/operator attribution identifies the existing member and sealed |
| 91 | client label, and does not mint a local agent/person. Commit precedes any cache |
| 92 | insertion or publish notification. New sheet creation needs no preexisting |
| 93 | subscriber content broadcast. |
| 94 | |
| 95 | ## Evidence and release |
| 96 | |
| 97 | Test linked Home identity, identity-issuer mismatch before local lookup, |
| 98 | current team and sheet role enforcement, an authorized sheet paired with a |
| 99 | foreign tab, authority storage failures, explicit guest grants, no provisioning, |
| 100 | cookie-only refusal, lost authority, expired/revoked credentials, exact cursors, |
| 101 | read bounds and coherent revision. Real SQLite and calculation fixtures cover |
| 102 | Unicode, formulas, dependent values, concurrent retry, changed payload, deleted |
| 103 | replay, browser edits before retry, restarted process, changed receipt key, and equal subject/client/team/UUID under a changed issuer |
| 104 | namespace (refused without migration). |
| 105 | Inject failure after cells and grant creation to prove the whole transaction |
| 106 | rolls back and no cached handle survives. Inspect database/WAL/receipt/log bytes |
| 107 | for title, tab-name, raw-value and calculated-string canaries. Exercise actual |
| 108 | operations through the suite HTTP/MCP gateway. New gates must fail against |
| 109 | material adverse mutations. Run complete CI, highest-capability branch review, |
| 110 | and deployed canary verification before merge. Source/spec approval does not |
| 111 | claim deployment. |
| 112 | |
| 113 | ## Store foundation review (2026-10-25) |
| 114 | |
| 115 | GPT-6 Astra approved the first store slice after two calculation-completeness |
| 116 | findings were fixed. ReadRange holds one handle lock for raw/calculated values |
| 117 | and revision, refuses a tab with durable dirty markers, and refuses nonempty |
| 118 | inputs with missing caches. Capped browser recalculation and unrecoverable |
| 119 | corrupt cache states therefore produce explicit failure rather than old or |
| 120 | empty values at a new revision. InitializeTab never registers its transaction |
| 121 | handle and shares the caller's atomic commit/rollback. Focused race tests passed. |
| 122 | Five effective mutations failed: cache transaction handle, remove range lock, |
| 123 | remove initial-tab emptiness guard, ignore dirty markers, ignore missing cache. |
| 124 | This is store-slice approval; app adapter, full CI, whole-branch review and |
| 125 | deployed canary remain required. |
| 126 | |
| 127 | ## Identifier and write-boundary amendment (2026-10-25) |
| 128 | |
| 129 | GPT-6 Astra approved correction of the original Sqid wording: this baseline's |
| 130 | browser routes use decimal sheet/tab IDs. Expose IDs and cursors as JSON strings |
| 131 | containing canonical positive decimals up to 9223372036854775807. Reject signs, |
| 132 | leading zeroes, whitespace and overflow; omit the cursor for the first page. |
| 133 | Do not introduce a second ID scheme. |
| 134 | |
| 135 | Contracts must be identical across teams; enforce the selected target team at |
| 136 | invocation. Reject malformed Unicode before lossy decoding. Reverify delegation |
| 137 | at the reserved writer boundary and before commit, preserving subject, client, |
| 138 | grant, team and scope; failure rolls back creation. Keep those network checks |
| 139 | separate from transaction-local identity queries. Validate the bounded create |
| 140 | result before commit, and preserve recoverable client attribution sealed outside |
| 141 | the digest-only receipt. These amendments are approved design, not source |
| 142 | approval for the forthcoming app adapter. |
| 143 | |
| 144 | ## Home roster compatibility (2026-10-30) |
| 145 | |
| 146 | In provisioned team mode the roster replaces stored team_role and the local |
| 147 | allowlist as standing. Agent configuration must match the verified roster team. |
| 148 | Resolve only an existing Home link, without the browser's Home-only fallback. |
| 149 | Capture one Access for the verified Home subject and retain it through registry |
| 150 | checks, the writer transaction, completed retries and every response chunk; |
| 151 | Unknown is latched and never refreshed within a request. Creation requires |
| 152 | Member. Read permissions retain explicit-grant precedence, including refusal of |
| 153 | unknown roles: a creator's self-grant needs membership, an independent share |
| 154 | survives removal. Filter these grants before pagination. Unknown full lists |
| 155 | return unavailable even when independent shares remain; an exact shared item |
| 156 | can still be read. Socket deadlines cannot exceed the captured membership lease |
| 157 | or a shorter caller deadline. Non-team behavior is unchanged. GPT-6 Astra |
| 158 | reviewed this compatibility plan; final source/evidence review is separate. |
| 159 | |