Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions INTERFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,7 @@ far as "words go in and events come back" and no further.)*

The composer makes the browser the **originator** of agent mutations for the
first time. Nothing today refreshes the read caches when the agent writes:
`queries.ts` defines `keys.{project,parts,build,script,properties,checks,dfm,
`queries.ts` defines `keys.{project,parts,build,script,params,properties,checks,dfm,
gitStatus,gitLog,gitTags}` and a 5s project staleness, and no mutation path
invalidates any of them. The blank-canvas flow would therefore end with a
transcript full of successful tool calls and a rail that still says the project
Expand All @@ -2759,8 +2759,11 @@ has no parts.
this project — and on the prompt response, which §7A.6 already makes the
authority for turn completion — the client invalidates
`keys.project`, `keys.parts`, `keys.build(part)`, `keys.script(part)`,
`keys.properties(part)`, `keys.checks(part)`, `keys.dfm(part)` and
`keys.gitStatus()`.
`keys.params(part)`, `keys.properties(part)`, `keys.checks(part)`,
`keys.dfm(part)` and `keys.gitStatus()`. A slider commit that rebuilds the part
invalidates the same set (§10): Results / Checks / DFM / properties are
projections of that build, and an invalidation of only `params` + `build`
leaves those panels stale.

**TIGHTENING (binds §1).** The invalidation is a **refetch of the server
projection**, never a client-side merge of tool results. A composer that patched
Expand Down
26 changes: 22 additions & 4 deletions web/src/api/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ import { keys } from "./queries";
* The keys §7A.11 enumerates, resolved for one part.
*
* Exported as data so the test asserts the **list** rather than the effect of
* calling it: §7A.11 names eight keys, and a key quietly dropped from an
* calling it: §7A.11 names these keys, and a key quietly dropped from an
* invalidation is a panel that quietly goes stale.
*
* `part === null` is the blank canvas — no part is selected, so the
* part-scoped keys have no argument to resolve against. The three
* project-scoped keys still fire, and they are the ones that matter in exactly
* that case: `keys.parts()` is how a part the agent has just created appears in
* the tree. `keys.params` is the ninth key: §10's sliders read a projection
* §7A.11 did not name because the panel had not shipped.
* the tree.
*/
export function refreshKeys(part: string | null): readonly (readonly unknown[])[] {
const projectScoped: readonly (readonly unknown[])[] = [
Expand Down Expand Up @@ -79,11 +78,30 @@ export function refreshKeys(part: string | null): readonly (readonly unknown[])[
* this function computed.
*
* Deliberately fire-and-forget: the caller has already rendered the turn, and a
* composer that waited for eight refetches before re-enabling its textarea would
* composer that waited for the refetches before re-enabling its textarea would
* make the agent's own latency the operator's.
*/
export function refreshAfterTurn(client: QueryClient, part: string | null): void {
for (const queryKey of refreshKeys(part)) {
void client.invalidateQueries({ queryKey });
}
}

/**
* After a PARAMS slider write (§10).
*
* A rebuild dirties the same projections an agent turn does — Results, Checks,
* DFM, properties, the script snapshot, the tree. Conflict is params-only:
* nothing persisted and nothing rebuilt, so the other panels are still right.
*/
export function refreshAfterParamWrite(
client: QueryClient,
part: string,
outcome: "rebuilt" | "conflict",
): void {
if (outcome === "conflict") {
void client.invalidateQueries({ queryKey: keys.params(part) });
return;
}
refreshAfterTurn(client, part);
}
8 changes: 4 additions & 4 deletions web/src/components/stage/ParamSliders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import { useEffect, useRef, useState } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { postBuild, postParams } from "../../api/params";
import { keys, useParams } from "../../api/queries";
import { useParams } from "../../api/queries";
import { refreshAfterParamWrite } from "../../api/refresh";
import { uuid7 } from "../../api/idempotency";
import type { ParamRejection, ParamRow, ParamsDocument } from "../../api/types";
import { copy } from "../../copy";
Expand Down Expand Up @@ -176,7 +177,7 @@ export function ParamSliders(): React.JSX.Element {
rejected: [],
conflict: true,
}));
void client.invalidateQueries({ queryKey: keys.params(part) });
refreshAfterParamWrite(client, part, "conflict");
return;
}
if (result.rejected.length > 0) {
Expand All @@ -189,8 +190,7 @@ export function ParamSliders(): React.JSX.Element {
return;
}
return postBuild(part, uuid7()).then(() => {
void client.invalidateQueries({ queryKey: keys.params(part) });
void client.invalidateQueries({ queryKey: keys.build(part) });
refreshAfterParamWrite(client, part, "rebuilt");
});
})
.finally(() => {
Expand Down
35 changes: 35 additions & 0 deletions web/test/params.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { describe, expect, it } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import type { ReactElement } from "react";

import type { QueryClient } from "@tanstack/react-query";
import paramsJson from "./fixtures/params.json";
import type { ParamRejection, ParamsDocument } from "../src/api/types";
import { keys } from "../src/api/queries";
import { refreshAfterParamWrite, refreshKeys } from "../src/api/refresh";
import {
controlStep,
isIntegerParam,
Expand Down Expand Up @@ -95,6 +98,38 @@ describe("G5.3 — rejected[] is verbatim, and the primitive does not clamp", ()
expect(message?.textContent).toContain("10");
});

it("a successful commit invalidates the refreshKeys set, not just params+build", () => {
const invalidated: unknown[] = [];
const client = {
invalidateQueries: ({ queryKey }: { queryKey: readonly unknown[] }) => {
invalidated.push(queryKey);
},
} as Pick<QueryClient, "invalidateQueries"> as QueryClient;
refreshAfterParamWrite(client, "tread", "rebuilt");
expect(invalidated).toEqual(refreshKeys("tread"));
expect(invalidated).toEqual(
expect.arrayContaining([
keys.params("tread"),
keys.build("tread"),
keys.properties("tread"),
keys.checks("tread"),
keys.dfm("tread"),
]),
);
expect(invalidated).not.toEqual([keys.params("tread"), keys.build("tread")]);
});

it("a conflict re-reads params only — nothing rebuilt", () => {
const invalidated: unknown[] = [];
const client = {
invalidateQueries: ({ queryKey }: { queryKey: readonly unknown[] }) => {
invalidated.push(queryKey);
},
} as Pick<QueryClient, "invalidateQueries"> as QueryClient;
refreshAfterParamWrite(client, "tread", "conflict");
expect(invalidated).toEqual([keys.params("tread")]);
});

it("the number input has no min/max when clamp is off, so a typed 11 can leave", () => {
const host = render(
<Slider label="groove_count" min={2} max={10} step={1} value={11} clamp={false} onChange={() => undefined} />,
Expand Down
2 changes: 1 addition & 1 deletion web/test/stream/composer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe("the chip row", () => {
// §7A.11 — the read-refresh boundary

describe("the read-refresh boundary", () => {
it("names the §7A.11 keys plus the PARAMS projection for a selected part", () => {
it("names the §7A.11 keys for a selected part", () => {
expect(refreshKeys("tread")).toEqual([
keys.project(),
keys.parts(),
Expand Down
Loading