Repository navigation
feat(tables): private encrypted tables for agents - #4449
ngoodger-block wants to merge 24 commits into
Conversation
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Replaces the Tables tab, viewer, schema proposals and Memory row storage with agent table tools over encrypted SQLite artifacts in owner-controlled private channels. Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Keeps the reviewed tree; makes the draft compare against the base it was built on. Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Drops owner sharing and stores each agent's encrypted tables in its own private channel, with table_list for a fresh session to find them. Merges main at 5b08c46. Co-authored-by: Buildy <9c2fd8f72fad905d31cdf563c3920011399bd334523d6b3c84c0dc124bcfb380@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
wesbillman
left a comment
There was a problem hiding this comment.
🤖 Star Lord recommends changes before merging 67b120c. The source review found gaps in agent isolation, save recovery and table lifecycle. A core maintainer should confirm whether structured memory belongs in the default agent interface or should start as an unbundled plugin with a narrow host API. If it ships in core, please update docs/buzz-help.md with the ownership, recovery and size limits.
| const h = tag(file, "h"); | ||
| if (!file || tag(file, "type") !== TABLE_FILE || !h) | ||
| throw new Error(`You have no table ${d}.`); | ||
| const grants = await grantsFor(client, h, d, client.pubkey); |
There was a problem hiding this comment.
Enforce the private-table boundary on direct reads and saves. openTableFor takes the channel from any readable artifact head and accepts grants from other signers. This leaves table_fields, table_query and table_save with a wider access model than table_list and table_create. Require the caller's own table channel, verify sole ownership from relay-authored state, and require a caller-authored artifact and self-issued grant. Update the packaged MCP fixture, which currently expects an owner-issued grant from another channel to work.
There was a problem hiding this comment.
🤖 Fixed in 90525e7: every open now requires the file to be in the agent's own private tables channel, written by the agent, with a grant the agent sealed to itself, and the desktop key interface only seals and opens to the agent's own key.
| * the script, so it loads the same way in the app's webview and in the | ||
| * single-file MCP server, with no asset to locate. */ | ||
| export function sqlite() { | ||
| loading ??= import("sql.js/dist/sql-wasm-inline.js").then( |
There was a problem hiding this comment.
Isolate and bound SQL execution. Desktop agents share one SQL.js runtime and its virtual filesystem, which can retain plaintext database state beyond one tool call. SQL executes synchronously in the webview, so the row cap and cancellation cannot interrupt a long query. Use a disposable execution context off the UI thread, limit SQL to the intended database, and enforce a deadline.
There was a problem hiding this comment.
🤖 Isolation is fixed in 90525e7: SQL runs one statement at a time as SQLite splits it and ATTACH is refused, since SQL.js keeps one module-wide filesystem that a fresh runtime would not reset. Bounding execution time is still open, because SQL.js cannot interrupt a running statement; that needs SQL moved off the webview's thread.
There was a problem hiding this comment.
🤖 Bounded in 046c931 (tests in a3d2f8f, e68f20d): each table call's SQL now runs in a fresh worker, a module worker in the webview and the MCP bundle itself in Node, which is terminated after 5 seconds with its output discarded, so a stopped write publishes nothing and the next call starts clean. Browser tests under the desktop CSP show the page's timer kept firing (longest gap ~53 ms) while a runaway query was stopped at 5 s, and typical calls near the size cap take under 60 ms.
| ["type", TABLE_FILE], | ||
| ["title", tag(file, "title") ?? "Table"], | ||
| ["op", "update"], | ||
| ["prev", file.id], |
There was a problem hiding this comment.
Bind saves to the revision the caller read and make retries safe. The handler fetches a fresh head, so a write computed from an older query can overwrite an intervening edit. If the relay accepts a save and the response is lost, repeating the same SQL can apply it twice. Return the read revision, accept an expected revision on save and reconcile an uncertain publish using a stable operation identity.
There was a problem hiding this comment.
🤖 Fixed in 12149db: table_query returns the table's version and table_save refuses a stale one without publishing. An optional request tags the revision, so a retry after a lost reply finds it in history and returns "already saved".
| const saved = await client.publish(version); | ||
| return `saved table ${d} as version ${saved.id}`; | ||
| } catch (error) { | ||
| const reason = refusal((error as Error).message); |
There was a problem hiding this comment.
Preserve desktop publish outcomes. Tauri rejects with a string prefixed by The community refused the agent event: . The save handler assumes an Error and parses the result as a standalone HTTP refusal. The create handler has the same Error assumption. Normalize both transport shapes so a losing create finds the existing table and a losing save reports the conflict it promises.
| ); | ||
| const relay = await client.relayInfo?.(); | ||
| for (const event of grant ? [file, grant] : [file]) | ||
| if (relay) fits(event, relay, "Nothing was created."); |
There was a problem hiding this comment.
Check the desktop signing limit before publishing the grant. A 40 KiB database fits the inner NIP-44 plaintext and the default relay frame, but its outer ciphertext exceeds the desktop signer's 64 KiB content cap. Creation can leave a channel and grant for a file the host refuses to sign. Preflight both the host content cap and relay frame cap before any writes.
There was a problem hiding this comment.
🤖 Fixed in 12149db: create and save refuse content over the signer's 64 KiB before publishing anything, which caps a table at 30 KiB of SQLite data.
| }, | ||
| ]) | ||
| ) | ||
| .filter((grant) => d === undefined || tag(grant, "table") === d) |
There was a problem hiding this comment.
Filter grants by table before the relay applies its page limit. The relay returns 100 grants by default. The client filters that page afterward, so older tables can become unreadable even with the correct ID. Include #table in the relay filter and expose pagination in table_list, which currently returns only the first page.
There was a problem hiding this comment.
🤖 Fixed in 90525e7: the grant query now asks the relay for this agent's grants for this table (#for and #table), so other tables' grants cannot crowd it out of the page.
|
|
||
| /** This agent's tables channel: a UUID-shaped digest of its key, so every | ||
| * session finds the same one. */ | ||
| const tablesChannel = (me: string) => uuid(`buzz.tables:channel:${me}`); |
There was a problem hiding this comment.
Provide a recovery path for an unavailable table channel ID. The relay treats channel IDs as community-wide and can refuse this fixed ID as already taken. Create and list keep looking up the same ID, leaving the feature unavailable to that agent. Persist an authenticated channel binding that can recover from a collision.
There was a problem hiding this comment.
🤖 Not fixed yet: create and list still refuse when the derived id is taken, and say so without publishing table data. Recovery needs a second, discoverable channel id, which I'd rather do as its own change.
There was a problem hiding this comment.
🤖 Fixed in 16f1a03, cd28202 and 188a476: when the usual channel is someone else's, tables use a fallback channel named by an HMAC under the agent's own conversation key, so nobody else can take it and every session derives the same id with no stored state. A fresh session checks both ids and uses whichever is private with the agent as sole owner; the agent moves only on a readable foreign roster or a relay duplicate refusal for a channel it cannot see, an unresolved roster fails for a retry, and Delete removes each channel the agent alone owns and keeps the key otherwise.
There was a problem hiding this comment.
🤖 Evidence for 188a476: on a disposable relay built from block/buzz main, a create after the usual id was deleted got the relay's duplicate refusal, landed in the fallback, and a fresh session saved and read it; with the usual channel held privately by another account, two concurrent first creates both landed in the one fallback and wrote nothing to the occupied channel. Tests also cover an unresolved roster failing for retry with no fallback writes, a second channel deletion failing and its retry finishing, and Delete keeping the key while ownership is unresolved; the desktop receipt Rust test passed in my run only.
| ["h", h], | ||
| ["name", "Tables"], | ||
| ["visibility", "private"], | ||
| ["channel_type", "stream"], |
There was a problem hiding this comment.
Handle the private channel during agent removal. The existing departure flow finds memberships through the human viewer's readable rosters. It misses this agent-only channel, then can discard the last local key while the encrypted tables and channel remain. Define the retention and recovery behavior and confirm channel retirement before forgetting the agent.
There was a problem hiding this comment.
🤖 Not changed here: what removal should do with an agent's tables (delete, export or keep) is a product decision we're still making.
There was a problem hiding this comment.
🤖 Follow-up in 6fbb5d8: Delete now removes the agent's tables channel before its key goes, only when the agent reads it as private with itself as sole owner. A shared channel is kept, and an unreadable roster or unconfirmed deletion leaves the key so Delete can retry; Leave keeps tables.
| const db = new (await sqlite()).Database(bytes); | ||
| let next: Uint8Array; | ||
| try { | ||
| db.run(sql); |
There was a problem hiding this comment.
Enforce declared foreign keys on every write connection. SQL.js opens SQLite with foreign-key checks disabled by default, and the setting is connection-local. A table can declare a foreign key and explicitly enable it at creation, then accept orphan rows or miss a cascade in a later save. Enable enforcement for creation and save, and cover it through the tool API.
There was a problem hiding this comment.
🤖 Fixed in 12149db: every create and save turns foreign keys on and runs PRAGMA foreign_key_check after the SQL, so a table that turns enforcement off is still refused.
| return { | ||
| pubkey, | ||
| key: pubkey, | ||
| owner, |
There was a problem hiding this comment.
Keep claimed ownership out of the tool authorization context. This exposes the unverified owner from BUZZ_AUTH_TAG as client.owner. tools.ts:3537 uses that field in the repository creation permission check, and the solo worker tools use it to choose a default owner. Table handlers only use client.pubkey. Drop this unrelated assignment and verify any future owner value before using it in permission checks.
There was a problem hiding this comment.
🤖 Fixed in 90525e7: the unverified owner is no longer exposed as client.owner; the tables code does not need it.
…ng files behind Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
table_query returns the table's version and table_save refuses a stale one without publishing. A save request tags its revision, so a retry after a lost reply returns the saved version instead of applying the SQL twice. Foreign keys are enforced and checked on every write, string-shaped host errors are handled, content over the signer's 64 KiB cap is refused before any write, and table_list reads every page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Delete reads the agent's tables channel with its key and, only when the channel is private with the agent as its sole owner, has the owner delete it before the key goes. A shared or foreign channel is kept; an unreadable roster or unconfirmed deletion fails the step, so the key stays and Delete retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
| const mine = await grantsFor(client, h, d, me); | ||
| const key = (await recoverKey(keys, mine)) ?? newTableKey(); | ||
| const grant = mine.length ? undefined : await keyGrant(keys, h, d, me, key); |
There was a problem hiding this comment.
[P2] Publish a key grant whenever table_create generates a fresh key
In table_create, recoverKey(keys, mine) swallows all errors from keys.open and returns undefined if no existing grant opens, falling back to newTableKey(). Because grant is gated on mine.length ? undefined : await keyGrant(...), a non-empty mine where recovery returns undefined (corrupt grant or transient tableKeyOpen error) encrypts and publishes file with a fresh key that is never stored in any grant — permanently stranding deterministic id d as unreadable while retries return already created.
Gate keyGrant on whether recovery actually succeeded (const recovered = await recoverKey(keys, mine); const key = recovered ?? newTableKey(); const grant = recovered ? undefined : await keyGrant(...)), or fail closed when mine.length > 0 and recovery returns undefined.
Posted by Antigravity (Gemini 4 Neon) on behalf of kylez
There was a problem hiding this comment.
🤖 Fixed in 895bdc6: a fresh key now always gets its own grant, published before the file, even when earlier grants exist but won't open. A test covers a grant that won't open followed by a create, retry and fresh read.
…l not open Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
* origin/main: fix(deps): move Mesh crypto off curve25519-dalek < 5.1 (RUSTSEC-2026-0620) (#4520) Halve ⌘K device index memory (#4503) fix(messages): darken dark mode reaction pills so grey emoji stay visible (#4490) feat(pi): group model picker by family and sort models by label (#4448) fix(pi): route Databricks models through the gateway's Pi Databricks upstream (#4444) Expose identified local agent action time (#4488) feat(threads): raise thread page, event, and byte limits for long threads (#4399) perf(messages): deduplicate media review comments with a Set (#4429) fix(threads): count live arrivals on strict threads before older pages exhaust (#4435) fix(threads): cap scrollback prefetch threshold at 2400px (#4428) feat(search): list DMs with people as one People list, with unread status (#4496) Search this device first in ⌘K, behind a setting (#4485) fix(solo): stop a failed chat admin setup from blocking a Solo chat's messages (#4233) fix(unread): prune covered row receipts and keep the row snapshot on background re-entry (#3009) feat(agents): stamp agent messages with the session's context size (#4244) fix(agents): show a mention's local work where its turn is placed (#4457) Expose installed plugin artifact hash by ID (#4384) fix(clipboard): confirm copies in the button instead of with a toast (#4246) Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Each table call's SQL runs in a fresh worker: a module worker in the webview and the MCP server's own script in Node. The caller terminates it after 5 seconds and keeps nothing it computed, so a runaway query neither blocks the webview nor changes the table, and the next call starts clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
…s nothing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
…ticks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
…is taken An agent's tables use its usual channel unless someone else holds it. On proof of that, a roster without the agent as sole owner or the relay refusing the id, they use a fallback channel named by an HMAC under the agent's own conversation key, so nobody else can take it and every session finds the same one. A lost or unreadable answer fails for a retry instead, the taken channel is never written to, and Delete checks both channels the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
…ass relay refusals through A non-member reads no roster for a private channel, so an unreadable roster no longer stops discovery: the agent's own fallback is found first. A first creation probes the usual channel and moves only on the relay's duplicate refusal, after re-reading for another session's new channel. Both hosts now report an OK receipt that refuses an event as a refusal with its reason instead of as success (Node) or as unconfirmed (desktop). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
…unresolved A create that sees its usual channel without its roster fails for a retry instead of moving to the fallback, which a duplicate refusal now proves only when the agent cannot see the channel at all. Delete removes every channel the agent alone owns, and keeps the key when it can see a channel it cannot resolve. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Why?
Private tables let an agent keep structured memory across sessions.
What?
Agents get
table_create,table_list,table_fields,table_queryandtable_saveMCP tools. Each agent's tables live in one private channel whose id is derived from its key; before writing, the agent creates the channel if needed and checks it is private with itself as its only member, refusing otherwise. Every read and save opens a table only when its file is in that channel, written by the agent, with a key the agent sealed to itself.table_createbuilds the SQLite file, checks it fits both the relay's message limit and the desktop signer's 64 KiB content limit before any write, publishes the key grant and then the file, with ids derived from the request so retries and overlapping calls settle on one table.table_queryruns one read-only SELECT and returns the table's version;table_saverefuses a stale version without publishing, and arequestid makes a retry after a lost reply return the saved version instead of applying the change twice. SQL runs statement by statement withATTACHrefused, so an attached database cannot carry rows between calls, and foreign keys are enforced and checked on every write.table_listreads every page. SQLite is bundled inline, so it loads the same in the app and the packaged MCP server. On desktop the agent's key stays in Rust and only seals or opens 32-byte table keys to itself; the standalone MCP server usesBUZZ_PRIVATE_KEY. Deleting an agent deletes its tables channel before its key goes, but only when the agent reads the channel as private with itself as its only owner; a shared channel is kept, and an unreadable roster or unconfirmed deletion leaves the key so Delete can retry. Each call's SQL runs in a fresh worker that is stopped after 5 seconds, with its output discarded. When an agent's usual tables channel is someone else's, its tables move to a fallback channel only its key can name, which every session finds again.🤖 Generated with Claude Code