Repository navigation
docs(sdk): patchy-server says what ctx.viewer is and how row ids reach tables - #1244
allisonmahmood wants to merge 1 commit into
Conversation
…w ids reach tables Co-Authored-By: Claude Opus 5.5 <[email protected]>
Acceptance: PASS with notesChecked Done means
Local handler evidence (scenario data; row identifiers omitted)The query's relevant code was: import type { Id } from "patchy/config";
import { query } from "../patchy/_generated/server.js";
import { t } from "patchy/server";
// args: { id: t.text() }; result describes the returned fields.
handler: async (ctx, args) => {
const row = await ctx.tables.requests.get(args.id as Id<"requests">);
return {
title: row?.title ?? null,
admin: ctx.viewer.admin,
name: ctx.viewer.user.name,
viewer: ctx.viewer
};
}The complete temporary handlers, including their result descriptors and an admin-only update, passed The full returned viewer objects also had Golden journeys
Rollback answers: match the diff. There is no schema, stored-data, infrastructure or API change. Regeneration returns the release's skill text, and code written from the new instructions already uses APIs present on the base. No Not run / notes
|
|
Superseded by #1249, which carries this change as its first commit, alongside the rest of the climb measured on top of it. Closing in favour of the one PR. Fermy (Claude Opus 5.5, Claude Code in T3 Code) |
… kept missing (#1249) ## What changed Agents building on Patchy kept tripping over the same few platform behaviours that nothing they read said plainly. The fixes are facts, one or two sentences each, in the two places builders read: the `AGENTS.md` that `patchy init` writes, and the project skills. - **A page's form never submits.** Every page runs in a sandboxed frame without `allow-forms`, so `<form onSubmit>` with a submit button sends nothing. This caused 27 of the 53 failing runs on main (51%), nearly all of them Terra's. - **A plain `Error` doesn't reach the page.** Anything a handler throws besides a declared `HandlerError`, or one of Patchy's own refusals, arrives as `handler_failed`, with its message lost. - **An agent knows a tool's arguments only from its description and schema.** `t.enum` lists the accepted values in the schema; `t.text()` names none. - **The look can colour every `button`'s text, as the Patchy look does.** A button restyled with a light background then keeps the look's cream text and disappears. - **What `ctx.viewer` is, and how a row id reaches `ctx.tables.<t>.get`.** This was the most common reason builders left the skills to read Patchy's type declarations. - **`get` refuses an empty id.** A last round of edits, written by Claude Fable 5.2 from the judges' findings on this branch, is the last four commits, the last of them fixing a review of the round: - **List order and paging.** A list on a declared index comes back ascending by the index's columns, so oldest first when `eq` fixes them all, unless it passes `order: "desc"`; and rows past `limit` come only through the cursor. The tables example passes both, and patchy-server gains a paged handler example. - **What a refusal looks like on the page.** A `HandlerError`'s `message` is its code. The generated client exports `isHandlerError` and `isPatchyError`, and patchy-preact shows a page telling them apart and keeping `retry()` for a lost reply. - **`useQuery` can't be skipped**, so a query that can't run yet belongs in a component rendered once it can. - **`useFileUrl` downloads the whole file as soon as it mounts**, and each download counts against the viewer's 300 calls a minute. - **An action's table writes commit one at a time**, and a write that fails with `unknown_outcome` may have committed. - **Every `server/` export is callable from the page.** `ctx.agent` is null where no tool arrives, and a re-export can rename a tool with `as`. - **The look's heading colour and paragraph width hold** the way its button colour does. - **The members skill exists only after `pnpm patchy add members`.** - It also cuts paragraphs repeated word for word in another skill, corrects the per-patch live-query re-run limit (2, not 1), and gives the agent section's error sentence the same exception for Patchy's own refusals. Part of #1141. Supersedes #1244, whose change is the first commit here. ## Look at  | ×6, 120 verdicts a side | Fit | Platform | Correctness | UX | Code | Mean | Checks pass | | --- | --- | --- | --- | --- | --- | --- | --- | | main (`8a3b347`) | 4.02 | 3.89 | 3.75 | 4.11 | 3.96 | 3.95 | 50/60 (83%) | | this branch | **4.20** | **4.03** | 3.90 | **4.06** | 3.94 | **4.03** | **54/60 (90%)** | The goal was 4.0 or more on every judge dimension. Fit, platform and UX meet it; **correctness (3.90) and code (3.94) don't yet**. UX and code are level with main in this run, within noise, though round K moved both. The rest of the correctness gap is design choices: paging, which agent tools exist, copying a handler instead of re-exporting it, receipt cleanup. Five rounds of facts didn't move those (see below). - **Native-form pages** went from 4 to 0, and "the page sent Patchy nothing" failures from 6 to 0. - **Off-skill lookups** fell on the hard tasks: war-room/terra 4.0 → 0.3, spend-approvals/terra 3.7 → 0.0, spend-approvals/sonnet 5.7 → 2.8 per run. - **Per task**, spend-approvals/terra went from 3/6 to 6/6. One drop: spend-approvals/sonnet went 5/6 → 4/6. One head build subscribed every viewer to an admin-only query, and logged `not_admin` refusals. In another, Ben's request wasn't on Ada's starting view. **Held-out tasks** (#1242 `recipe-book`, #1243 `standup`, ×3, never used to choose a change): checks pass 9/12 → **12/12**; judges 3.68 → **4.04**, correctness 3.04 → 3.75. **On today's main, with the last round.** Measured after rebasing onto `7f93b91`: | ×3, 60 verdicts a side | Fit | Platform | Correctness | UX | Code | Mean | Checks pass | | --- | --- | --- | --- | --- | --- | --- | --- | | main (`7f93b91`) | 3.85 | 3.88 | 3.65 | 4.08 | 3.97 | 3.89 | 17/30 | | the first five commits (two suites, 120 verdicts) | **4.10** | 3.98 | 3.79 | **4.18** | 3.98 | **4.01** | 16/30, 18/30 | | with the last round | **4.05** | **4.10** | 3.90 | **4.13** | **4.00** | **4.04** | 18/30 | - **The first five commits** still score higher than main on every dimension. - **The last round** against the first five is within ×3 noise on scores (+0.06 mean), but what it aimed at moved. The judges' high and medium findings about paging and truncation fell from 38 to 17, lists returning the wrong end from 12 to 6, and retry handling from 18 to 12. All high and medium findings fell from 170 to 154. - **Pass rates are low on every side because the eval is broken on main.** Since #1204, the `team` scenario's Cleo hasn't accepted the terms, so when the grader opens a patch as her it gets the terms prompt and the patch never loads. Every cheers and spend-approvals build fails there. That hits both sides equally, so the comparison holds, but these pass rates can't be compared with the ×6 above. **Where the facts go matters more than what they say.** Terra (Codex) loads `AGENTS.md` into its instructions and reads the skills as long tool output. Each fact in this table was first tried in a skill alone, and none changed what Terra built there. In `AGENTS.md`, each did: | Fact | In the skill only | In `AGENTS.md` | | --- | --- | --- | | Forms never submit | native-form pages 1 → 4 of 12, dropped (H1) | native-form pages 2 → 0; pass 77% → 93% (round A) | | A plain `Error` is `handler_failed` | plain throws 2 → 1, judges flat, dropped (G) | plain throws 1 → 0; pass 80% → 90% (H) | | `t.enum` is in the tool's schema | judges 3.86 → 3.81, dropped (C) | every dimension up, mean 3.91 → 4.01 (I) | | A restyled button keeps the look's text colour | too rare in its suite to read, dropped (F) | transparent-button rules 9 → 3 of 30; UX 3.92 → 4.15, code 3.85 → 3.98 (K) | `AGENTS.md` is written once, at `patchy init`; `refresh` never touches it. So each fact also goes into its skill, as it was measured there, so builders in existing repos get it too. Those skill versions measured neutral on their own, not harmful. After review, three sentences were tightened without changing what they tell a builder. A business refusal is a declared `HandlerError`, and Patchy's own refusals keep their codes. A tool's description counts as well as its schema. The button rule holds when the look sets a button text colour. **War room, Terra, one build each side (round K):** before, the Resolved and All filter tabs are cream text on cream and only Open shows; after, all three read. | Before | After | | --- | --- | |  |  | <details><summary>Every round, kept and dropped</summary> Each round is an A/B suite: base and head both build all five training tasks ×3, both builders (Claude Code on Sonnet 5.5, Codex on Terra 6.1), both judges (Opus 5.5, Sol 6.1): 30 runs and 60 verdicts a side (H2, run twice: 60 and 120). Rounds after A are measured against #1244 + A. | Round | Change, and where | Judges, mean | Pass | Target signal | Result | | --- | --- | --- | --- | --- | --- | | H1 | Retitle patchy-loop's "Tier 1 constraints" to cover every page (forms) | 3.93 → 3.80 | 80% → 77% | native-form pages 1 → 4 of 12 | dropped | | H2 | patchy-server: `ctx.viewer`'s shape; row ids reach tables as `Id<"table">` (×6) | 3.85 → 3.83 | 83% → 78% | off-skill lookups on the hard tasks 5.2 → 2.1 per run; held-out `standup` too | **kept** (was #1244) | | H3 | patchy-server: a `HandlerError`'s message is its code; the `errors` list | 3.92 → 3.91 | 80% → 83% | bare-code findings 16 → 15 | dropped | | A | `AGENTS.md` and patchy-preact: forms never submit in the frame; patchy-tables: `get` refuses an empty id | 3.82 → **4.03** | 77% → **93%** | native-form pages 2 → 0; "sent nothing" 3 → 0 | **kept** | | B | patchy-server: a `t.member()` column holds `user.id`, a copied name goes stale; patchy-tables: filtering a fetched page misses later pages | 3.86 → 3.80 | 83% → 73% | builds using a member column 5 → 5 of 12; truncation findings 65 → 67 | dropped | | C | patchy-server: an action with no tool is closed to agents; `t.enum` is in the tool's schema | 3.86 → 3.81 | 73% → 73% | agent-coverage findings 17 → 18 | dropped | | D | patchy-look: recipe classes need their CSS, the Patchy look's example company is made up; files: `put` by a caller's name, `useFileUrl` fetches on mount | 3.93 → 3.91 | 90% → 83% | look findings 13 → 10, files 22 → 15; dimensions flat | dropped | | F | patchy-tables: a declared index lists ascending; patchy-look: a restyled button keeps the look's text colour | 3.97 → 4.01 | 90% → 90% | invisible-text findings 1 → 1, order findings 5 → 7 | dropped | | G | patchy-server: a plain `Error` reaches the page as `handler_failed` | 4.06 → 4.05 | 90% → 87% | plain throws 2 → 1 | dropped (moved to H) | | H | `AGENTS.md`: G's fact | 3.95 → 3.95 | 80% → **90%** | plain throws 1 → 0; `handler_failed` failures 1 → 0 | **kept** | | I | `AGENTS.md`: C's `t.enum` fact | 3.91 → **4.01** | 83% → 80% | every dimension up; agent-check failures 1 → 0 | **kept** (part of the lift is likely noise: it spans tasks without agent tools) | | J | `AGENTS.md`: a `list` returns one page and a cursor | 3.99 → 3.96 | 83% → 83% | truncation findings 17 → 19 | dropped | | K | `AGENTS.md`: F's button fact | 3.92 → **4.03** | 90% → 77% | transparent-button rules 9 → 3 of 30; UX 3.92 → 4.15 | **kept**, an exception: its pass dip was 4 plain-`Error` refusals and 1 free-text agent argument, H's and I's targets, which K's branch lacked | Judges are the mean of the five dimensions over both judges; each round is 30 runs and 60 verdicts a side (H2: 60 runs and 120 verdicts). </details> ## What didn't work, and why - **Restating a rule where Terra already reads it.** Terra `cat`s whole skill files on both sides of every A/B, so a heading never gated whether it saw the form rule (H1). It saw it, and wrote a native form about half the time anyway. The same fact in `AGENTS.md` worked. - **Facts about design choices.** Telling builders that a `t.member()` column holds a stable id (B), that leaving out an agent tool closes it to agents (C), that filtering a fetched page misses later pages (B, and J in `AGENTS.md`), or that a declared index lists oldest first (F) left the designs unchanged. Truncation findings stayed at 65 → 67 and 17 → 19. Only facts about behaviour the builder didn't know changed what it built. The exception came in the last round: it restated paging as what `list` does, with an example passing `order` and the cursor, and the paging findings halved (38 → 17). - **Saying what a refusal looks like on the page (H3).** True, and builders still showed the bare code. - **The look's example company.** I wrote that the Patchy look's example markup names a made-up company, Acme Co, after judges flagged pages that read "Acme Co". The `team` scenario's company *is* Acme Co, so those pages were right and the judges wrong. Dropped (D). The last round says only that the sample's names are placeholders and the company's name is `company.name`. - **Codex truncating long output.** Terra prints several skills in one command, so I checked whether the form rule fell in an elided middle. Runs where the rule landed in the visible head or tail used native forms as often (3/5) as those where it was cut (21/49), so that isn't why. ## How it was verified - **Final:** this branch's head against main (`8a3b347`), ×6 (two ×3 suites on the same commits), all five training tasks, both builders, both judges. - **Held-out:** both held-out tasks, #1242 `recipe-book` and #1243 `standup`, merged locally onto main, with this branch on top. They were never used to choose a change. Result, ×3, 24 verdicts a side: pass 9/12 (75%) → **12/12 (100%)**; judges 3.68 → **4.04** (fit 3.79 → 4.17, platform 3.96 → 4.25, correctness 3.04 → 3.75, UX 3.92 → 4.13, code 3.71 → 3.88); native-form pages 3 → 0. - **Facts checked against the code:** - forms: `packages/serving/src/shell.ts`, the frame's `sandbox="allow-scripts allow-modals"` - refusals: `packages/runtime/src/Invocation.ts`, `HandlerFailed`'s fixed message - enums in tool schemas: `packages/api/src/agentTools.ts` - buttons: `packages/companies/looks/patchy/look.css`, the `button` rule - empty ids: `packages/api/src/runtime.ts`, `tables.get` takes `NonEmptyText` - viewer shape: `ContextBase.viewer: Me` in `packages/patchy/src/server.ts` - **The last round:** its head (`c8af5ed`, before the last commit's two wording fixes and a clean rebase) against the first five commits, ×3; and the first five against main in a separate ×3 suite, both on `7f93b91`. Each claim in it was checked against the code: `TableOperations.ts` for list order, `handlerError.ts`, `generateClient.ts` and `generateServer.ts` for refusals and imports, `useQuery.ts`, the admission in `Runtime.ts` for file downloads, `registry.ts` for limits, `handlerDescriptors.ts` for re-exports, `Generation.ts` for the members skill, and `look.css`. - **Review of the last round:** GPT-6.1 Sol at xhigh, in Codex. Its five findings are fixed in the last commit: a declared index sorts by its columns, not by age; the page's error example left the `missing` code to show as text; only handler runs leave log entries; a call never sent fails with `unknown_outcome` and no `retry()`; and patchy-server repeated patchy-preact on `useQuery`. - **Raw runs stay on the eval machine.** - On this head, format, the SDK's skill tests (34, in `install`, `FrontDoor` and `SdkApi`) and `initProject.test.ts` (15) pass. Before the last round, `env -u NODE_ENV pnpm check`: format, lint, typecheck and synth pass; 2,828 of 2,830 tests pass. The two that timed out at 30 s (`cliRepoPublish`, `devServerWatch`) did so while four eval suites shared the machine; rerun alone with `initProject.test.ts`, all 38 pass. **Noise, so the numbers read right.** The same main commit read between 3.89 and 3.99 mean across suites, and one run is 3.3 points of a ×3 pass rate. Rounds were kept when their target moved and their pass rate held; K is the stated exception. The headline numbers pool two ×3 suites run on the same two commits. **Found on the way, outside this PR:** - **The eval since #1204.** The grader can't open a patch as the `team` scenario's Cleo, who hasn't accepted the terms, so two of the five tasks can't pass. A fix: the eval accepts the current terms for every person it signs in as. - **A live-query race.** A shell `replace` that arrives after a later `subscribe` is refused with 409, and the grader fails any check whose page logged an error. That can fail a correct build. - **Eval disk use.** The harness keeps a ~2 GB builder home per run. A trimmer on the eval machine covered it here. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required: skill text, and the `AGENTS.md` text new repos get. - **What does a revert leave behind?** Repos initialised in between keep the new `AGENTS.md` sentences, which stay true; skills regenerate from the release. - **Does the release before it still work with that?** Yes. Claude Opus 5.5 in Claude Code, through T3 Code; the last round's skill edits by Claude Fable 5.2. --------- Co-authored-by: Allison Mahmood <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
What changed
Agents building tier 2 patches kept leaving the skills to read
node_modules/patchy/dist/*.d.ts, because patchy-server never says whatctx.vieweris or how a row id from a handler's arguments reachesctx.tables.<t>.get. It now says both:ctx.vieweris the sameMea page'sme()returns (with its shape), and a row id argument ist.text()while table methods takeId<"table">frompatchy/config, cast as the repo's own reference patches already do.Part of #1141.
Look at
The eval suite (
pnpm dev eval --base 8a3b347 --repeats 3, run twice on the same commits and pooled to ×6; both builders, all five tasks, judged, 240/240 verdicts):node_modules/patchyoutside its skills, or of.d.tsfiles), spend-approvals + war-roomThe pool drops by exactly 5.0 points, the edge of the climb's keep rule. The first ×3 read −13 and the second +3, so most of the swing is one source of noise. Per task, the drops are these. The failures inspected show no error in either newly documented fact, though a run can't rule out an indirect effect of changed instructions:
<form onSubmit>pages, which the patch frame blocks: 6/12 runs on each side. Two head spend runs refused non-admins withthrow new Error, which Patchy reports ashandler_failed; both used the newargs.id as Id<"requests">correctly.replaceracing asubscribe.War-room/sonnet's remaining lookups are for the member directory (
Members/Member),ReadOnlyActionContextandfileHandle, which this change doesn't cover. Minutes and tokens moved both ways across the two runs and aren't evidence either way.Held-out tasks (#1242
recipe-book, #1243standup, run against this change before opening it):standup(tier 2) / sonnetstandup/ terrarecipe-book(tier 1, no handlers) / sonnet, terrarecipe-booksonnet, terra ·standupsonnet, terraThe one failure on each side is Terra's native form (
recipe-bookon base,standupon head), which is also the only judged move. The held-out tasks were run from their open PRs merged locally onto main, with this change on top; they were never used to choose it.How it was verified
ContextBase.viewer: Meinpackages/patchy/src/server.ts,Meinpackages/patchy/src/clientTransport.ts,Id<Table>inpackages/patchy/src/config.ts, andimport type { Id } from "patchy/config"withargs.id as Id<…>inscenarios/brightline/patches/spend/server/requests.tsandscenarios/kit-room/patches/kit-loans/server/loans.ts.Release impact
Breaking — requires action from anyone already running this
Not breaking — no action required: skill text served to project repos by generation.
What does a revert leave behind? Nothing; project skills are regenerated from the release.
Does the release before it still work with that? Yes.
Claude Opus 5.5 in Claude Code, through T3 Code.