Skip to content

Commit 4bc489e

Browse files
committed
🐛 Wait for the reply to be published, not for it to be drawn
The Node shard saw the preview-to-reply journey read a published chat with no response in it, having just watched the screen say the Sidekick's words. Both are true at once, and the test was reading the second after waiting for the first. Caught locally — once in twenty single-test runs, then again with the state printed — the file at that moment ends in the control the evaluation had just taken: owner, ready, conversation, …, control, control-outcome, control. No response, no feedback. The screen beside it says "[S] Half a thought." and "[U] think · evaluating the reply" and "[S] working", with Entry 1 already complete. That is the product doing what it says: the words are shown as soon as the Sidekick has said them, and the reply carrying an entry is published once that entry has been evaluated. The two moments are not the same moment. So the row waits for the fact it goes on to read. `awaitedFact` is `awaited` for something only an operation can see — the file, here — with the same deadline and the same loud failure. Nothing is relaxed: one response, one reply row, no preview row and no "(preview)" on the screen are all still required, and the screen must still have shown the reply before any of it is read. Forty single-test runs after this, none failed. The whole file passes under Node, Deno and Bun, and no production file moves.
1 parent 8aedd19 commit 4bc489e

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎packages/cli/tests/fixtures/repl/issue-883/mounted-program.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,28 @@ export function* awaited(what: string, settled_: () => boolean): Operation<void>
10491049
throw new Error(`${what} never happened within ${MOUNTED_DEADLINE_MS}ms`);
10501050
}
10511051

1052+
/**
1053+
* The same wait again, for a fact only an operation can read.
1054+
*
1055+
* What is on disk is the case in point. A row drawn on the screen and a record
1056+
* published in the history are two different moments: the Sidekick's words are
1057+
* shown as soon as it has said them, and the reply they belong to is saved
1058+
* after the entry it carries has been evaluated. A row that waited for the
1059+
* screen and then read the file would be asking about the second moment having
1060+
* waited for the first.
1061+
*/
1062+
export function* awaitedFact(what: string, held: () => Operation<boolean>): Operation<void> {
1063+
const deadline = Date.now() + MOUNTED_DEADLINE_MS;
1064+
while (Date.now() < deadline) {
1065+
if (yield* held()) {
1066+
return;
1067+
}
1068+
yield* sleep(10);
1069+
yield* settled(20);
1070+
}
1071+
throw new Error(`${what} never happened within ${MOUNTED_DEADLINE_MS}ms`);
1072+
}
1073+
10521074
/** Where this text is on the screen, if it is anywhere. */
10531075
export function coordinateOf(
10541076
terminal: Terminal,

‎packages/cli/tests/repl-sidekick-journey.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
} from "./fixtures/repl/issue-932/history.ts";
6060
import {
6161
appendGate,
62+
awaitedFact,
6263
awaiting,
6364
awaited,
6465
draftText,
@@ -1388,6 +1389,15 @@ describe("Tier PV — a response in flight, shown as it arrives", () => {
13881389
yield* awaiting(repl.terminal, "the evaluated reply", (one) =>
13891390
saidBySidekick(one, "Half a thought."),
13901391
);
1392+
// The screen says the Sidekick's words as soon as it has said them, and
1393+
// this reply carries an entry: the response is published once that entry
1394+
// has been evaluated, which is after the row is drawn. Caught on a loaded
1395+
// runner as a published chat whose last record was still the control the
1396+
// evaluation had just taken. So the fact this row goes on to read is the
1397+
// one it waits for.
1398+
yield* awaitedFact("the reply reaching the published chat", function* () {
1399+
return (yield* mountedReading(repl)).chat.some((record) => record.kind === "response");
1400+
});
13911401
const after = (yield* mountedReading(repl)).chat;
13921402
const answered = after.flatMap((record) =>
13931403
record.kind === "response"

0 commit comments

Comments
 (0)