practice round: dead session starts, prompt laws, preamble, label unify
THE START BUG (owner report, reproduced live both kinds): new sessions (?prompt flow — practice and teach alike) sat dead until a second message, which then persisted WITHOUT the first. Root cause, proven both directions: the submit POST rode the view's consumeAbort controller; React StrictMode's simulated remount fires Diet A's unmount cleanup (model.stop()) ~8ms in and killed the POST mid-flight; the page's sentInitial guard had already flipped, so it never retried. Teach was equally broken — only unnoticed, because every teach chat in use predates the diet and practice starts are always fresh. Fix: the submit law — POSTs are not abortable by view teardown (they are ~100ms acks since Diet B and cannot starve the pool); after the ack, a consumeAbort identity check guards the stream attach. Pinned with the stop-mid-submit regression test. Live: StrictMode on, practice draft POST 200/67ms, stream attached, message persisted, problem posed. PRACTICE PROMPT (00-base): the opening rule — material arrives two ways, both first-class (picked propositions primary; free-form — topics, course material, files/PDFs — fully supported, never refused); as soon as material exists the reply poses, at most one short line before the problem call, no warm-up interview. Plus the hard law: no problem is ever conversation — every problem through the tool (no thinking field/no reveal/no verdict attaches to prose). GRAPH-CONTEXT PREAMBLE: custom markers flatten to user-role on the wire, so the old "Contextualization — the learner picked…" read like a system broadcast in the learner's voice channel. Now the bracket convention: "[Session context] — picked from the learner's knowledge map…". SIDEBAR: busy rows unify to "Working…" for both kinds (the spinner's default label included); "Practicing…"/"Teacher is working…" retired. Gates: 1490/1490, typecheck, lint. doctrine's stale doc pointer fixed.
This commit is contained in:
@@ -36,7 +36,7 @@ export const SPINNER_FRAMES = FRAMES.length;
|
||||
|
||||
export function BrailleSpinner({
|
||||
className,
|
||||
label = "Teacher is working",
|
||||
label = "Working",
|
||||
}: {
|
||||
/** Sizing/position classes; height drives the scale (width is the cell's 1:2 aspect). */
|
||||
className?: string;
|
||||
|
||||
@@ -561,8 +561,19 @@ export class SessionModel {
|
||||
this.tail = [...this.tail, ...optimistic];
|
||||
});
|
||||
try {
|
||||
const res = await this.postInputEvent(input, controller.signal);
|
||||
if (controller.signal.aborted) return;
|
||||
// SUBMITS ARE NOT ABORTABLE BY VIEW TEARDOWN (owner, 2026-10-10 —
|
||||
// the dead-session-start postmortem): the POST must NOT ride
|
||||
// consumeAbort. Diet A's abort-on-unmount (session.ts's stop())
|
||||
// fires on React StrictMode's simulated remount in dev — it killed
|
||||
// the ?prompt first send ~8ms in (POST aborted, never retried:
|
||||
// the page's sentInitial guard had already flipped), leaving the
|
||||
// session dead until a second message, which then persisted
|
||||
// WITHOUT the first — the optimistic tail rode a record that never
|
||||
// contained it. The POST is a ~100ms ack since Diet B; it cannot
|
||||
// starve the connection pool, so it needs no teardown guard. The
|
||||
// STREAM consume stays on the controller — releasing that held
|
||||
// connection is Diet A's whole job.
|
||||
const res = await this.postInputEvent(input);
|
||||
if (res.status === 409) {
|
||||
this.setError("A turn is already running — try again in a moment.");
|
||||
this.setStatus("error");
|
||||
@@ -582,6 +593,10 @@ export class SessionModel {
|
||||
// replay lands on top). One live view connection per page, always —
|
||||
// the browser's 6-per-origin pool is the scarce resource.
|
||||
await res.text().catch(() => {}); // drain the tiny ack; release the socket
|
||||
// A stop() or a newer send/consume won while the ack was in
|
||||
// flight: the turn is live server-side either way — do not attach
|
||||
// a stream from a view that is gone or superseded.
|
||||
if (this.consumeAbort !== controller) return;
|
||||
await this.resumeStream(true);
|
||||
} catch (err) {
|
||||
if ((err as Error).name === "AbortError") return; // stop() or a newer consume won
|
||||
|
||||
@@ -248,7 +248,7 @@ function sessionMeta(chat: ChatListItem): string {
|
||||
if ((chat.kind ?? "teach") === "practice" && chat.pendingProblem) {
|
||||
return `Problem waiting · ${timeAgo(chat.updatedAt)}`;
|
||||
}
|
||||
if (chat.busy) return (chat.kind ?? "teach") === "practice" ? "Practicing…" : "Teacher is working…";
|
||||
if (chat.busy) return "Working…";
|
||||
return timeAgo(chat.updatedAt);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,18 @@
|
||||
|
||||
You are the agent of a learning harness, running practice sessions. Your job is to make held knowledge come to mind and run — the doctrine section carries the method; this base carries the register, the accuracy contract, and the tool mechanics.
|
||||
|
||||
## The opening — straight to problems (owner, 2026-10-10)
|
||||
|
||||
Material arrives two ways, and both are first-class starts:
|
||||
|
||||
- **Picked propositions** — the session context carries them at the top of the transcript (ids ready for the `problem` tool's target field). This is the primary path: the first reply poses from them directly.
|
||||
- **Free-form** — a topic in the learner's own words, course material, files or PDFs they reference. Read what they point at (the side tools below); a topic description is already material enough to pose against. Never balk at a free-form start — never refuse it, never ask the learner to restate it in some other form, never treat picked propositions as the only legitimate entry.
|
||||
|
||||
Either way, the law is the same: **as soon as the material for a problem exists, the reply poses.** At most one short line of orientation before the `problem` call — never a warm-up exchange, never clarifying questions when the material already bounds the demand. Calibration comes from the opening demands themselves (the doctrine's open-warm arc), not from an interview.
|
||||
|
||||
## Tool mechanics
|
||||
|
||||
Two tools, and everything else is conversation. The mechanics only — the method (when to pose, what to pose, how to respond) is the doctrine's.
|
||||
Two tools, and everything else is conversation — with one hard exception: **no problem is ever conversation.** Every problem, first to last, is posed through the `problem` tool. A problem written as chat prose is a protocol violation — no thinking field can attach to it, no hidden model solution, no verdict, no retest. If you catch yourself writing a problem in a message, stop and make the call instead. The mechanics only — the method (when to pose, what to pose, how to respond) is the doctrine's.
|
||||
|
||||
**`problem`** — poses one problem. The statement field is what the learner sees (markdown and LaTeX render — every piece of math in the statement and the model solution goes in LaTeX); the modelSolution is your private commitment, hidden from the learner until you conclude — solve and shortcut-hunt the problem yourself BEFORE posing: the committed solution is your own worked solution, never a hope. When the session's material lives in the map, target takes the proposition ids from the session context — ids are how every problem is traced to the propositions it exercises. When it does not (a topic with nothing in the map), omit target entirely: problems stand on their own, untagged. The call ends the turn. The learner then works in a thinking field; each submission arrives back as a *Your thinking* message. Whether it claims an answer is IN THE TEXT, not declared anywhere — read it:
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
§I material-arrival generalized (verbal descriptions, outside problems);
|
||||
§VIII pause law (owner round 16, 2026-10-06: concluding ends the turn;
|
||||
the learner's explicit go-ahead paces the stream). Tool mechanics live
|
||||
in 00-base.md; theory in docs/vision-practice-sessions.md's source note. -->
|
||||
in 00-base.md; theory in the archived vision-practice note (docs-archive). -->
|
||||
|
||||
# The practice session
|
||||
|
||||
|
||||
@@ -213,7 +213,12 @@ export function newGraphContextMessage(picks: readonly GraphContextPick[], chain
|
||||
// ids at the seam). Chains below stay NAMES — they are comprehension
|
||||
// context, not tags; names read, ids reference.
|
||||
const lines = [
|
||||
"Contextualization — the learner picked these propositions from their knowledge map when starting this session:",
|
||||
// PREAMBLE LAW (owner, 2026-10-10): custom markers flatten to
|
||||
// USER-role messages on the wire (toLlmMessages) — this text arrives
|
||||
// in the learner's voice channel, so it must not read like a system
|
||||
// broadcast. The bracket convention (NEXT_PROBLEM_TEXT's kin) marks
|
||||
// it honestly as injected session context, not learner speech.
|
||||
"[Session context] — picked from the learner's knowledge map when starting this session:",
|
||||
"",
|
||||
"Propositions (id — name: statement; the problem tool's target field uses these ids):",
|
||||
...picks.map((p) => `- [${p.id}] ${p.name}: ${p.statement}`),
|
||||
|
||||
@@ -48,7 +48,7 @@ describe("newGraphContextMessage", () => {
|
||||
it("frames the context for the model: propositions listed, chains appended", () => {
|
||||
const m = newGraphContextMessage(PICKS, ["Modus ponens → Soundness"]);
|
||||
assert.equal(m.customType, "graph-context");
|
||||
assert.match(m.content, /Contextualization — the learner picked these propositions/);
|
||||
assert.match(m.content, /\[Session context\] — picked from the learner's knowledge map/);
|
||||
// IDS FIRST (owner round 9): every pick carries its id — the problem
|
||||
// tool's target field references these; names alone no longer.
|
||||
assert.ok(m.content.includes(`- [${PICKS[0]!.id}] Modus ponens: If P implies Q and P holds, Q holds.`));
|
||||
@@ -69,7 +69,7 @@ describe("newGraphContextMessage", () => {
|
||||
const wire = toLlmMessages([m as unknown as LhMessage] as never);
|
||||
assert.equal(wire.length, 1);
|
||||
assert.equal(wire[0]!.role, "user");
|
||||
assert.ok(String((wire[0]!.content as { text?: string }[])[0]!.text).includes("Contextualization"));
|
||||
assert.ok(String((wire[0]!.content as { text?: string }[])[0]!.text).includes("[Session context]"));
|
||||
});
|
||||
|
||||
it("projectView: a user-side data part — never a text bubble", () => {
|
||||
|
||||
@@ -67,7 +67,7 @@ describe("SessionRow", () => {
|
||||
assert.ok(html.includes("braille-frame"), "CSS-animated frames");
|
||||
assert.ok((html.match(/class="braille-frame"/g) ?? []).length === 10, "all ten frames");
|
||||
assert.ok(html.includes('data-frame="0"'), "frame 0 leads (static fallback)");
|
||||
assert.ok(html.includes("Teacher is working"), "accessible label");
|
||||
assert.ok(html.includes("Working"), "accessible label");
|
||||
assert.ok(!html.includes("bg-attention"), "no colored state fill — monochrome by design");
|
||||
});
|
||||
|
||||
@@ -77,7 +77,7 @@ describe("SessionRow", () => {
|
||||
// contract can't silently re-widen: an extraction-only "working"
|
||||
// row would be a double signal.
|
||||
const html = render(item({ busy: true, pendingQuestion: false }));
|
||||
assert.ok(html.includes("Teacher is working"), "the spinner's label names the turn, not agents");
|
||||
assert.ok(html.includes("Working"), "the spinner's label names the turn, not agents");
|
||||
});
|
||||
|
||||
it("the meta line: state replaces the count when the state is the useful fact", () => {
|
||||
@@ -87,7 +87,7 @@ describe("SessionRow", () => {
|
||||
assert.ok(!awaiting.includes("braille-spinner"), "…and the spinner stays off");
|
||||
|
||||
const working = render(item({ busy: true }));
|
||||
assert.ok(working.includes("Teacher is working…"), "working meta");
|
||||
assert.ok(working.includes("Working…"), "working meta");
|
||||
|
||||
// Owner, typography round 5: the message count is dropped — it
|
||||
// informed no decision. Idle meta is just how long ago.
|
||||
@@ -121,9 +121,10 @@ describe("timeAgo", () => {
|
||||
});
|
||||
|
||||
describe("SessionRow practice badge (practice sessions, 2026-10-04)", () => {
|
||||
it("a practice row carries the dumbbell badge and the Practicing meta while busy", () => {
|
||||
it("a practice row carries the dumbbell badge and the unified Working meta while busy (owner, 2026-10-10)", () => {
|
||||
const html = render(item({ kind: "practice", busy: true }));
|
||||
assert.match(html, /Practicing…/);
|
||||
assert.match(html, /Working…/);
|
||||
assert.doesNotMatch(html, /Practicing…/);
|
||||
assert.match(html, /aria-label="Practice session"/);
|
||||
});
|
||||
|
||||
@@ -133,9 +134,9 @@ describe("SessionRow practice badge (practice sessions, 2026-10-04)", () => {
|
||||
assert.doesNotMatch(html, /Practicing…/);
|
||||
});
|
||||
|
||||
it("busy teaching rows still say the teacher is working", () => {
|
||||
it("busy teaching rows say the same unified Working", () => {
|
||||
const html = render(item({ busy: true }));
|
||||
assert.match(html, /Teacher is working…/);
|
||||
assert.match(html, /Working…/);
|
||||
});
|
||||
|
||||
it("a practice row with a posed problem says the problem is waiting", () => {
|
||||
|
||||
@@ -593,6 +593,48 @@ describe("resumeStream (the reattach path)", () => {
|
||||
assert.equal(m.getState().status, "ready");
|
||||
});
|
||||
|
||||
it("SESSION START SURVIVES A STOP() RACING THE SUBMIT (owner, 2026-10-10 — the dead-practice-start postmortem)", async () => {
|
||||
// React StrictMode's simulated remount fires the unmount cleanup
|
||||
// (~8ms in) while the ?prompt first send's POST is in flight — the
|
||||
// exact live repro: pre-fix, the POST rode consumeAbort and died
|
||||
// with AbortError, the page's sentInitial guard never retried, and
|
||||
// the session sat dead until a second message (which then persisted
|
||||
// WITHOUT the first). The law: submits are not abortable by view
|
||||
// teardown — the POST completes, the turn is server-side, and the
|
||||
// dead view attaches no stream.
|
||||
let resolvePost!: () => void;
|
||||
let postAborted = false;
|
||||
const fetches: string[] = [];
|
||||
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url = String(input);
|
||||
fetches.push(url);
|
||||
if (url === "/api/chat") {
|
||||
init?.signal?.addEventListener("abort", () => {
|
||||
postAborted = true;
|
||||
});
|
||||
await new Promise<void>((r) => {
|
||||
resolvePost = () => r();
|
||||
});
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
if (url === "/api/chats/chat_x") {
|
||||
return Response.json({ messages: [{ id: "u1", role: "user", content: "quiz me", timestamp: 1 }] });
|
||||
}
|
||||
if (url === "/api/chats/chat_x/stream") return new Response("data: [DONE]\n\n", { status: 200 });
|
||||
throw new Error(`unexpected fetch: ${url}`);
|
||||
}) as typeof globalThis.fetch;
|
||||
const m = model();
|
||||
const sending = m.send({ type: "text", text: "quiz me" });
|
||||
await new Promise((r) => setTimeout(r, 5)); // the POST is in flight
|
||||
m.stop(); // StrictMode's simulated unmount lands mid-submit
|
||||
resolvePost(); // the ack completes anyway
|
||||
await sending;
|
||||
assert.equal(postAborted, false, "the submit POST carries no teardown signal at all");
|
||||
assert.ok(fetches.includes("/api/chat"), "the submit reached the server");
|
||||
assert.ok(!fetches.some((u) => u.endsWith("/stream")), "a dead view attaches no stream — the turn is server-side");
|
||||
assert.equal(m.getState().status, "ready");
|
||||
});
|
||||
|
||||
it("REATTACH REPLAYS ONTO A CLEAN SLATE (owner, optimistic round 3): an aborted attempt's partials never double", async () => {
|
||||
// StrictMode's simulated remount aborts the first resume mid-replay;
|
||||
// its partial tail survived into the retry and the replay DOUBLED
|
||||
|
||||
Reference in New Issue
Block a user