From 36ec0ed93bd531ef83f92404b86577497a12ab0b Mon Sep 17 00:00:00 2001 From: GLDRoger <130458023+GLDRoger@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:43:26 +0530 Subject: [PATCH 1/2] test(kin): rule saves and refused pushes keep each owner chat's thread, and the lead memory test waits for publication The journal-push race test gains an editor-save case. After the owner saves new standing rules, the direct chat and a private group each continue their own owner-chat thread and session, and each turn carries the rule-change note with the new rules in full. The race cases now also assert that a wake completing after a refused push stays on its chat's owner-chat thread and that the next wake continues it. The lead memory test read a wake's commit from the remote as soon as commitWakeup returned. The rules editor's step moved publication to the lander, so the test now waits for the lander's settled signal until the remote has each commit it reads. The reply, people and discussion models are re-confirmed for the joined line. People-change: none Co-Authored-By: Claude Opus 5.5 --- apps/server/src/kin/lead/LeadMemory.test.ts | 27 +++++++ apps/server/src/kin/lead/WakeupRunner.test.ts | 77 +++++++++++++++++-- verification/kin/discussion/README.md | 2 + verification/kin/people/README.md | 2 + verification/kin/reply/README.md | 2 + 5 files changed, 103 insertions(+), 7 deletions(-) diff --git a/apps/server/src/kin/lead/LeadMemory.test.ts b/apps/server/src/kin/lead/LeadMemory.test.ts index 400028ce073c..6093f0911cff 100644 --- a/apps/server/src/kin/lead/LeadMemory.test.ts +++ b/apps/server/src/kin/lead/LeadMemory.test.ts @@ -24,6 +24,7 @@ import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; +import * as Queue from "effect/Queue"; import * as Schema from "effect/Schema"; import * as SqlClient from "effect/sql/SqlClient"; import { McpSchema, McpServer } from "effect/ai"; @@ -45,6 +46,7 @@ import * as Memory from "../memory/Memory.ts"; import { parseFrontMatter } from "../memory/frontMatter.ts"; import * as Cache from "../memory/MemoryCache.ts"; import { MemoryConfig } from "../memory/MemoryConfig.ts"; +import { MemoryLanderHooks } from "../memory/MemoryLander.ts"; import * as Writer from "../memory/MemoryWriter.ts"; import * as Scan from "../memory/secretScan.ts"; import { authorise, fingerprint, storedLabels, visibility } from "../memory/sensitivity.ts"; @@ -436,7 +438,27 @@ it.live( }); }), ).pipe(Layer.provideMerge(memoryLayer)); + // A wake's commit reaches the remote from the lander, after commitWakeup returns. + const landings = yield* Queue.unbounded(); + const published = Effect.fn("LeadMemoryTest.published")(function* (commit: string) { + const present = vcs + .run({ + operation: "test.lead", + command: "git", + cwd: remote, + args: [`--git-dir=${remote}`, "cat-file", "-e", `${commit}^{commit}`], + allowNonZeroExit: true, + }) + .pipe(Effect.map((r) => r.exitCode === 0)); + while (!(yield* present)) yield* Queue.take(landings); + return commit; + }); const writer = Writer.layer.pipe( + Layer.provide( + Layer.succeed(MemoryLanderHooks, { + settled: () => Queue.offer(landings, undefined).pipe(Effect.asVoid), + }), + ), Layer.provideMerge(Lead.authority), Layer.provide(Cache.layer), Layer.provide(Scan.layer), @@ -1419,6 +1441,7 @@ it.live( "fixture-wakeup", "completed", ); + yield* published(committed.commit); const closed = yield* git(remote, ["show", `${committed.commit}:deferrals/close-me.md`]); assert.include(closed, "status: done"); assert.include(closed, "source_event: original-event"); @@ -1540,6 +1563,7 @@ it.live( yield* sql`INSERT INTO kin_lead_tool_calls (org_id, wakeup_id, call_key, request_hash) VALUES (${orgId}, 'restart-wakeup', 'end', 'fixture-hash')`; yield* writerService.discard(orgId, "restart-wakeup"); const recovered = yield* writerService.commitWakeup(orgId, "restart-wakeup", "failed"); + yield* published(recovered.commit); assert.notInclude( yield* git(remote, ["ls-tree", "-r", "--name-only", recovered.commit]), "lost-claim", @@ -1604,6 +1628,7 @@ it.live( onDue: "remind", }); const shadowCommit = yield* writerService.commitWakeup(orgId, "shadow-wakeup", "completed"); + yield* published(shadowCommit.commit); const shadow = `kin/shadow/${agentId}`; assert.strictEqual(yield* git(remote, ["rev-parse", shadow]), shadowCommit.commit); assert.notInclude( @@ -1754,6 +1779,7 @@ it.live( assert.deepStrictEqual(kept, [{ state: runState }]); } const cancelCommit = yield* writerService.commitWakeup(orgId, "cancel-wakeup", "completed"); + yield* published(cancelCommit.commit); assert.include( yield* git(remote, ["show", `${cancelCommit.commit}:deferrals/${reminder.itemId}.md`]), "status: cancelled", @@ -1907,6 +1933,7 @@ it.live( yield* service.journal(scope, { saw: ["Invented teammate request"], did: [] }); assert.isTrue(yield* writerService.staged(orgId, "team-wakeup")); const teamCommit = yield* writerService.commitWakeup(orgId, "team-wakeup", "completed"); + yield* published(teamCommit.commit); const kept = yield* git(remote, ["show", `${teamCommit.commit}:claims/member-claim.md`]); for (const line of [ "sensitive: false", diff --git a/apps/server/src/kin/lead/WakeupRunner.test.ts b/apps/server/src/kin/lead/WakeupRunner.test.ts index ecd22f6722a0..86b02514186f 100644 --- a/apps/server/src/kin/lead/WakeupRunner.test.ts +++ b/apps/server/src/kin/lead/WakeupRunner.test.ts @@ -73,6 +73,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; import * as Budget from "./KinBudget.ts"; import * as KinIdentity from "../chat/KinIdentity.ts"; import * as Writer from "../memory/MemoryWriter.ts"; +import { OWNER_CHAT_THREAD_PREFIX } from "./sessionAudience.ts"; import * as Memory from "../memory/Memory.ts"; import { MemoryLanderHooks } from "../memory/MemoryLander.ts"; import * as SecretScan from "../memory/secretScan.ts"; @@ -2577,8 +2578,8 @@ describe("WakeupRunner", () => { }, ); - it.live.each(["disjoint", "conflicting"] as const)( - "a %s journal push race completes the wake and keeps the session", + it.live.each(["disjoint", "conflicting", "editor save"] as const)( + "%s: the wake completes and keeps the session (a journal push race, or a save in the editor)", (race) => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; @@ -2607,11 +2608,15 @@ describe("WakeupRunner", () => { yield* git(source, ["add", "--", "rules.md", journal]); yield* git(source, [...commit, "Initial memory"]); yield* git(root, ["clone", "--bare", "--", source, remote]); + // An editor save has no outside push; its rules change goes through saveRulesBook. + const editor = race === "editor save"; const outside = race === "disjoint" ? "rules.md" : journal; - yield* fs.writeFileString(`${source}/${outside}`, "Use the violet ledger.\n"); - yield* git(source, [...commit, "Outside edit"]); + if (!editor) { + yield* fs.writeFileString(`${source}/${outside}`, "Use the violet ledger.\n"); + yield* git(source, [...commit, "Outside edit"]); + } const outsidePush = git(source, ["push", "--", remote, "main"]); - let raced = false; + let raced = editor; const intercepted = Layer.succeed(VcsProcess.VcsProcess, { run: Effect.fn("WakeupTest.remoteRace")(function* (input: VcsProcess.VcsProcessInput) { if ( @@ -2640,8 +2645,14 @@ describe("WakeupRunner", () => { }); const memoryLayer = Memory.layer.pipe(Layer.provide(recovery)); let memory: Memory.Memory["Service"] | undefined; + let saver: Writer.MemoryWriter["Service"] | undefined; let rules = ""; const writer = Writer.layer.pipe( + Layer.tap((context) => + Effect.sync(() => { + saver = Context.get(context, Writer.MemoryWriter); + }), + ), Layer.provide(Layer.succeed(Writer.MemoryWriterHooks, { notify: () => Effect.void })), Layer.provide( Layer.succeed(MemoryLanderHooks, { @@ -2680,7 +2691,53 @@ describe("WakeupRunner", () => { ); const reads: string[] = []; yield* Effect.gen(function* () { - yield* seedCarry; + const sql = yield* seedCarry; + if (editor) { + // The owner saves in the editor; the direct chat and a private group each continue. + yield* sql`INSERT INTO kin_chats (chat_id, org_id, kind, title, last_seq, created_at) + VALUES ('private', ${orgId}, 'team_group', 'Dispatch', 0, '2026-11-26')`; + for (const chat of ["direct", "private"]) { + yield* wake(`fixture-editor-${chat}-first`, chat); + yield* Queue.take(outcomes); + } + const book = yield* saver!.readRulesBook(orgId); + yield* saver!.saveRulesBook( + { orgId, revision: book.revision, text: "Use the editor's ledger." }, + Effect.succeed("Rhea"), + ); + for (const chat of ["direct", "private"]) { + yield* wake(`fixture-editor-${chat}-second`, chat); + yield* Queue.take(outcomes); + } + const rows = yield* carryRows; + assert.lengthOf(rows, 4); + for (const [first, second] of [ + [rows[0]!, rows[2]!], + [rows[1]!, rows[3]!], + ]) + assert.deepInclude(second, { + threadId: first.threadId, + status: "completed", + sent: "carried", + reason: null, + }); + assert.notStrictEqual(rows[0]!.threadId, rows[1]!.threadId); + for (const row of rows) + assert.isTrue(row.threadId.startsWith(OWNER_CHAT_THREAD_PREFIX)); + assert.lengthOf(reads, 2); + for (const note of reads) { + assert.match( + note, + /^# Standing rules changed since your previous turn\n\nThe owner's standing rules changed at /m, + ); + assert.include( + note, + `They are now, in full: "Use the editor's ledger." This replaces`, + ); + assert.notInclude(note, "Use the first ledger."); + } + return; + } yield* wake("fixture-race-first"); yield* Queue.take(outcomes); const [first] = yield* carryRows; @@ -2696,7 +2753,13 @@ describe("WakeupRunner", () => { } yield* wake("fixture-race-second"); yield* Queue.take(outcomes); - assert.include((yield* carryRows).at(-1), { status: "completed", sent: "carried" }); + // The completed wake stays on its own chat's owner-chat thread, and the next one continues it. + assert.isTrue(first!.threadId.startsWith(OWNER_CHAT_THREAD_PREFIX)); + assert.include((yield* carryRows).at(-1), { + threadId: first!.threadId, + status: "completed", + sent: "carried", + }); assert.deepStrictEqual(yield* sessions(), [1, 1]); if (race === "disjoint") assert.include(reads[0], "Use the violet ledger."); else assert.lengthOf(notices, 1); diff --git a/verification/kin/discussion/README.md b/verification/kin/discussion/README.md index 76f2804531d2..37eb57d548b3 100644 --- a/verification/kin/discussion/README.md +++ b/verification/kin/discussion/README.md @@ -115,3 +115,5 @@ On 2026-11-26, against `feat/kin-session-changes` (`fc8c965117c`, on kin `4df1cc **Re-confirmed 2026-11-29** on train 17 of 29 Nov (the schedule guard after an outside read, carry on by default with one 49-minute lifetime, and the reply model's session check, three steps joined on kin `7e273b01f3b`; no spec change, all 13 rules hold over 44,410 states in 33 s; 16/16 variants caught in 24 s). The one covered file the line changes, `lead/WakeupRunner.ts`, loses the cost gate's pricing call and stamps an approved draft on the wake. Carry stays on the owner-only Claude path, so a Team-room turn still starts fresh and inherits no session marks. **Re-confirmed 2026-11-29** on train 18 of 29 Nov (every cache lever, eight rows joined on kin `de2553ba2c6`; no spec change, all 13 rules hold over 44,410 states in 33 s; 16/16 variants caught in 24 s). The one covered file the line changes, `lead/WakeupRunner.ts`, gains the per-chat stored session, notes instead of resets and Kin's compaction. A confined room or teammate chat may now keep its own session only while its audience and briefing stay the same (J3c). Caps, objections, pitches and telling are unchanged. + +**Re-confirmed 2026-11-29** on train 19 of 29 Nov (owner chats, the rules editor and the turn-start memory check, its screens, and keep-warm from day one, four steps joined on kin `3c0ea045dde`; no spec change, all 13 rules hold over 44,410 states in 35 s; 16/16 variants caught in 24 s). The covered files the line changes are `team/KinTeam.ts`, `chat/KinChatService.ts`, `chat/KinGroups.ts` and `lead/WakeupRunner.ts`. The owner-alone Team room gets its own owner-chat thread, and it ends, with its running turn stopped, when a person joins. Caps, objections, pitches and telling are unchanged. diff --git a/verification/kin/people/README.md b/verification/kin/people/README.md index c59f70ee7508..4106c0100875 100644 --- a/verification/kin/people/README.md +++ b/verification/kin/people/README.md @@ -60,3 +60,5 @@ On 2026-11-26, against the visibility-rule fix (#906, kin `6c18694fa04`; every r **Re-confirmed 2026-11-28** on the phone-look server fixes (`816e8c9011c`; no spec change, all 9 rules hold over 6,243 states in 1 s; 10/10 variants caught in 8 s). `ChatSharing` keeps pre-share reminder wording on the original history-fenced card. A joiner receives a system line with the asker's name and status, not the card or its wording. This changes neither membership nor any owner-level grant. **Re-confirmed 2026-11-28** on train 15 (the phone fix, bills round 2 and the phone look's fixes, seven steps joined on kin `19fff00b325`; no spec change, all 9 rules hold over 6,243 states; 10/10 variants caught). The one covered file, `lead/ChatSharing.ts`, differs from kin only by the phone-look server fixes (step 6, above): the original reminder card stays behind the first join's history floor and joiners get a status line. Levels, removal and links are unchanged. + +**Re-confirmed 2026-11-29** on train 19 of 29 Nov (owner chats, the rules editor and the turn-start memory check, its screens, and keep-warm from day one, four steps joined on kin `3c0ea045dde`; no spec change, all 9 rules hold over 6,243 states in 1 s; 10/10 variants caught in 7 s). The covered files the line changes, `people/KinPeople.ts`, `lead/Audience.ts` and `lead/ChatSharing.ts`, end a chat's owner-chat thread and stop its running private turn when a person joins the chat or is brought back to it. Levels, removal, links and who may bring someone back are unchanged. diff --git a/verification/kin/reply/README.md b/verification/kin/reply/README.md index 2f9c681c7728..8a7571147245 100644 --- a/verification/kin/reply/README.md +++ b/verification/kin/reply/README.md @@ -182,3 +182,5 @@ TLC 1.7.4, one worker per run; wall times reflect concurrent checks on the same **Checked 2026-11-29** for train 19 A: all 18 rules hold over 1,794,442 distinct states (674,893 ms), and 43/43 mutations are caught (69,955 ms). `owner-join-retains-private` is the entitlement catch: Ben gains Rhea’s earlier private words. `owner-cross-chat` and `owner-reuse-mixed` instead pin the per-chat design and the exclusion of mixed text; Rhea is still the only reader in both traces. **Re-checked 2026-11-29** for the train 19 A fix round: all 18 rules hold over 1,794,442 distinct states (658,714 ms); 44/44 mutations are caught (75,550 ms). The new `return-without-abort` variant gives the private group’s former reader access while a carried turn is in flight. The model records disclosure at completion: Ben would receive an answer containing retained text he was not entitled to. The sound return interrupts that turn, using the same transition as a join. + +**Re-confirmed 2026-11-29** on train 19 of 29 Nov (each owner chat keeps its own session, the owner's rules editor with the turn-start memory check, the rules screens, and keep-warm from day one, four steps joined on kin `3c0ea045dde`; no spec change, all 18 rules hold over 1,794,442 distinct states in 695 s; 44/44 variants caught in 77 s). The covered files the line changes are `lead/WakeupRunner.ts`, `lead/ChatSharing.ts`, `lead/Audience.ts`, `lead/sessionCarry.ts`, `chat/KinGroups.ts` and `people/KinPeople.ts`. They give each owner-only chat its own thread, which continues only while its readers stay the same. A mixed wake runs on a one-shot thread and is never stored. A join or a return stops the private turn. The rules editor's save and a refused journal push change only which rules revision a turn reads, and whether a finished turn counts as completed. From ca618d7e74ce04d6986401364cb8256eb74ae29b Mon Sep 17 00:00:00 2001 From: GLDRoger <130458023+GLDRoger@users.noreply.github.com> Date: Mon, 30 Nov 2026 00:48:26 +0530 Subject: [PATCH 2/2] test(kin): the editor-save case indexes its rows so the server typecheck passes People-change: none Co-Authored-By: Claude Opus 5.5 --- apps/server/src/kin/lead/WakeupRunner.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/server/src/kin/lead/WakeupRunner.test.ts b/apps/server/src/kin/lead/WakeupRunner.test.ts index 86b02514186f..4f43141b026d 100644 --- a/apps/server/src/kin/lead/WakeupRunner.test.ts +++ b/apps/server/src/kin/lead/WakeupRunner.test.ts @@ -2712,11 +2712,11 @@ describe("WakeupRunner", () => { const rows = yield* carryRows; assert.lengthOf(rows, 4); for (const [first, second] of [ - [rows[0]!, rows[2]!], - [rows[1]!, rows[3]!], - ]) - assert.deepInclude(second, { - threadId: first.threadId, + [0, 2], + [1, 3], + ] as const) + assert.deepInclude(rows[second], { + threadId: rows[first]!.threadId, status: "completed", sent: "carried", reason: null,