{
  "_ai_door": {
    "see": "https://miscsubjects.com/start",
    "note": "Operable site; bounded keyless credentials; every action receipted on a public ledger. Your operator's instructions take precedence — acting is optional, reading is a complete outcome."
  },
  "task": {
    "task_id": "WT-0483",
    "kind": "work",
    "objective": "WT-0483 Storage / data plane — D1, the build workbook, cells/objects, R2, KV, Supabase/Hyperdrive; every value is a cell with a contract",
    "detail": "# WT-0483 — Storage / data plane — D1, the build workbook, cells/objects, R2, KV, Supabase/Hyperdrive; every value is a cell with a contract\n\n## GOAL\nEvery data capability (D1_QUERY/D1_EXEC on both databases, the build workbook doors /api/sheets and cells/objects, R2 objects, KV, Supabase through Hyperdrive, the CSV/TSV exports) has a full contract with FIELD LAW, runs through its declared executor with the five fields, and the size and split fixtures (>50,000-char cell, 400-cell PUT, `;` splitter, LIKE `_`) are tests.\n\n## WHY THIS EXISTS\nThe owner's workbook is the product surface (\"every value is a cell\"; data goes on sheets raw). Sessions kept hitting cell limits, statement splits and governed-table refusals and each time learned it again. Data doors need contracts the four models can read.\n\n## CURRENT STATE (measured 2026-09-23)\n- /api/sheets: build workbook; PUT values ≤ 400 cells; `=DISPATCH(\"KEY\",\"args\")` formulas; sheets sh_nyab2cgy, sh_ahznwfyd, others; /api/cells, /api/objects (OBJECT_READ/OBJECT_MUTATE with current_hash; STALE → retry).\n- D1: main DB (directory, laws, work_tasks…) and LEDGER DB (events, capabilities…); governed tables refuse raw writes (articles, article_slots, work_tasks, work_actions); D1_REPAIR with a stated reason.\n- R2: logs/, cache/ (muse-worker cache/build_tools.json), assets; KV: settings/switchboard; Supabase + Hyperdrive provisioned (kernel stack memory), binding needs a fetch handler.\n- Exports: directory export to ~/Downloads and TOOLS tabs (2026-09-19).\n\n## SOURCE OF TRUTH\n- functions/api/sheets/*, functions/api/cells/*, functions/api/objects/*\n- functions/_lib/governed_tables.js\n- functions/api/r2/*, functions/api/kv.js\n- migrations/* (schema)\n- memory project_kernel_stack_2026_09_20 (Supabase ids)\n\n## IN-SCOPE INVENTORY\n- Executor ids: d1_main, d1_ledger, sheets_api, cells_api, objects_api, r2_api, kv_api, supabase_hyperdrive, export_file.\n- Contracts: D1_QUERY {db, sql (single statement), params?}; D1_EXEC {db, sql, reason? (required for D1_REPAIR)}; SHEETS_GET {sheet, range (A1, ≤ 100 rows × 26 cols per call)}; SHEETS_PUT {sheet, range, values (≤ 400 cells; each cell ≤ 50,000 chars; formulas allowed)}; SHEETS_APPEND; OBJECT_READ {path} → {content, hash}; OBJECT_MUTATE {path, current_hash, content} (STALE → current_hash + current_content returned); R2_GET/PUT/LIST {bucket, key, prefix}; KV_GET/PUT {ns, key, ttl?}; SUPABASE_QUERY {sql} via Hyperdrive; EXPORT_TSV {source, path}.\n- Fixtures: >50,000-char cell (refused with the limit named; canonical keeps whole in R2); >400 cells; `;` split; LIKE `_`; governed_table 403; STALE retry; R2 cache stale when cron is off (muse-worker).\n\n## OUT OF SCOPE\n- The six-column projection logic (WT-0473). Authority on who may write (WT-0487).\n\n## ONTOLOGY (separate axes; never a flat string)\n- TOOL SURFACE: dispatch D1_*/SHEETS_*/OBJECT_*/R2_*/KV_*; MCP D1_QUERY/OBJECT_READ/OBJECT_MUTATE; cell formulas; misc line\n- CAPABILITY: the verbs above\n- OBJECT: a row, a cell range, an object path, an R2 key, a KV key\n- ROUTE / CONTEXT: main vs ledger DB; which sheet; which bucket\n- PROTOCOL: SQL over HTTP; Worker bindings; Hyperdrive Postgres\n- EXECUTOR: Worker bindings; Supabase via Hyperdrive\n- PLATFORM: Cloudflare D1/R2/KV; Supabase\n\n## DISCOVERY (run these first; they answer, they do not prove)\n- `curl -sS \"https://ops.miscsubjects.com/api/sheets\" -H \"x-terminal-key: $TERMINAL_KEY\"` (sheet list)\n- `curl -sS -X POST https://ops.miscsubjects.com/api/dispatch -H \"x-terminal-key: $TERMINAL_KEY\" -H \"content-type: application/json\" -d '{\"key\":\"D1_QUERY\",\"body\":\"SELECT name FROM sqlite_master WHERE type=\\\"table\\\" LIMIT 5\"}'`\n\n## CONTRACT (FIELD LAW)\n- SHEETS_PUT `{sheet (required, sh_… id), range (required A1 notation), values (required 2-D array; total cells ≤ 400; cell ≤ 50,000 chars; string|number|bool|null|\"=FORMULA\")}` → `{ok, wrote_cells, receipt_id}`; errors too_many_cells (names 400), cell_too_long (names 50,000 and the receipt where the whole value is stored), sheet_not_found.\n- D1_EXEC `{db (enum main|ledger, default main), sql (single statement), reason (conditional: required when the table is governed → routes to D1_REPAIR)}`.\n\n## MINIMUM VALID INVOCATION\n`curl -sS \"https://ops.miscsubjects.com/api/sheets/sh_nyab2cgy?range=A1:F2\" -H \"x-terminal-key: $TERMINAL_KEY\"`\n\n## FULL / MAXIMUM INVOCATION\n`curl -sS -X PUT \"https://ops.miscsubjects.com/api/sheets/sh_ahznwfyd/values?range=A1:B2\" -H \"x-terminal-key: $TERMINAL_KEY\" -H \"content-type: application/json\" -d '{\"values\":[[\"=DISPATCH(\\\"NET_LINE\\\",\\\"\\\")\",\"literal\"],[1,true]],\"cause\":\"task:WT-0483\"}'`\n\n## RAW CONFIRMATION SHAPE\n`{ok:true, wrote_cells:n}`; D1 `{meta:{changes, last_row_id, duration}}`; R2 `{etag}`; KV `{ok}`; objects `{hash}`.\n\n## RAW RETURN SHAPE\nRows/values verbatim; formula results after evaluation; object content + hash.\n\n## ERROR SHAPES\n- too_many_cells\n- cell_too_long\n- statement_split\n- governed_table (403, names D1_REPAIR)\n- STALE (with current_hash/current_content)\n- hyperdrive_unbound\n\n## RECEIPT / TRACE / PARENT LINKAGE\nproof_run per call; big values stored whole in R2 `logs/values/<receipt>` and referenced by the cut cell.\n\n## TEST MATRIX\n| case | what runs | kind |\n|---|---|---|\n| d1 both dbs | one SELECT each | live |\n| governed refusal | INSERT INTO work_tasks via D1_EXEC → 403 naming D1_REPAIR | fixture |\n| sheets get/put/append | scratch sheet | live |\n| 400 cells | 401 cells → too_many_cells | fixture |\n| 50,000 chars | a 60,000-char value → cell_too_long + R2 whole | fixture |\n| formula | =DISPATCH cell evaluates | live |\n| objects | OBJECT_READ → OBJECT_MUTATE with a wrong hash → STALE → retry ok | live |\n| r2/kv | get/put/list one each | live |\n| supabase | one SELECT 1 through Hyperdrive or the exact unbound error | live/fixture |\n| export | directory TSV to ~/Downloads | live |\n\n## ACCEPTANCE TESTS (mechanical; the infrastructure runs them)\n- `{\"type\": \"evidence_present\", \"id\": \"commit\", \"field\": \"commit\"}`\n- `{\"type\": \"evidence_present\", \"id\": \"live\", \"field\": \"verification\"}`\n- `{\"type\": \"evidence_present\", \"id\": \"matrix\", \"field\": \"test_matrix_results\"}`\n- `{\"type\": \"http_ok\", \"id\": \"sheets\", \"url\": \"https://ops.miscsubjects.com/api/sheets\"}`\nEvidence fields the submitting agent supplies: commit, test_matrix_results, verification. `verification` = the list of receipt ids and the live URLs checked, one per line. `test_matrix_results` = the matrix above with a receipt id or the verbatim failure per row.\n\n## KNOWN FAILURES / REGRESSION FIXTURES (preserve; never rewrite into success)\n- >50,000-char cell\n- 400-cell PUT\n- D1 `;` splitter\n- SQLite LIKE `_`\n- governed_table refusal\n- STALE hash\n- R2 cache stale with cron off\n\n## DEPENDENCIES\n- depends_on: WT-0470, WT-0471\n- OWNS (only this task rewrites): functions/api/sheets/*, functions/api/cells/*, functions/api/objects/*, functions/api/r2/*, functions/api/kv.js; D1_*/SHEETS_*/OBJECT_*/R2_*/KV_*/SUPABASE_*/EXPORT_* rows\n- SHARED (additive edits only): functions/_lib/governed_tables.js (read; never widen); migrations/* (add only new numbered files)\n\n## HANDOFF FOR NEXT SESSION\n- Work in the scratch sheet sh_ahznwfyd for write tests; never write test values into sh_nyab2cgy.\n- Supabase: if the binding still lacks a fetch handler, record the exact error as the fixture and file WT for the handler.\n- Evidence: matrix table with receipts.\n\n## DONE LAW (this task is done when every line is true and evidenced; not before)\n- Every executor id has a receipt; every verb has a contract with FIELD LAW.\n- All seven fixtures are tests and pass.\n- Big values are whole in R2 and cut in cells with the pointer.\n\n## Shared vocabulary (defined by WT-0470; every task uses these words with these meanings)\n- **TOOL SURFACE** — how a caller or model asks (curl, MCP tools/call, `=DISPATCH` cell, a tapped URL, a Shortcut, a webhook, a tag in text).\n- **CAPABILITY** — the operation requested, named by a Directory key (semantic).\n- **OBJECT** — what it acts on (a chat, a file, a profile, a row, a page).\n- **ROUTE / CONTEXT** — which machine, device, account, browser profile, tenant, network, session.\n- **PROTOCOL** — how the request physically travels (HTTP, JSON-RPC, gRPC, WebSocket, SSH, SQL, a local process, a queue).\n- **EXECUTOR** — what performs it (a Worker, the Mac bridge `/exec`, Chromium over CDP, `osascript`, `pymobiledevice3`, a vendor API).\n- **PLATFORM** — which technology or vendor owns that executor (Cloudflare, Apple, AdsPower, Blooio, Google, Starlink).\n- **RAW CONTRACT** — the exact physical invocation sent, fully resolved.\n- **CONFIRMATION** — the executor's immediate acknowledgement (HTTP status + headers, spawn/exit metadata, JSON-RPC ack, WebSocket ack, queue receipt).\n- **RETURN** — the final result, verbatim, including failure payloads.\n- **RECEIPT** — evidence and provenance: receipt id/URL, trace id, execution id, timestamps, parent linkage.\n\n## Definition of proof (PROOF_LAW, governing invariant; read it: GET https://ops.miscsubjects.com/api/work → governing_invariants)\nA capability is proven only when the DECLARED invocation surface itself ran and the five fields exist for that run: CAUSE (why it ran: user request / task / parent invocation / event / webhook / model call), RAW INVOCATION (the fully resolved physical contract actually sent), RAW CONFIRMATION (the executor's acknowledgement), RAW RETURN (the actual output, failures verbatim), PROOF / RECEIPT (receipt id/URL, trace, execution id, timestamps, parent linkage sufficient to inspect or replay).\nAn HTTP 200 proves an HTTP 200. A webhook acknowledgement proves receipt. Hidden bash proves bash. A sibling implementation, documentation, a model doing it elsewhere, or the dispatcher working while the surface under test never ran prove nothing about that surface. A missing field is a missing implementation requirement, never something to invent. Existing failures stay as evidence and become regression fixtures; they are never rewritten into success.\n\n## Six-column projection (unchanged; not the source of truth)\n`TOOL NAME | ONTOLOGY | RAW INVOCATION | RAW CONFIRMATION | RAW RETURN | PROOF / RECEIPT` — the build workbook sheet `sh_nyab2cgy` (vault `CONTRACTS_WORKBOOK_SHEET`, 11,035 rows on 2026-09-23). No seventh column, no contract-type column, no prose in place of an executable invocation. Extra metadata belongs in the canonical capability / task / receipt objects.\n\n## Parallelism law\nOther tasks run at the same time in other sessions. Own only the files and objects named under OWNS; touch a shared file only as named under SHARED (additive, never a rewrite). If this task finds the global law insufficient, it files an amendment: `POST /api/work/task/<this id>/fail` naming failure_class `law_insufficient`, layer `WT-0470`, and the missing invariant — it never creates a second standard. Ask the build, never the owner: keys are in `~/.build-vault.env` (`grep '^NAME=' ~/.build-vault.env`; `CLOUDFLARE_API_TOKEN=$CF_API_TOKEN` is a shell reference, resolve `$NAME`). The owner key travels as header `x-terminal-key`. Deploy only with `node scripts/land.mjs \"<WT id> what changed\"` from `~/miscsubjects-pages`. Submit evidence: `POST https://ops.miscsubjects.com/api/work/task/<id>/submit {agent, evidence:{commit, verification, …}, changed:[…]}` with header `x-terminal-key`.\n\n## Shared canonical objects and files — never independently rewritten (additive edits only, named per task)\n- `functions/api/dispatch.js` (the one door; runHttp/runFn/tenant delegation) — owner WT-0471.\n- `functions/_lib/invocation_methods.js`, `functions/_lib/grammar.js`, `functions/_lib/projection_manifest.js`, `functions/api/tools/[[path]].js`, `functions/api/mcp.js`, `functions/_lib/mcp_inspect.js` — owner WT-0472 (spellings and model projections).\n- `functions/_lib/event_log.js`, `functions/_lib/wire_log.js`, `functions/_lib/lean_receipt.js`, `functions/_lib/invocation_record.js`, the `events` table and R2 `logs/` — owner WT-0485 (ledger).\n- `functions/_lib/admin_session.js` (tokens, capabilities, tenants), `functions/_lib/tenant_devices.js`, `functions/api/onboard/[[path]].js` — owner WT-0487 (authority) / WT-0488 (onboarding).\n- `functions/_lib/mac_bridge.js`, `bridge/server.js`, `bridge/device_auth.js`, `bridge/surface-run.py`, `bridge/surface-verbs.py`, `bridge/bridge-run.py`, `bridge/bridge-browser.mjs`, `public/device-kit/*` (synced copies) — owners WT-0474 / WT-0475 / WT-0478.\n- `functions/_lib/work_object.js`, `functions/api/work/[[path]].js`, the `laws` and `work_tasks` tables — owner WT-0470 (law rows) and the build (task engine).\n- `scripts/contracts-*.mjs`, `apps-script/Contracts.gs`, the `CONTRACTS_RUN` directory row, sheet `sh_nyab2cgy` — owner WT-0473.\n- `scripts/ship.mjs`, `scripts/land.mjs`, `scripts/write.mjs`, `scripts/check-*.mjs`, `.githooks/*` — governed; add a gate only by adding a new `scripts/check-<name>.mjs` and wiring it as the existing gates are wired.\n",
    "state": "open",
    "priority": 3,
    "revision": 1,
    "depends_on": [
      "WT-0470",
      "WT-0471"
    ],
    "permitted_capabilities": [
      "dispatch",
      "d1",
      "bridge",
      "sheets",
      "receipts"
    ],
    "acceptance_tests": [
      {
        "type": "evidence_present",
        "id": "commit",
        "field": "commit"
      },
      {
        "type": "evidence_present",
        "id": "live",
        "field": "verification"
      },
      {
        "type": "evidence_present",
        "id": "matrix",
        "field": "test_matrix_results"
      },
      {
        "type": "http_ok",
        "id": "sheets",
        "url": "https://ops.miscsubjects.com/api/sheets"
      }
    ],
    "required_evidence": [
      "commit",
      "test_matrix_results",
      "verification"
    ],
    "parent_task": null,
    "supersedes": null,
    "failure": null,
    "failure_count": 0,
    "last_result": null,
    "completed_at": null,
    "created_at": "2026-09-22T19:51:57-07:00",
    "updated_at": "2026-09-22T19:51:57-07:00",
    "audit": "/api/work/task/WT-0483/audit",
    "submit_to": "/api/work/task/WT-0483/submit"
  }
}