Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src-tauri/src/frame_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ pub(crate) fn run_frame_loop(
you: false,
at: None,
error: None,
superseded: false,
},
);
continue;
Expand All @@ -749,6 +750,7 @@ pub(crate) fn run_frame_loop(
you: false,
at: None,
error: None,
superseded: false,
},
);
continue;
Expand All @@ -771,6 +773,7 @@ pub(crate) fn run_frame_loop(
you: false,
at: None,
error: None,
superseded: false,
},
);
continue;
Expand Down Expand Up @@ -1329,6 +1332,7 @@ pub(crate) fn run_frame_loop(
you: false,
at: None,
error,
superseded: false,
},
);
}
Expand Down Expand Up @@ -1434,8 +1438,9 @@ pub(crate) fn run_frame_loop(
// Starting a call cancels the one before it
// (ADR-0016) and `Slots::take` drops the superseded
// reply, so a typed line on the wire is told here
// that no answer is coming. Nothing else would, and
// a row left unanswered would take the next turn's
// that its caret is cancelled, not that nothing
// came back (#681). Nothing else would, and a row
// left unanswered would take the next turn's
// answer, blinking for the life of the window.
if live.chat_turn {
let _ = app.emit_to(
Expand All @@ -1448,6 +1453,7 @@ pub(crate) fn run_frame_loop(
you: false,
at: None,
error: None,
superseded: true,
},
);
}
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,10 @@ struct ChatReply {
/// it named a version this CLI will not serve (#514). Not replayed: the
/// session log keeps the line said, and there was none.
error: Option<String>,
/// The Shell cancelled this caret because a newer wake started (ADR-0016).
/// `said` is `None`; this is not a turn that produced no Speech (#681).
#[serde(default)]
superseded: bool,
}

/// The Spatial Layer state one Chat surface draws in its status bar (ADR-0010).
Expand Down Expand Up @@ -1507,6 +1511,7 @@ fn chat_ready(
reacting_to: turn.reacting_to,
you: turn.you,
error: None,
superseded: false,
at: Some(
turn.at
.duration_since(UNIX_EPOCH)
Expand Down
59 changes: 59 additions & 0 deletions src/chat-settle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// What a `chat` payload does to a waiting caret. Its own module because
// chat.js reaches window.__TAURI__ as it loads and cannot be imported outside
// a webview; this can, so it has a test. #681.

export const MISSING_ANSWER = "No answer came back.";

export function createChatTurns() {
const waiting = [];

return {
typed() {
const turn = { alreadyHasSpeechAhead: false };
waiting.push(turn);
return turn;
},

drop(turn) {
const at = waiting.indexOf(turn);
if (at >= 0) {
waiting.splice(at, 1);
}
},

popNewest() {
return waiting.pop();
},

clear() {
waiting.length = 0;
},

settle(payload) {
const turn = waiting.shift();
if (!turn) {
return { action: "orphan", turn: null, said: payload.said ?? "" };
}
if (payload.said) {
for (const leftover of waiting) {
leftover.alreadyHasSpeechAhead = true;
}
return { action: "speech", turn, said: payload.said };
}
if (payload.error) {
return {
action: "error",
turn,
note: `The Harness reported an error: ${payload.error}`,
};
}
// #681: empty is not "no answer" when a leftover caret sits behind
// Speech already in the log, or when the Shell named the settle as
// superseded rather than silent-failure.
if (turn.alreadyHasSpeechAhead || payload.superseded) {
return { action: "silent", turn };
}
return { action: "missing", turn, note: MISSING_ANSWER };
},
};
}
36 changes: 19 additions & 17 deletions src/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ADR-0025 says why it is a strip above the composer instead.

import { composerPlaceholder } from "./chat-placeholder.js";
import { MISSING_ANSWER, createChatTurns } from "./chat-settle.js";
import { createStrip } from "./chat-strip.js";
import { stampWhen } from "./chat-stamp.js";
import { mindLine, plainStatus, statusCells } from "./chat-status.js";
Expand Down Expand Up @@ -78,7 +79,7 @@ function paint() {
// Turns waiting on an answer, oldest first. The Shell answers them in the
// order it took them and refuses a line typed while one is still waiting, so
// the oldest row takes the next answer and the newest takes a refusal.
const waiting = [];
const turns = createChatTurns();

function el(cls, tag) {
const node = document.createElement(tag || "div");
Expand Down Expand Up @@ -466,8 +467,9 @@ composer.addEventListener("submit", (event) => {
line.value = "";
// The last turn's mark has been read; this is the next question.
strip.asked();
const turn = { you: said("You", text, "you"), them: opening_answer() };
waiting.push(turn);
const turn = turns.typed();
turn.you = said("You", text, "you");
turn.them = opening_answer();
return invoke("chat_send", { instance, text }).catch((why) => {
drop(turn);
throw why;
Expand All @@ -482,10 +484,7 @@ composer.addEventListener("submit", (event) => {
// A line that will never be answered takes its rows with it, rather than
// leaving the user looking at a question in the log that nothing is working on.
function drop(turn) {
const at = waiting.indexOf(turn);
if (at >= 0) {
waiting.splice(at, 1);
}
turns.drop(turn);
turn.you.remove();
turn.them.remove();
}
Expand All @@ -508,7 +507,7 @@ function newSession(why) {
// out with the rows leaves that lookup dereferencing null.
log.replaceChildren(empty);
strip.asked();
waiting.length = 0;
turns.clear();
asks.clear();
// A boundary is where a stamp should say the hour again rather than count
// minutes from a line that is no longer on screen.
Expand All @@ -531,7 +530,7 @@ async function start() {
}
// #610: The strip is for thinking only (ADR-0025).
if (payload.busy) {
const refused = waiting.pop();
const refused = turns.popNewest();
if (refused) {
drop(refused);
}
Expand All @@ -552,31 +551,34 @@ async function start() {
said(`${them} · ${payload.reacting_to}`, payload.said, "them", payload.at);
return;
}
const turn = waiting.shift();
if (!turn) {
const outcome = turns.settle(payload);
if (outcome.action === "orphan") {
// An answer with no question in this window: the Instance was asked
// somewhere else, or this window opened after the line was sent.
said(them, payload.said ?? "", "them", payload.at);
said(them, outcome.said, "them", payload.at);
return;
}
const turn = outcome.turn;
settled(turn.them);
if (payload.said) {
arrived(turn.them, payload.said);
} else if (payload.error) {
if (outcome.action === "speech") {
arrived(turn.them, outcome.said);
} else if (outcome.action === "error") {
// The Harness answered, and the answer was an error — a model the
// installed CLI will not serve, a signed-out agent. Static weights
// took the turn either way, so the row looks like the one below; the
// error is the only part the user can act on, and #514 is a day of
// wakes spent because it was never said (ADR-0008).
turn.them.remove();
note(`The Harness reported an error: ${payload.error}`);
note(outcome.note);
} else if (outcome.action === "silent") {
turn.them.remove();
} else {
// A turn that produced no line: the call failed and static weights
// took over, which are silent by contract, or Do Not Disturb refused
// the dialogue. Said out loud, because a log that stops is
// indistinguishable from one still waiting.
turn.them.remove();
note("No answer came back.");
note(MISSING_ANSWER);
}
},
{ target: chat.label },
Expand Down
85 changes: 85 additions & 0 deletions tests/chat-settle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Run with `node --test tests/chat-settle.test.js`.
//
// #681: the Chat surface wrote "No answer came back." under a turn that
// already had Speech. Treating an empty `said` as a missing-answer note after
// Speech has already been drawn is the production change that fails this file.

import assert from "node:assert/strict";
import { test } from "node:test";

import { MISSING_ANSWER, createChatTurns } from "../src/chat-settle.js";

function play(turns, payloads) {
const log = [];
for (const payload of payloads) {
const outcome = turns.settle(payload);
if (outcome.action === "speech") {
log.push(outcome.said);
} else if (outcome.action === "missing") {
log.push(outcome.note);
} else if (outcome.action === "error") {
log.push(outcome.note);
}
}
return log;
}

test("Speech already drawn, then said None, does not report a missing answer", () => {
const turns = createChatTurns();
turns.typed();
turns.typed();

const log = play(turns, [
{
said: "You may! Tell me one thing that would make me a more useful little buddy.",
},
{ said: null },
]);

assert.deepEqual(log, [
"You may! Tell me one thing that would make me a more useful little buddy.",
]);
assert.equal(
log.includes(MISSING_ANSWER),
false,
"an empty settle after Speech landed is not a missing answer",
);
});

test("a turn that produced no Speech still reports a missing answer", () => {
const turns = createChatTurns();
turns.typed();

const log = play(turns, [{ said: null }]);

assert.deepEqual(log, [MISSING_ANSWER]);
});

test("a later turn that produced no Speech still reports a missing answer", () => {
const turns = createChatTurns();
turns.typed();
play(turns, [{ said: "You may!" }]);
turns.typed();

const log = play(turns, [{ said: null }]);

assert.deepEqual(log, [MISSING_ANSWER]);
});

test("a superseded caret is not reported as a missing answer", () => {
const turns = createChatTurns();
turns.typed();

const log = play(turns, [{ said: null, superseded: true }]);

assert.deepEqual(log, []);
});

test("a Harness error is still the error, not a missing answer", () => {
const turns = createChatTurns();
turns.typed();

const log = play(turns, [{ said: null, error: "model not found" }]);

assert.deepEqual(log, ["The Harness reported an error: model not found"]);
});