Skip to content

Commit 3c7631a

Browse files
ryansolidclaudecursoragent
authored
fix(signals,web): ABANDONED_FLIGHTS skips the frames slot-arg memo (#3852) (#3874)
Every re-shipped slot record re-runs the fill's per-key async-arg memo while the arg is still pending, superseding the flight in the air by design. Dev builds mark that memo with the internal `_supersedes` option (CONFIG_SUPERSEDES, following #3850's `_wide` / CONFIG_WIDE), and the attribution engine's ABANDONED_FLIGHTS check skips marked nodes. Flight records and feedback() counts are unchanged; prod and observe artifacts are byte-identical. Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent d1309ad commit 3c7631a

9 files changed

Lines changed: 223 additions & 7 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/signals": patch
3+
"@solidjs/web": patch
4+
---
5+
6+
ABANDONED_FLIGHTS no longer fires for a frames slot arg that every re-shipped record re-reads while it is still pending (#3852). Dev builds mark the per-key slot-arg memo with an internal option that the check skips; the memo's flights are still recorded and still counted in `feedback()`.

‎documentation/solid-2.0/08-dev-diagnostics.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ The finding fires at settle when the handler took no other road: no root write b
546546

547547
**Message:** "`"posts"` abandoned 3 flights in 1000ms (`keydown on input#search` started the first): each was superseded by the next before it landed, so every input asked again and the answers were discarded. Put a debounced or equality-gated derivation between the input and the fetch, or key the fetch on what changes rather than on every keystroke; a preload the flights share (`markFlight`) reads as one flight, not many."
548548

549-
The request-per-keystroke signature `feedback().flights[].abandoned` counts, as a finding while it happens. One async source abandoned `abandonedFlights.count` flights (default 3) within `windowMs` (default 1000ms) — each superseded by the node's next flight before it landed. `warn`, once per window per source; the window lives in the engine, not on the node. `data`: `source`, `abandoned`, `windowMs`, `interaction` (the one whose write started the flight that was abandoned, when known). Subject: the async node. `false` disables.
549+
The request-per-keystroke signature `feedback().flights[].abandoned` counts, as a finding while it happens. One async source abandoned `abandonedFlights.count` flights (default 3) within `windowMs` (default 1000ms) — each superseded by the node's next flight before it landed. `warn`, once per window per source; the window lives in the engine, not on the node. `data`: `source`, `abandoned`, `windowMs`, `interaction` (the one whose write started the flight that was abandoned, when known). Subject: the async node. In dev builds a framework node that supersedes its own flights by design (a `@solidjs/web/frames` slot arg, re-read by every re-shipped record while it is still pending) is not judged; its flights still appear in the records and in `feedback()`. `false` disables.
550550

551551
#### `FALLBACK_FLASH`
552552

‎packages/signals/src/core/attribution.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CONFIG_OVERRIDE,
1111
CONFIG_PLUMBING,
1212
CONFIG_WIDE,
13+
CONFIG_SUPERSEDES,
1314
CONFIG_VERDICT,
1415
NOT_PENDING
1516
} from "./constants.js";
@@ -546,7 +547,9 @@ export interface AttributionOptions {
546547
* abandons `count` flights within `windowMs` — each superseded by the
547548
* next before it landed (default 3 / 1000ms: the request-per-keystroke
548549
* signature, every input asking again and the answers discarded). Once
549-
* per window per source. `false` disables.
550+
* per window per source. In dev builds a framework node that supersedes
551+
* its own flights by design (a frames slot arg re-read by each re-shipped
552+
* record) is not judged. `false` disables.
550553
*/
551554
abandonedFlights?: { count: number; windowMs: number } | false;
552555
/**
@@ -3241,11 +3244,14 @@ const abandonWindows = new WeakMap<
32413244
* One source abandoning flight after flight inside a window: every input
32423245
* asked again and the earlier answers were thrown away — the
32433246
* request-per-keystroke signature `feedback().flights[].abandoned` counts,
3244-
* as a finding while it happens. Warned once per window per source.
3247+
* as a finding while it happens. Warned once per window per source. A
3248+
* framework node superseding its own flights by design (CONFIG_SUPERSEDES)
3249+
* is not judged; its flights are still recorded.
32453250
*/
32463251
function checkAbandonedFlights(el: Computed<any>, abandoned: LiveFlight): void {
32473252
const cfg = options.abandonedFlights;
3248-
if (cfg === false || excludedNode(el)) return;
3253+
// Only dev sets CONFIG_SUPERSEDES (see constants.ts).
3254+
if (cfg === false || (__DEV__ && el._config & CONFIG_SUPERSEDES) || excludedNode(el)) return;
32493255
const at = Date.now();
32503256
let win = abandonWindows.get(el);
32513257
if (win === undefined || at - win.start > cfg.windowMs) {

‎packages/signals/src/core/constants.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ export const CONFIG_PLUMBING = 1 << 25;
178178
* does not. Set from the internal `_wide` option at creation by dev builds only
179179
* (the observe artifact mangles the option name, as it does `_plumbing`). */
180180
export const CONFIG_WIDE = 1 << 26;
181+
/** Observe tiers only: a framework async node that supersedes its own flights
182+
* by design (`@solidjs/web/frames`' per-key slot-arg memo, re-run by every
183+
* re-shipped record while the arg is still pending) — the attribution
184+
* engine's ABANDONED_FLIGHTS skips it; its flight records and the feedback
185+
* fold's counts are unchanged. Set from the internal `_supersedes` option at
186+
* creation by dev builds only (the observe artifact mangles the option name,
187+
* as it does `_wide`). */
188+
export const CONFIG_SUPERSEDES = 1 << 27;
181189

182190
export const STATUS_NONE = 0;
183191
export const STATUS_PENDING = 1 << 0;

‎packages/signals/src/core/core.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
CONFIG_NO_SNAPSHOT,
2323
CONFIG_PLUMBING,
2424
CONFIG_WIDE,
25+
CONFIG_SUPERSEDES,
2526
CONFIG_SLOT_NODE,
2627
CONFIG_OWNED_WRITE,
2728
CONFIG_PROMOTED,
@@ -921,6 +922,8 @@ export function computed<T>(
921922
_x: null
922923
} as Computed<T>);
923924
if (options?.unobserved) (ext(self) as NodeExtension)._unobserved = options.unobserved;
925+
// Dev only, as `_wide` (see CONFIG_SUPERSEDES).
926+
if (__DEV__ && options?._supersedes) self._config |= CONFIG_SUPERSEDES;
924927
setupComputedNode(self, options);
925928
return self;
926929
}

‎packages/signals/src/core/types.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export interface NodeOptions<T> {
3939
* WIDE_SCOPE_DEPS, never from HUGE_FAN_IN (internal — not part of public
4040
* API; see CONFIG_WIDE). */
4141
_wide?: boolean;
42+
/** Observe tiers: a framework async node that supersedes its own flights by
43+
* design — exempt from ABANDONED_FLIGHTS (internal — not part of public
44+
* API; see CONFIG_SUPERSEDES). */
45+
_supersedes?: boolean;
4246
unobserved?: () => void;
4347
lazy?: boolean;
4448
sync?: boolean;

‎packages/signals/tests/attribution-feedback-findings.test.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ function arm(code: DiagnosticCode, opts: AttributionOptions = {}) {
6060
const CLICK = { type: "click", target: 'button#next "Next →"' };
6161

6262
/** A controllable async source; `read: false` leaves it to a boundary to read. */
63-
function pagedFeed(name = "posts", read = true) {
63+
function pagedFeed(name = "posts", read = true, supersedes = false) {
6464
const [page, setPage] = createSignal(1, { name: `${name}Page` });
6565
let resolve: ((v: string) => void) | null = null;
6666
const posts = createMemo(
6767
() => {
6868
const p = page();
6969
return new Promise<string>(r => (resolve = v => r(`${v}-p${p}`)));
7070
},
71-
{ name }
71+
{ name, _supersedes: supersedes } as any
7272
);
7373
const shown: string[] = [];
7474
if (read)
@@ -152,6 +152,27 @@ describe("ABANDONED_FLIGHTS", () => {
152152
other.resolve("z");
153153
await until(() => other.shown.includes("z-p5"), "other landing");
154154
});
155+
156+
it("a node superseding its own flights by design (_supersedes) is not judged; its flights are still recorded", async () => {
157+
const { findings } = arm("ABANDONED_FLIGHTS");
158+
const outcomes: string[] = [];
159+
const off = OBSERVE!.records.subscribe("flight", e => {
160+
if (e.nodeName === "slotArg") outcomes.push(e.outcome);
161+
});
162+
const feed = pagedFeed("slotArg", true, true);
163+
flush();
164+
feed.resolve("a");
165+
await until(() => feed.shown.includes("a-p1"), "initial load");
166+
for (const p of [2, 3, 4, 5]) {
167+
feed.setPage(p);
168+
flush();
169+
}
170+
expect(findings).toHaveLength(0);
171+
expect(outcomes).toEqual(["landed", "abandoned", "abandoned", "abandoned"]);
172+
feed.resolve("z");
173+
await until(() => feed.shown.includes("z-p5"), "the last flight to land");
174+
off();
175+
});
155176
});
156177

157178
describe("FALLBACK_FLASH", () => {

‎packages/web/frames/src/client.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ function slotArgsProxy(args: () => Record<string, any>) {
426426
// claim walk is synchronous: without the sync adopt the fill
427427
// renders its fallback branch over a page whose markup settled
428428
// before flush — branch mismatch, key misses, dead range.
429+
//
430+
// SUPERSEDES: every re-shipped record re-runs this memo while the
431+
// arg is still pending, abandoning the flight in the air — by
432+
// design, so dev marks it `_supersedes` (exempt from
433+
// ABANDONED_FLIGHTS). Dev only: signals' observe artifact mangles
434+
// `_` option names.
429435
const make = () =>
430436
createMemo(
431437
() => {
@@ -436,7 +442,7 @@ function slotArgsProxy(args: () => Record<string, any>) {
436442
}
437443
return raw;
438444
},
439-
{ transparent: true } as any
445+
(IS_DEV ? { transparent: true, _supersedes: true } : { transparent: true }) as any
440446
);
441447
read = owner ? runWithOwner(owner, make)! : make();
442448
asyncReads.set(key, read);
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #3852: a watched slot arg re-ships the occurrence's record on every server
6+
// commit, and each re-ship re-runs the fill's per-key async-arg memo — a new
7+
// flight superseding the one still in the air, by design. ABANDONED_FLIGHTS
8+
// does not judge that memo; a user memo churning flights inside the fill
9+
// still warns.
10+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
11+
import { createMemo, createRoot, flush, Loading, OBSERVE } from "solid-js";
12+
import type { DiagnosticEvent } from "solid-js";
13+
import { attribution } from "solid-js/attribution";
14+
import { dynamic } from "../src/index.js";
15+
import { installServerComponents, createFrameHost } from "../frames/src/client.js";
16+
import { createJSONDataTable, createJSONSerializer } from "../serialization/src/serializer.js";
17+
import { createServerReference } from "../server-functions/src/client.js";
18+
import { createChunk } from "../server-functions/src/shared.js";
19+
20+
const settle = () => new Promise(r => setTimeout(r));
21+
const getReply = createServerReference("reply/get");
22+
23+
function makeHost() {
24+
const table = createJSONDataTable();
25+
return createFrameHost({
26+
applyData: (c: any) => table.apply(c),
27+
resolve: (ref: any) => table.resolve(ref)
28+
});
29+
}
30+
31+
const disposers: Array<() => void> = [];
32+
beforeEach(() => installServerComponents(makeHost()));
33+
afterEach(() => {
34+
for (const d of disposers.splice(0)) d();
35+
attribution.disable();
36+
flush();
37+
vi.unstubAllGlobals();
38+
vi.restoreAllMocks();
39+
});
40+
41+
function capture() {
42+
vi.spyOn(console, "warn").mockImplementation(() => {});
43+
const events: DiagnosticEvent[] = [];
44+
disposers.push(
45+
OBSERVE!.diagnostics.subscribe(e => {
46+
if (e.code === "ABANDONED_FLIGHTS") events.push(e);
47+
})
48+
);
49+
attribution.enable({ log: false, hotRuns: false, hotTime: false, waterfalls: false });
50+
return events;
51+
}
52+
53+
/**
54+
* The chat reply's status slot: `progress` a scalar the server re-ships on
55+
* every commit, `stats` a promise still pending until generation ends.
56+
*/
57+
async function streamReply(fill: (p: any) => any) {
58+
let resolveStats!: (v: string) => void;
59+
const statsPromise = new Promise<string>(r => (resolveStats = r));
60+
const dataRecords: any[] = [];
61+
const ser = createJSONSerializer({ onData: (r: any) => dataRecords.push(r) });
62+
ser.write("arg:status#0:stats", statsPromise);
63+
const initialData = dataRecords.splice(0);
64+
65+
let controller!: ReadableStreamDefaultController;
66+
const body = new ReadableStream({ start: c => (controller = c) });
67+
const send = (chunk: any) => controller.enqueue(createChunk(JSON.stringify(chunk)));
68+
const record = (progress: string) => ({
69+
type: "slot",
70+
id: "srv",
71+
version: 1,
72+
key: "status#0",
73+
args: { progress, stats: { $ref: "arg:status#0:stats" } }
74+
});
75+
vi.stubGlobal("fetch", async () => {
76+
send({ type: "start", id: "srv", version: 1 });
77+
send(record("0 tokens"));
78+
for (const r of initialData) send({ type: "data", id: "srv", version: 1, ...r });
79+
send({
80+
type: "html",
81+
id: "srv",
82+
version: 1,
83+
html: "<article><!--slot:status#0:start--><!--slot:status#0:end--></article>"
84+
});
85+
return new Response(body, { headers: { "X-Frame-Stream": "srv" } });
86+
});
87+
88+
const Reply = dynamic(() => getReply("hi") as any);
89+
let div!: HTMLDivElement;
90+
disposers.push(
91+
createRoot(d => {
92+
<div ref={div}>
93+
<Loading fallback={<span>typing</span>}>
94+
<Reply status={fill} />
95+
</Loading>
96+
</div>;
97+
document.body.appendChild(div);
98+
return () => (d(), div.remove());
99+
})
100+
);
101+
const tick = async () => {
102+
flush();
103+
await settle();
104+
flush();
105+
await settle();
106+
};
107+
await tick();
108+
109+
for (const n of [1, 2, 3, 4, 5]) {
110+
send(record(`${n * 10} tokens`));
111+
await tick();
112+
}
113+
expect(div.querySelector(".progress")!.textContent).toBe("50 tokens");
114+
115+
resolveStats("done");
116+
await settle();
117+
for (const r of dataRecords.splice(0)) send({ type: "data", id: "srv", version: 1, ...r });
118+
send({ type: "complete", id: "srv", version: 1 });
119+
controller.close();
120+
await tick();
121+
expect(div.querySelector(".stats")!.textContent).toBe("done");
122+
}
123+
124+
describe("ABANDONED_FLIGHTS and re-shipped slot args (#3852)", () => {
125+
test("a pending arg re-read on every re-ship does not warn", async () => {
126+
const events = capture();
127+
await streamReply(p => (
128+
<p>
129+
<span class="progress">{p.progress}</span>
130+
<Loading fallback="…">
131+
<span class="stats">{p.stats}</span>
132+
</Loading>
133+
</p>
134+
));
135+
expect(events).toEqual([]);
136+
});
137+
138+
test("a user memo minting a fresh flight per re-ship still warns", async () => {
139+
const events = capture();
140+
await streamReply(p => {
141+
const ticker = createMemo(
142+
() => {
143+
const line = p.progress;
144+
return new Promise<string>(r => setTimeout(() => r(line), 1000));
145+
},
146+
{ name: "ticker" }
147+
);
148+
return (
149+
<p>
150+
<span class="progress">{p.progress}</span>
151+
<Loading fallback="…">
152+
<span class="ticker">{ticker()}</span>
153+
</Loading>
154+
<Loading fallback="…">
155+
<span class="stats">{p.stats}</span>
156+
</Loading>
157+
</p>
158+
);
159+
});
160+
expect(events.map(e => e.nodeName)).toEqual(["ticker"]);
161+
});
162+
});

0 commit comments

Comments
 (0)