Multiplayer agent harness for work.
Trim per-turn context: grouped memory deltas, recent-only deliveries, no onboarding block (#2163)
Regan Bell54c5f16a3887
diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.tsindex 1f13f67b6..e432f92b9 100644--- a/src/core/orchestrator.ts+++ b/src/core/orchestrator.ts@@ -106,13 +106,7 @@ import { DEFAULT_MEMORY_POLICY } from "../memory/policy.ts";import { createMemoryMap } from "../persistence/durable-map.ts";import { collectBlob, createMemoryBlobTransferStore } from "../persistence/blob-transfer.ts";import { skillsIndex } from "../skills/materialize.ts";-import {- resolveOnboardingStatus,- onboardingSkillVisible,- isIdeasConversation,- PROACTIVE_OPENER_PROMPT,- renderPendingOnboardingPrompt,-} from "../onboarding/onboarding.ts";+import { isIdeasConversation, PROACTIVE_OPENER_PROMPT } from "../onboarding/onboarding.ts";import { createToolContext, NeedsApproval, CommandDenied, type CommandCredential } from "../tools/primitives.ts";import type { FileArtifact } from "../files/file-artifact-store.ts";import { filterHistoryForAudience, principalEntitledToScope } from "../resolution/context-filter.ts";@@ -1311,16 +1305,11 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {if (conversation.kind === "dm") memoryContext = "a direct message";else if (conversation.channelName) memoryContext = `#${conversation.channelName}`;else if (conversation.kind === "group") memoryContext = "a group conversation";- const memoryHeading = `\n\n## What you remember\nYou're in ${memoryContext}. Scope headings and \`(said in …)\` tags identify provenance. You may use facts from these included, authorized memories to answer this request; do not ask for them to be shared again merely because they came from another scope. Context-specific instructions and preferences still apply only to their source context unless the user says otherwise.\n\n`;+ const memoryHeading = `\n\n## What you remember\nYou're in ${memoryContext}; use these authorized memories freely, but preferences tagged with another scope heading or \`(said in …)\` apply only there.\n\n`;- let onboardingBlock = isIdeasConversation(input)+ const onboardingBlock = isIdeasConversation(input)? "## Ideas conversation\nThe user chose to explore ideas in this conversation. Skip the onboarding skill and setup flow for this entire conversation, including follow-ups. Do not mark onboarding completed or dismissed in memory. Use available authorized company context and answer their request directly.": "";- if (!onboardingBlock && useMemory && conversation.kind === "dm" && onboardingSkillVisible(visibleSkills)) {- onboardingBlock = await resolveOnboardingStatus(deps.memory, deps.sessions, memoryScopeId)- .then(renderPendingOnboardingPrompt)- .catch(swallowAs("orchestrator: onboarding status", ""));- }let type: SessionType = "channel";if (conversation.kind === "dm") type = "dm";@@ -3179,7 +3168,11 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {MAX_DOCUMENT_BYTES -documentInputs.documents.reduce((sum, document) => sum + Buffer.byteLength(document.dataBase64, "base64"), 0);let remainingDocumentCount = 10 - documentInputs.documents.length;- const principalDelivered = await recentPrincipalDeliveryNote(deps.deliveries, session.threadRef);+ const principalDelivered = await recentPrincipalDeliveryNote(+ deps.deliveries,+ session.threadRef,+ visibleHistory.findLast((e) => e.type === "user" && !isOverheardEntry(e))?.createdAt,+ );const sender = !automatedTurn && input.text.trim() ? senderNote(actor.displayName) : "";const unscreenedNote =inputUnscreened || (enforceScreen && inbound.unscreened.length) || documentsUnscreeneddiff --git a/src/core/orchestrator/turn-helpers.ts b/src/core/orchestrator/turn-helpers.tsindex 93bceb927..88d6a5e32 100644--- a/src/core/orchestrator/turn-helpers.ts+++ b/src/core/orchestrator/turn-helpers.ts@@ -184,9 +184,12 @@ const DELIVERY_NOTE_ITEM_MAX_CHARS = 200;export async function recentPrincipalDeliveryNote(deliveries: DeliveryStore | undefined,threadRef: string,+ since = 0,): Promise<string> {if (!deliveries) return "";- const recent = await deliveries.listByRecipientThread(threadRef, { limit: 5 });+ const recent = (await deliveries.listByRecipientThread(threadRef, { limit: 5 })).filter(+ (d) => (d.deliveredAt ?? d.createdAt) > since,+ );if (!recent.length) return "";const lines = recent.map((d) => {const from = d.destination.onBehalfOf ? ` from ${d.destination.onBehalfOf}` : "";@@ -198,11 +201,7 @@ export async function recentPrincipalDeliveryNote(: flattened;return `- ${new Date(d.deliveredAt ?? d.createdAt).toISOString()}${trigger}${from}: ${text}`;});- return [- "Recent agent-initiated deliveries to this conversation:",- ...lines,- "These are delivery events, not prior assistant turns. Use them as context if the user replies about them.",- ].join("\n");+ return ["Delivered here since the user's last message (delivery events, not your turns):", ...lines].join("\n");}function principalAssertion(p: Principal): ActorAssertion {diff --git a/src/memory/recall-delta.ts b/src/memory/recall-delta.tsindex a7c600afa..cb8993a62 100644--- a/src/memory/recall-delta.ts+++ b/src/memory/recall-delta.ts@@ -1,20 +1,27 @@import type { SessionEntry } from "../types.ts";+import { isMemoryBookkeeping } from "./notebook.ts";interface RecallRecord {body: string;anchorSeq?: number;}-function facts(body: string): Map<string, string> {- const result = new Map<string, string>();+interface Fact {+ scope: string;+ header: string;+ text: string;+}++function facts(body: string): Map<string, Fact> {+ const result = new Map<string, Fact>();const headings: string[] = [];let scope = "";let pending: string[] = [];const flush = () => {const text = pending.join("\n").trim();if (text) {- const rendered = [scope, ...headings.filter(Boolean), text].filter(Boolean).join("\n");- result.set(rendered, rendered);+ const header = [scope, ...headings.filter(Boolean)].filter(Boolean).join("\n");+ result.set(`${header}\n${text}`, { scope: scope.slice(4), header, text });}pending = [];};@@ -31,15 +38,21 @@ function facts(body: string): Map<string, string> {const level = heading[1]!.length;headings.length = level;headings[level - 1] = line;- } else if (!line.trim() || /^[-*]\s/.test(line)) {+ } else if (!line.trim() || isMemoryBookkeeping(line) || /^[-*]\s/.test(line)) {flush();- if (line.trim()) pending.push(line);+ if (line.trim() && !isMemoryBookkeeping(line)) pending.push(line);} else pending.push(line);}flush();return result;}+function render(list: Iterable<Fact>): string {+ const groups = new Map<string, string[]>();+ for (const { header, text } of list) groups.set(header, [...(groups.get(header) ?? []), text]);+ return [...groups].map(([header, texts]) => [header, ...texts].filter(Boolean).join("\n")).join("\n\n");+}+export function memoryRecallDelta(body: string,history: readonly SessionEntry[],@@ -54,21 +67,24 @@ export function memoryRecallDelta(const anchorSeq = previous?.anchorSeq ?? previousEntry?.seq;const retained = anchorSeq !== undefined && history.some((entry) => entry.seq === anchorSeq);const record = { body, ...(retained ? { anchorSeq } : {}) };- if (!retained || !previous) return { text: body, record };+ const newFacts = facts(body);+ if (!retained || !previous) return { text: render(newFacts.values()), record };if (previous.body === body) return { text: "", record };const oldFacts = facts(previous.body);- const newFacts = facts(body);- const added = [...newFacts].filter(([key]) => !oldFacts.has(key)).map(([, text]) => text);- const removed = [...oldFacts].filter(([key]) => !newFacts.has(key)).map(([, text]) => text);- const mayQuote = (fact: string) => authorizedScopes.some((scope) => fact.startsWith(`### ${scope}\n`));- const withdrawn = removed.filter(mayQuote);+ const added = [...newFacts].filter(([key]) => !oldFacts.has(key)).map(([, fact]) => fact);+ const removed = new Map<string, number>();+ for (const [key, { scope }] of oldFacts) if (!newFacts.has(key)) removed.set(scope, (removed.get(scope) ?? 0) + 1);+ const withdrawn = [...removed].filter(([scope]) => authorizedScopes.includes(scope));return {text: [- added.length ? `New or updated memory facts:\n\n${added.join("\n\n")}` : "",- withdrawn.length- ? `These earlier memory facts have been withdrawn; do not continue relying on them:\n\n${withdrawn.join("\n\n")}`- : "",- removed.length > withdrawn.length+ added.length ? `New or updated memory facts:\n\n${render(added)}` : "",+ withdrawn+ .map(+ ([scope, n]) =>+ `${scope}: ${n} earlier ${n === 1 ? "fact was" : "facts were"} consolidated or removed; rely only on the current list.`,+ )+ .join("\n"),+ removed.size > withdrawn.length? "Some previously recalled memory sources are no longer included. Do not rely on memory from sources that are not currently authorized.": "",]diff --git a/src/onboarding/onboarding.ts b/src/onboarding/onboarding.tsindex 3dadfebdb..da086a6d1 100644--- a/src/onboarding/onboarding.ts+++ b/src/onboarding/onboarding.ts@@ -1,9 +1,5 @@-import type { ScopeId, TurnRequest } from "../types.ts";-import type { SkillResolution } from "../skills/skill-store.ts";-import type { MemoryService } from "../memory/memory-service.ts";-import type { SessionStore } from "../sessions/session-store.ts";+import type { TurnRequest } from "../types.ts";-const ONBOARDING_SKILL_NAME = "onboarding";const ONBOARDING_VERSION = "v2";export const PROACTIVE_OPENER_PROMPT =@@ -55,48 +51,6 @@ export function setOnboardingStatus(return (base ? `${base}\n${line}` : line) + "\n";}-export function onboardingSkillVisible(skills: SkillResolution[]): boolean {- return skills.some((r) => r.skill?.manifest.name === ONBOARDING_SKILL_NAME);-}--export async function resolveOnboardingStatus(- memory: MemoryService,- sessions: SessionStore,- scope: ScopeId,-): Promise<OnboardingStatus> {- const status = detectOnboardingStatus(await memory.read(scope));- if (status === "completed" || status === "dismissed") return status;- if (!scope.startsWith("personal:") || (await sessions.countPersonalConversations(scope, 3)) < 3) return status;- if (memory.readHead && memory.replaceIfRevision) {- for (let attempt = 0; attempt < 3; attempt++) {- const head = await memory.readHead(scope);- const current = detectOnboardingStatus(head.content);- if (current === "completed" || current === "dismissed") return current;- const next = setOnboardingStatus(head.content, "dismissed", new Date().toISOString().slice(0, 10));- if (await memory.replaceIfRevision(scope, next, head.revision, "system:onboarding")) break;- }- }- return "dismissed";-}--export function renderPendingOnboardingPrompt(status: OnboardingStatus, version = ONBOARDING_VERSION): string {- if (status === "completed" || status === "dismissed") return "";- const marker =- status === "pending"- ? `Memory says onboarding is pending for ${version}.`- : `Memory has no onboarding completion marker for ${version}.`;- return [- "## Pending Onboarding",- marker,- "",- "Onboarding is a high-priority setup task; already knowing who they are is no reason to skip it.",- "",- "Before ordinary work in this personal DM, load the onboarding skill with the skills tool and follow its complete ordered flow. Keep each turn light, but do not confuse a greeting or existing profile data with completion.",- "",- `Use the \`memory\` tool as the source of truth. On completion or an explicit stop, preserve the notebook and add \`- Onboarding: completed ${version} on YYYY-MM-DD.\` so onboarding does not recur.`,- ].join("\n");-}-export function isIdeasConversation(input: {surface?: string;conversation: Pick<TurnRequest["conversation"], "kind" | "threadRef">;diff --git a/src/sessions/memory-session-store.ts b/src/sessions/memory-session-store.tsindex b6ac75b9d..8235353bb 100644--- a/src/sessions/memory-session-store.ts+++ b/src/sessions/memory-session-store.ts@@ -691,41 +691,6 @@ export function createMemorySessionStore(opts: StoreOptions = {}): SessionStorereturn [...sessions.values()].some((s) => s.scopeId === scope);},- async countPersonalConversations(scope, limit = 3) {- const boundedLimit = Math.max(0, Math.floor(limit));- if (!boundedLimit) return 0;- let count = 0;- for (const session of sessions.values()) {- if (- session.scopeId !== scope ||- session.type !== "dm" ||- session.parentSessionId ||- sessionOrigin(session.threadRef) !== "conversation"- )- continue;- const log = new Map((entries.get(session.id) ?? []).map((entry) => [entry.seq, entry]));- for (const row of tape.get(session.id) ?? []) {- const entry = transcriptEntryFromTape(row);- if (entry) log.set(entry.seq, entry);- }- if (- [...log.values()].some((entry) => {- const payload = entry.payload as { hidden?: unknown; overheard?: unknown } | null;- return (- entry.seq > (session.forkBoundarySeq ?? -1) &&- entry.type === "user" &&- payload?.hidden !== true &&- payload?.overheard !== true- );- })- ) {- count++;- if (count >= boundedLimit) break;- }- }- return count;- },-async sessionsByThreadRefs(threadRefs) {const wanted = new Set(threadRefs);return [...sessions.values()]diff --git a/src/sessions/postgres-session-store.ts b/src/sessions/postgres-session-store.tsindex 51d64d0d0..f87700765 100644--- a/src/sessions/postgres-session-store.ts+++ b/src/sessions/postgres-session-store.ts@@ -1711,33 +1711,6 @@ export function createPostgresSessionStore(connectionString: string, opts: Storereturn Boolean(rows[0]?.present);},- async countPersonalConversations(scope, limit = 3): Promise<number> {- const boundedLimit = Math.max(0, Math.floor(limit));- if (!boundedLimit) return 0;- const rows = await q(- `SELECT COUNT(*) AS n FROM (- SELECT s.id FROM sessions s- WHERE s.scope_id = $1 AND s.type = 'dm' AND s.parent_session_id IS NULL- AND ${hasOrigin("s", "conversation")}- AND EXISTS (- SELECT 1 FROM (- SELECT DISTINCT ON (seq) seq, type, payload FROM (- SELECT seq, type, payload, 1 AS priority FROM session_transcript_entries WHERE session_id = s.id- UNION ALL- SELECT seq, type, payload, 0 AS priority FROM session_entries WHERE session_id = s.id- ) sources ORDER BY seq, priority DESC- ) e- WHERE e.seq > COALESCE(s.fork_boundary_seq, -1) AND e.type = 'user'- AND (safe_json(replace(e.payload, '\\u0000', ''))->'hidden')::text IS DISTINCT FROM 'true'- AND (safe_json(replace(e.payload, '\\u0000', ''))->'overheard')::text IS DISTINCT FROM 'true'- )- LIMIT $2- ) conversations`,- [scope, boundedLimit],- );- return Number(rows[0]?.n ?? 0);- },-async sessionsByThreadRefs(threadRefs): Promise<SessionRef[]> {if (threadRefs.length === 0) return [];const rows = await q("SELECT id, thread_ref, scope_id, type, title FROM sessions WHERE thread_ref = ANY($1)", [diff --git a/src/sessions/session-store.ts b/src/sessions/session-store.tsindex f08e7654e..a76cde66a 100644--- a/src/sessions/session-store.ts+++ b/src/sessions/session-store.ts@@ -780,8 +780,6 @@ export interface SessionStore {scopeHasSessions(scope: ScopeId): Promise<boolean>;- countPersonalConversations(scope: ScopeId, limit?: number): Promise<number>;-sessionsByThreadRefs(threadRefs: readonly string[]): Promise<SessionRef[]>;distinctScopes(): Promise<DistinctScope[]>;diff --git a/test/admin-observability.test.ts b/test/admin-observability.test.tsindex c46417fda..917815b01 100644--- a/test/admin-observability.test.ts+++ b/test/admin-observability.test.ts@@ -647,7 +647,7 @@ test("principal deliveries render as delivery events and later DM turns get struconst reqs = await s.built.sessions.listLlmRequests(session!.id);const latest = reqs[reqs.length - 1] as any;const userMessage = latest.promptEnvelope.messages.at(-1).content;- assert.match(userMessage, /Recent agent-initiated deliveries to this conversation/);+ assert.match(userMessage, /Delivered here since the user's last message/);assert.match(userMessage, /the deploy is done/);} finally {await s.close();diff --git a/test/memory-recall-delta.test.ts b/test/memory-recall-delta.test.tsindex 3e761fd90..c670adec6 100644--- a/test/memory-recall-delta.test.ts+++ b/test/memory-recall-delta.test.ts@@ -17,7 +17,7 @@ const entry = (body: string, seq = 1, anchorSeq?: number): SessionEntry => ({test("first automatic recall is complete; repeated unchanged recall is empty after reload", () => {const body = notebook("- ALPHA\n- BETA");- assert.equal(memoryRecallDelta(body, []).text, body);+ assert.equal(memoryRecallDelta(body, []).text, "### personal:alice\n# Memory\n- ALPHA\n- BETA");const persisted = JSON.parse(JSON.stringify([entry(body)])) as SessionEntry[];assert.equal(memoryRecallDelta(body, persisted).text, "");});@@ -26,7 +26,8 @@ test("changed notes emit additions and withdrawals with scope provenance, omitticonst delta = memoryRecallDelta(notebook("- ALPHA\n- GAMMA"), [entry(notebook("- ALPHA\n- BETA"))]);assert.doesNotMatch(delta.text, /ALPHA/);assert.match(delta.text, /New or updated memory facts:[\s\S]*personal:alice[\s\S]*GAMMA/);- assert.match(delta.text, /withdrawn[\s\S]*BETA/);+ assert.match(delta.text, /personal:alice: 1 earlier fact was consolidated or removed/);+ assert.doesNotMatch(delta.text, /BETA/);assert.equal(delta.record.anchorSeq, 1);});@@ -49,13 +50,16 @@ test("multiline facts remain intact and headings with unchanged content add nothtest("compacting away the recall anchor restores a current baseline", () => {const body = notebook("- ALPHA\n- BETA");const history = [entry(body, 8, 1)];- assert.equal(memoryRecallDelta(body, history).text, body);+ assert.match(memoryRecallDelta(body, history).text, /ALPHA\n- BETA/);assert.equal(memoryRecallDelta(body, history).record.anchorSeq, undefined);});test("all removed facts are withdrawn and repeated empty memory adds nothing", () => {const before = notebook("- OLD");- assert.match(memoryRecallDelta("", [entry(before)], ["personal:alice"]).text, /withdrawn[\s\S]*OLD/);+ assert.equal(+ memoryRecallDelta("", [entry(before)], ["personal:alice"]).text,+ "personal:alice: 1 earlier fact was consolidated or removed; rely only on the current list.",+ );assert.equal(memoryRecallDelta("", [entry(before), entry("", 3, 1)]).text, "");});@@ -66,6 +70,16 @@ test("withdrawals never quote facts from a revoked or disabled memory scope", ()assert.match(result.text, /no longer included/);});+test("each scope and heading is rendered once and bookkeeping markers are never facts", () => {+ const body = `### personal:alice\n### personal:alice\n## Work\n- ONE\n\n- TWO\n<!-- consolidated: 2026-10-01 -->\n<!-- captures-since-promote: 4 -->`;+ assert.equal(memoryRecallDelta(body, []).text, "### personal:alice\n## Work\n- ONE\n- TWO");+ const delta = memoryRecallDelta(body.replace("- TWO", "- THREE\n- FOUR"), [entry(body)]);+ assert.equal(+ delta.text,+ "New or updated memory facts:\n\n### personal:alice\n## Work\n- THREE\n- FOUR\n\npersonal:alice: 1 earlier fact was consolidated or removed; rely only on the current list.",+ );+});+test("recall checkpoint metadata never leaks into attachment-only compaction input", () => {const recorded = entry(notebook("- CHECKPOINT_ONLY_FACT"));recorded.payload = { ...(recorded.payload as Record<string, unknown>), text: "", environment: "file: report.csv" };diff --git a/test/onboarding.test.ts b/test/onboarding.test.tsindex 86a39fd1a..db44ecf52 100644--- a/test/onboarding.test.ts+++ b/test/onboarding.test.ts@@ -8,12 +8,7 @@ import { join } from "node:path";import { buildApp } from "../src/wiring.ts";import type { Config } from "../src/config.ts";import { scopeId, type TurnRequest } from "../src/types.ts";-import {- detectOnboardingStatus,- resolveOnboardingStatus,- setOnboardingStatus,- PROACTIVE_OPENER_PROMPT,-} from "../src/onboarding/onboarding.ts";+import { detectOnboardingStatus, setOnboardingStatus, PROACTIVE_OPENER_PROMPT } from "../src/onboarding/onboarding.ts";import { testConfig } from "./support/test-config.ts";const actor = { externalId: "U1" };@@ -66,7 +61,7 @@ test("setOnboardingStatus rewrites the marker and round-trips through detect", (assert.equal(detectOnboardingStatus(setOnboardingStatus("", "pending", "2026-06-22")), "pending");});-test("a new personal DM gets the high-priority pending onboarding prompt", async () => {+test("a new personal DM offers onboarding through the skills index", async () => {const { app, skills } = freshApp();await waitForOnboardingSkill(skills);@@ -77,47 +72,7 @@ test("a new personal DM gets the high-priority pending onboarding prompt", asynctext: "!sysprompt",} as TurnRequest);- assert.match(sys.reply ?? "", /## Pending Onboarding/);- assert.match(sys.reply ?? "", /high-priority setup task/);- assert.match(sys.reply ?? "", /no reason to skip it/);- assert.match(sys.reply ?? "", /load the onboarding skill with the skills tool/);-});--test("completed or dismissed onboarding markers suppress the pending prompt", async () => {- const { app, skills, memory } = freshApp();- await waitForOnboardingSkill(skills);- await memory.replace(scopeId("personal", "U1"), "## Onboarding\n\n- Onboarding: completed v2 on 2026-06-09.\n");-- const completed = await app.turn({- surface: "test",- actor,- conversation: { kind: "dm", threadRef: "dm:U1:onboarding-completed" },- text: "!sysprompt",- } as TurnRequest);- assert.doesNotMatch(completed.reply ?? "", /## Pending Onboarding/);-- await memory.replace(scopeId("personal", "U1"), "## Onboarding\n\n- Onboarding: dismissed v2 on 2026-06-09.\n");- const dismissed = await app.turn({- surface: "test",- actor,- conversation: { kind: "dm", threadRef: "dm:U1:onboarding-dismissed" },- text: "!sysprompt",- } as TurnRequest);- assert.doesNotMatch(dismissed.reply ?? "", /## Pending Onboarding/);-});--test("onboarding prompt does not appear in channel sessions", async () => {- const { app, skills } = freshApp();- await waitForOnboardingSkill(skills);-- const sys = await app.turn({- surface: "test",- actor,- conversation: { kind: "channel", threadRef: "C1:onboarding", channelRef: "C1", audience: [actor] },- text: "!sysprompt",- } as TurnRequest);-- assert.doesNotMatch(sys.reply ?? "", /## Pending Onboarding/);+ assert.match(sys.reply ?? "", /\*\*onboarding\*\*/);});test("the opener defers Slack setup until status can be checked without requiring provider configuration", () => {@@ -139,7 +94,6 @@ test("ideas web conversations bypass onboarding on every turn without completingconversation: { kind: "dm", threadRef },text: "!sysprompt",} as TurnRequest);- assert.doesNotMatch(sys.reply ?? "", /## Pending Onboarding/);assert.match(sys.reply ?? "", /Skip the onboarding skill and setup flow for this entire conversation/);}assert.equal(detectOnboardingStatus(await memory.read(scopeId("personal", "U1"))), "not_started");@@ -149,120 +103,5 @@ test("ideas web conversations bypass onboarding on every turn without completingconversation: { kind: "dm", threadRef: "web:U1:ordinary" },text: "!sysprompt",} as TurnRequest);- assert.match(ordinary.reply ?? "", /## Pending Onboarding/);- const slack = await app.turn({- surface: "slack",- actor,- conversation: { kind: "dm", threadRef },- text: "!sysprompt",- } as TurnRequest);- assert.match(slack.reply ?? "", /## Pending Onboarding/);-});--for (const initialStatus of ["not_started", "pending"] as const) {- test(`three personal chats durably dismiss ${initialStatus} onboarding`, async () => {- const { app, skills, memory, sessions } = freshApp();- await waitForOnboardingSkill(skills);- const scope = scopeId("personal", "U1");- await memory.replace(scope, setOnboardingStatus("## Notes\n\nKeep my preferences.\n", initialStatus, "2026-09-17"));- const prompt = async () =>- (- await app.turn({- surface: "test",- actor,- conversation: { kind: "dm", threadRef: "dm:U1:current" },- text: "!sysprompt",- } as TurnRequest)- ).reply ?? "";- for (let i = 0; i < 3; i++) {- assert.equal(await resolveOnboardingStatus(memory, sessions, scope), initialStatus);- const session = await sessions.getOrCreateByThread(`web:U1:past-${i}`, "dm", scope);- const { lease } = await sessions.acquireLease(session.id);- assert.ok(lease);- await sessions.append(lease, { type: "user", payload: { text: "Help with my work" }, scopeLabel: scope });- await sessions.releaseLease(lease);- }- assert.doesNotMatch(await prompt(), /## Pending Onboarding/);- assert.equal(detectOnboardingStatus(await memory.read(scope)), "dismissed");- assert.match(await memory.read(scope), /Keep my preferences/);- const dismissed = await memory.read(scope);- for (const session of await sessions.listByScope(scope)) await sessions.deleteSession(session.id);- assert.doesNotMatch(await prompt(), /## Pending Onboarding/);- assert.equal(await memory.read(scope), dismissed);- });-}--test("automatic dismissal preserves concurrent completion and memory changes", async () => {- const { memory, sessions } = freshApp();- const scope = scopeId("personal", "U1");- const countingSessions = {- ...sessions,- async countPersonalConversations() {- await memory.replace(scope, "- Onboarding: completed v2 on 2026-09-17.\n- A concurrent preference.\n");- return 3;- },- };- await resolveOnboardingStatus(memory, countingSessions, scope);- assert.equal(detectOnboardingStatus(await memory.read(scope)), "completed");- assert.match(await memory.read(scope), /A concurrent preference/);-});--test("completed and dismissed onboarding do not recount or rewrite history", async () => {- const { memory, sessions } = freshApp();- const scope = scopeId("personal", "U1");- const noCounting = {- ...sessions,- async countPersonalConversations() {- throw new Error("unexpected count");- },- };- for (const status of ["completed", "dismissed"] as const) {- const content = setOnboardingStatus("Keep this.", status, "2026-09-17");- await memory.replace(scope, content);- const before = await memory.readHead!(scope);- assert.equal(await resolveOnboardingStatus(memory, noCounting, scope), status);- assert.deepEqual(await memory.readHead!(scope), before);- }-});--test("automatic dismissal writes the permanent notebook with scratch-promote memory", async () => {- const { memory, sessions } = freshApp({ memoryStrategy: "scratch-promote" });- const scope = scopeId("personal", "U1");- let count = 3;- const history = {- ...sessions,- async countPersonalConversations() {- return count;- },- };- await resolveOnboardingStatus(memory, history, scope);- assert.equal(detectOnboardingStatus(await memory.read(scope)), "dismissed");- count = 0;- assert.equal(await resolveOnboardingStatus(memory, history, scope), "dismissed");-});--test("automatic dismissal retries a notebook revision conflict without losing new facts", async () => {- const { memory, sessions } = freshApp();- const scope = scopeId("personal", "U1");- let attempts = 0;- const racingMemory = {- ...memory,- async replaceIfRevision(s: typeof scope, body: string, revision: string) {- if (attempts++ === 0) await memory.replace(s, "- A concurrently saved fact.\n");- return memory.replaceIfRevision!(s, body, revision);- },- };- await resolveOnboardingStatus(- racingMemory,- {- ...sessions,- async countPersonalConversations() {- return 3;- },- },- scope,- );- assert.equal(attempts, 2);- assert.equal(detectOnboardingStatus(await memory.read(scope)), "dismissed");- assert.match(await memory.read(scope), /A concurrently saved fact/);+ assert.doesNotMatch(ordinary.reply ?? "", /## Ideas conversation/);});diff --git a/test/orchestrator.test.ts b/test/orchestrator.test.tsindex 898f27961..911ffe5d9 100644--- a/test/orchestrator.test.ts+++ b/test/orchestrator.test.ts@@ -334,7 +334,7 @@ test("a cron-delivered digest lands as a delivery event with origin, not recipieconst reqs = await built.sessions.listLlmRequests(recipient!.id);const latest = reqs.at(-1) as any;const footer = latest.promptEnvelope.messages.at(-1).content;- assert.match(footer, /Recent agent-initiated deliveries to this conversation/);+ assert.match(footer, /Delivered here since the user's last message/);assert.match(footer, /\[cron\] from U-carol: /);assert.match(footer, /…$/m);assert.doesNotMatch(footer, /deploy digest ready/);diff --git a/test/postgres-store.test.ts b/test/postgres-store.test.tsindex 14fb85208..530f7b0b8 100644--- a/test/postgres-store.test.ts+++ b/test/postgres-store.test.ts@@ -1,6 +1,5 @@import { forModelContext } from "../src/harness/context-compaction.ts";import { memoryContextPayload, nextMemoryContext } from "../src/memory/context-boundary.ts";-import { assertPersonalConversationParity } from "./support/personal-conversation-parity.ts";import "./run-availability.ts";import { migrateTranscriptPage } from "../scripts/lib/transcript-tape-migration.ts";import { test, before } from "node:test";@@ -3333,37 +3332,6 @@ test("pg child parentage and spawn metadata survive reopening", { skip }, asyncassert.equal((await reopened.get(child.id))?.parentSessionId, undefined);});-test("pg personal conversation counts exclude synthetic and inherited chats", { skip }, async () => {- await assertPersonalConversationParity(createPostgresSessionStore(URL!), "pg-personal-count");-});--test("pg personal conversation counts tolerate legacy null characters", { skip }, async () => {- const store = createPostgresSessionStore(URL!);- const scope = scopeId("personal", "legacy-null-count");- const session = await store.getOrCreateByThread("legacy-null-count", "dm", scope);- const { lease } = await store.acquireLease(session.id);- assert.ok(lease);- await store.append(lease, { type: "user", payload: { text: "Hello" }, scopeLabel: scope });- await store.releaseLease(lease);- const pg = (await import("pg")).default;- const raw = new pg.Pool({ connectionString: URL });- try {- await raw.query("DELETE FROM session_tape WHERE session_id = $1", [session.id]);- await raw.query("UPDATE session_entries SET payload = $2 WHERE session_id = $1", [- session.id,- JSON.stringify({ text: "Hello\u0000", hidden: "true", overheard: "true" }),- ]);- assert.equal(await store.countPersonalConversations(scope), 1);- await raw.query("UPDATE session_entries SET payload = $2 WHERE session_id = $1", [- session.id,- JSON.stringify({ text: "Hello\u0000", hidden: true }),- ]);- assert.equal(await store.countPersonalConversations(scope), 0);- } finally {- await raw.end();- }-});-test("pg session status survives restart, is shared, and clears", { skip }, async () => {const first = createPostgresSessionStore(URL!);const session = await first.getOrCreateByThread("session-status", "dm", scopeId("personal", "U1"));diff --git a/test/recent-delivery-note.test.ts b/test/recent-delivery-note.test.tsindex f69ed8d69..202b43b17 100644--- a/test/recent-delivery-note.test.ts+++ b/test/recent-delivery-note.test.ts@@ -3,7 +3,7 @@ import assert from "node:assert/strict";import { createDeliveryStore } from "../src/delivery/delivery-store.ts";import { recentPrincipalDeliveryNote } from "../src/core/orchestrator/turn-helpers.ts";-async function deliveredNote(texts: string[]): Promise<string> {+async function deliveredNote(texts: string[], since?: number): Promise<string> {const store = createDeliveryStore();for (const [i, text] of texts.entries()) {const d = await store.enqueue({@@ -13,7 +13,7 @@ async function deliveredNote(texts: string[]): Promise<string> {});await store.recordRecipientThread(d.id, "dm:D-alice", 1_700_000_000_000 + i);}- return recentPrincipalDeliveryNote(store, "dm:D-alice");+ return recentPrincipalDeliveryNote(store, "dm:D-alice", since);}test("a long delivery is capped at 200 chars with an ellipsis, keeping timestamp and sender", async () => {@@ -41,3 +41,10 @@ test("the note lists at most five deliveries", async () => {assert.match(note, /delivery number 7/);assert.doesNotMatch(note, /delivery number 2\b/);});++test("only deliveries after the user's previous message are listed", async () => {+ const note = await deliveredNote(["before reply", "after reply"], 1_700_000_000_000);+ assert.match(note, /after reply/);+ assert.doesNotMatch(note, /before reply/);+ assert.equal(await deliveredNote(["already seen"], 1_700_000_000_000), "");+});diff --git a/test/session-store.test.ts b/test/session-store.test.tsindex b9ff2558f..095518470 100644--- a/test/session-store.test.ts+++ b/test/session-store.test.ts@@ -1,4 +1,3 @@-import { assertPersonalConversationParity } from "./support/personal-conversation-parity.ts";import { test } from "node:test";import assert from "node:assert/strict";import { createMemorySessionStore } from "../src/sessions/memory-session-store.ts";@@ -1138,7 +1137,3 @@ test("renewLease keeps a live turn's lock fresh and refuses stale or supersededassert.ok(taken.lease, "an expired lease can still be taken over");assert.equal(await store.renewLease(lease!), false, "the superseded holder cannot renew the new lock");});--test("personal conversation counts exclude synthetic and inherited chats", async () => {- await assertPersonalConversationParity(createMemorySessionStore(), "personal-count");-});diff --git a/test/support/personal-conversation-parity.ts b/test/support/personal-conversation-parity.tsdeleted file mode 100644index dfa066d32..000000000--- a/test/support/personal-conversation-parity.ts+++ /dev/null@@ -1,58 +0,0 @@-import assert from "node:assert/strict";-import { scopeId, type SessionType } from "../../src/types.ts";-import { tapeTranscriptEntryRecord, type SessionStore } from "../../src/sessions/session-store.ts";--export async function assertPersonalConversationParity(store: SessionStore, prefix: string): Promise<void> {- const scope = scopeId("personal", prefix);- const create = async (- name: string,- payload?: Record<string, unknown>,- type: SessionType = "dm",- sessionScope = scope,- threadRef = `${prefix}:${name}`,- ) => {- const session = await store.getOrCreateByThread(threadRef, type, sessionScope);- if (payload) {- const { lease } = await store.acquireLease(session.id);- assert.ok(lease);- await store.append(lease, { type: "user", payload, scopeLabel: sessionScope });- await store.releaseLease(lease);- }- return session;- };- await create("empty");- await create("proactive", { text: "Greet the user", hidden: true });- await create("overheard", { text: "Ambient chatter", overheard: true });- await create("channel", { text: "Hello" }, "channel");- await create("other", { text: "Hello" }, "dm", scopeId("personal", `${prefix}-other`));- for (const origin of ["cron", "webhook", "monitor"])- await create(origin, { text: "Hello" }, "dm", scope, `agent:main:${origin}:${prefix}`);- const child = await create("child", { text: "Delegated work" });- await store.setParentSession(child.id, "parent");- const fork = await create("fork", { text: "Copied user request" });- await store.updateForkProvenance(fork.id, { forkedFrom: { sessionId: "source" }, forkBoundarySeq: 0 });- assert.equal(await store.countPersonalConversations(scope), 0);- const archived = await create("archived", { text: "Hello" });- await store.addParticipant(archived.id, prefix);- await store.updateParticipantView(archived.id, prefix, { archived: true });- assert.equal(await store.countPersonalConversations(scope), 1);- const { lease } = await store.acquireLease(fork.id);- assert.ok(lease);- await store.append(lease, { type: "user", payload: { text: "A new request" }, scopeLabel: scope });- await store.append(lease, { type: "user", payload: { text: "Another turn" }, scopeLabel: scope });- await store.releaseLease(lease);- assert.equal(await store.countPersonalConversations(scope), 2);- const canonical = await create("canonical", { text: "Synthetic", hidden: true });- const canonicalLease = (await store.acquireLease(canonical.id)).lease;- assert.ok(canonicalLease);- const [original] = await store.getEntries(canonical.id);- assert.ok(original);- await store.appendTape(canonicalLease, tapeTranscriptEntryRecord({ ...original, payload: { text: "Real request" } }));- await store.releaseLease(canonicalLease);- assert.equal(await store.countPersonalConversations(scope), 3);- await create("fourth", { text: "Hello\u0000", hidden: "true", overheard: "true" });- assert.equal(await store.countPersonalConversations(scope), 3);- assert.equal(await store.countPersonalConversations(scope, 4), 4);- assert.equal(await store.countPersonalConversations(scope, 1), 1);- assert.equal(await store.countPersonalConversations(scope, 0), 0);-}diff --git a/test/system-prompt-order.test.ts b/test/system-prompt-order.test.tsindex 0b7b6ac3f..7448210a4 100644--- a/test/system-prompt-order.test.ts+++ b/test/system-prompt-order.test.ts@@ -417,7 +417,7 @@ test("Open keeps unclassified personal memory out of rooms, loads room memory in}),);assert.match(dmPrompt.reply ?? "", /### channel:C1[\s\S]*ROOM_ONLY_MEMORY/);- assert.match(dmPrompt.reply ?? "", /included, authorized memories/);+ assert.match(dmPrompt.reply ?? "", /use these authorized memories freely/);assert.doesNotMatch(dmPrompt.reply ?? "", /apply it only if that tag matches here/);member = false;@@ -1134,7 +1134,7 @@ for (const surfaceTools of [false, true]) {await orchestrator.handleTurn({ ...input, text: "third" });assert.doesNotMatch(seen[2]!.environment!, /ALPHA_MARKER/);assert.match(seen[2]!.environment!, /GAMMA_MARKER/);- assert.match(seen[2]!.environment!, /withdrawn[\s\S]*BETA_MARKER/);+ assert.match(seen[2]!.environment!, /personal:U1: 1 earlier fact was consolidated or removed/);const entries = await sessions.getEntries(first.sessionId!);const users = entries.filter((entry) => entry.type === "user");assert.match(JSON.stringify(users[0]!.payload), /memoryRecall/);