diff --git a/apps/server/src/kin/lead/WakeupRunner.test.ts b/apps/server/src/kin/lead/WakeupRunner.test.ts index 48223275109a..d6095d16d37b 100644 --- a/apps/server/src/kin/lead/WakeupRunner.test.ts +++ b/apps/server/src/kin/lead/WakeupRunner.test.ts @@ -464,7 +464,7 @@ type CacheWeights = { write1h: number; output: number; }; -// The shape `provider.ts` exports on `fix/kin-cache-instructions-boundary`, the change this one joins after. +// The shape `cacheWeights` in `provider.ts` returns. const pricing = vi.hoisted(() => ({ cacheWeights: (_driver: string, _model: string): CacheWeights | undefined => undefined, })); diff --git a/apps/server/src/kin/lead/WakeupRunner.ts b/apps/server/src/kin/lead/WakeupRunner.ts index 113f9987961d..6a7dedbc9a29 100644 --- a/apps/server/src/kin/lead/WakeupRunner.ts +++ b/apps/server/src/kin/lead/WakeupRunner.ts @@ -236,13 +236,6 @@ const decodeRunning = Schema.decodeUnknownEffect(RunningRow); const decodeTaskIds = Schema.decodeUnknownOption( Schema.fromJsonString(Schema.Array(Schema.String)), ); -// `cacheWeights` arrives with the instructions-boundary change; until then no turn is priced. -const pricing: typeof cachePricing & { - readonly cacheWeights?: ( - driver: string, - model: string, - ) => { readonly read: number; readonly write1h: number; readonly output: number } | undefined; -} = cachePricing; const make = Effect.gen(function* () { const boot = yield* Effect.serviceOption(KinBoot); @@ -2387,7 +2380,7 @@ const make = Effect.gen(function* () { const send = yield* Effect.gen(function* () { const toolListSha = agentSessions?.lastToolList(threadId) ?? null; const weights = ownerClaude - ? pricing.cacheWeights?.(claude.driver, modelSelection.model) + ? cachePricing.cacheWeights(claude.driver, modelSelection.model) : undefined; // The owner seat writes its prompt cache for an hour. const cacheWeights = diff --git a/apps/server/src/kin/lead/turn/providers/claude.test.ts b/apps/server/src/kin/lead/turn/providers/claude.test.ts index ee4f6a28fd19..ee2eccdb376e 100644 --- a/apps/server/src/kin/lead/turn/providers/claude.test.ts +++ b/apps/server/src/kin/lead/turn/providers/claude.test.ts @@ -31,6 +31,7 @@ import { OWNER_SEAT_NO_SUBAGENTS, OWNER_SEAT_OFF, } from "./claude.ts"; +import { cacheWeights } from "./provider.ts"; import { captureClaudeOptions } from "./claude.testkit.ts"; import { BILLS_SEAT_INSTRUCTIONS, kinInstructions, REVIEW_SEAT_INSTRUCTIONS } from "../session.ts"; import { KinSessionContext } from "../sessionContext.ts"; @@ -238,6 +239,23 @@ it.effect("every seat's options match Kin byte for byte", () => ), ); +it("weights only priced Claude models, in units of plain input", () => { + const haiku = { input: 1, read: 0.1, write5m: 1.25, write1h: 2, output: 5 }; + const high = { ...haiku, read: 0.05 }; + for (const [driver, model, expected] of [ + ["claudeAgent", "claude-haiku-5-5", haiku], + ["claudeAgent", "claude-opus-5-5", high], + ["claudeAgent", "claude-sonnet-5-5", high], + ["claudeAgent", "claude-sonnet-4-6", undefined], + ["claudeAgent", "claude-haiku-5-5-custom", undefined], + ["codex", "claude-haiku-5-5", undefined], + ["acpRegistry", "claude-haiku-5-5", undefined], + ["unknown", "claude-haiku-5-5", undefined], + ] as const) { + expect(cacheWeights(driver, model), `${driver}/${model}`).toEqual(expected); + } +}); + it.effect("an enabled owner seat without KinSessionContext logs one error and still opens", () => { const errors: string[] = []; return withPreparedContext( @@ -664,6 +682,25 @@ it.effect( assert.notProperty(full, "maxTurns"); const { hooks: fullHooks, env: fullEnv, settings: fullSettings, ...fullRequest } = full; const { env: _env, settings: leadSettings, ...leadRequest } = lead; + assert.deepStrictEqual( + yield* Effect.forEach( + [ + ["kin:tech", undefined], + ["kin:tech", "5m"], + ["kin-shared:tech", undefined], + ["kin-shared:tech", "5m"], + ["kin-shared:bills:tech", undefined], + ["kin-shared:review:tech", undefined], + ["kin-shared:triage:tech", undefined], + ] as const, + ([thread, override]) => + open(thread, { + ...lead, + env: { ...lead.env, CLAUDE_CODE_PROMPT_CACHE_TTL: override }, + }).pipe(Effect.map((options) => options?.env?.CLAUDE_CODE_PROMPT_CACHE_TTL)), + ), + ["1h", "5m", undefined, "5m", undefined, undefined, undefined], + ); assert.deepStrictEqual(fullRequest, { ...leadRequest, systemPrompt: { @@ -701,14 +738,6 @@ it.effect( idleCompaction: false, ...dietSettings, }); - const preconfigured = yield* open("kin:tech", { - ...lead, - env: { ...lead.env, CLAUDE_CODE_PROMPT_CACHE_TTL: "5m" }, - }); - assert.deepStrictEqual(preconfigured?.env, { - ...fullEnv, - CLAUDE_CODE_PROMPT_CACHE_TTL: "5m", - }); assert.sameMembers(Object.keys(fullHooks ?? {}), [ "PreToolUse", "SessionStart", diff --git a/apps/server/src/kin/lead/turn/providers/provider.ts b/apps/server/src/kin/lead/turn/providers/provider.ts index 74a099b0fea9..60368ff170f0 100644 --- a/apps/server/src/kin/lead/turn/providers/provider.ts +++ b/apps/server/src/kin/lead/turn/providers/provider.ts @@ -16,3 +16,26 @@ export interface KinProvider { readonly capabilities: Partial>>>; readonly install: (base: Layer.Layer) => Layer.Layer; } + +const claudeOpusAndSonnetWeights = { + input: 1, + read: 0.05, + write5m: 1.25, + write1h: 2, + output: 5, +} as const; +const claudeHaikuWeights = { ...claudeOpusAndSonnetWeights, read: 0.1 } as const; + +/** Relative token prices in units of plain input. Unpriced models have no cost comparison. */ +export const cacheWeights = (driver: string, model: string) => { + if (driver !== "claudeAgent") return undefined; + switch (model) { + case "claude-opus-5-5": + case "claude-sonnet-5-5": + return claudeOpusAndSonnetWeights; + case "claude-haiku-5-5": + return claudeHaikuWeights; + default: + return undefined; + } +}; diff --git a/verification/kin/discussion/README.md b/verification/kin/discussion/README.md index e67761ffaf86..eee7a1db11d6 100644 --- a/verification/kin/discussion/README.md +++ b/verification/kin/discussion/README.md @@ -107,3 +107,5 @@ On 2026-11-26, against `feat/kin-session-changes` (`fc8c965117c`, on kin `4df1cc **Re-confirmed 2026-11-28** on train 16 (the last Finance train, five steps joined on kin `db4a66e447d`; no spec change, all 13 rules hold over 44,410 states in 31 s; 16/16 variants caught in 25 s). The one covered file the line changes, `chat/KinChatService.ts`, differs from kin only by the money-in check (step 3): the bank-check card joins the types a generic widget upsert refuses. No discussion, ask, hand-off, room or check-in changes. **Re-confirmed 2026-11-29** for the session carry clocks and cost gate (base `bc0259ac6be`; no spec change; all 13 rules hold over 44,410 states, 16/16 broken variants caught). `WakeupRunner` changes how it ages and prices an owner-only session, not who can join or speak, which thread a turn uses, what the Team room can read, or how `finishWakeup`, `wakeupEnded` and `reportBack` settle a turn. A Team-room turn still starts fresh and inherits no session marks. + +**Re-confirmed 2026-11-29** on train 16 of 29 Nov (the cache fixes and the Finance follow-through, five steps joined on kin `bc0259ac6be`; no spec change, all 13 rules hold over 44,410 states in 34 s; 16/16 variants caught in 23 s). The one covered file the line changes, `lead/WakeupRunner.ts`, differs from kin only by the carry clocks and cost gate (the line above), which now price with the turn provider's real `cacheWeights(driver, model)` table, so the shim that waited for it is gone. Pricing is asked only on the owner-only Claude path; a Team-room turn still starts fresh and inherits no session marks. diff --git a/verification/kin/money/README.md b/verification/kin/money/README.md index d73c1cc24da1..c314c417e649 100644 --- a/verification/kin/money/README.md +++ b/verification/kin/money/README.md @@ -64,3 +64,5 @@ On 2026-11-27, against `feat/kin-credit-which-invoice` at `f79f03f9280` (the rev **Re-confirmed 2026-11-28** on `feat/kin-money-in-check` after its independent review, joined on kin `1fadc6799d1` (no spec change, all 7 rules hold over 934,934 states in 17 s; 9/9 variants caught in 6 s). The one covered file the branch changes, `statementReview.ts`, is as its line above says: `recordedPayments` leaves out a payment a confirmed statement linked (`prior.matched`), and the shared read uses `countedPayment`. The review's fixes touch only the read-only check (`moneyInCheck.ts`), its tool words and Finance's sentence: no Confirm, receipt, payment or statement row changes. **Re-confirmed 2026-11-28** on train 16 (the last Finance train, five steps joined on kin `db4a66e447d`: chat photo copies, the bills card screens, the money-in check, bills read many at once and bills fixed by talking; no spec change, all 7 rules hold over 934,934 states in 16 s; 9/9 variants caught in 8 s). The one covered file the line changes, `work/statements/statementReview.ts`, differs from kin only by the money-in check (step 3, as its lines above say): `recordedPayments` leaves out a payment a confirmed statement linked, and the shared read uses `countedPayment`. Outside the covered files, the join's fix in `work/bills.ts` gives Fix and keep's expense its own record when a chat correction had withdrawn the bill's suggestion; it is still kept through the existing `confirm` path. No receipt, payment or statement rule changes. + +**Re-confirmed 2026-11-29** on train 16 of 29 Nov (the cache fixes and the Finance follow-through, five steps joined on kin `bc0259ac6be`; no spec change, all 7 rules hold over 934,934 states in 15 s; 9/9 variants caught in 7 s). The line changes no covered file. `work/bills.ts`, named above, now reads a printed mark such as "Rs." in the company's own currency when it fits, carries an upload's "reimburse me" as an amount owed (never repaid), and reads a wrongly cut photo again as one bill, refused when a piece is kept. Every keep is still the owner's or a co-owner's tap through `keepRead`, `keepEntered` or `confirm`. The money-in check card is drawn on web and phone with no server change, and no receipt, payment or statement rule changes. diff --git a/verification/kin/reply/README.md b/verification/kin/reply/README.md index 7b349eace251..564145388b7d 100644 --- a/verification/kin/reply/README.md +++ b/verification/kin/reply/README.md @@ -116,3 +116,5 @@ The guard "Steer waits after a Stop" (rule 12) now rests on code, from kin's `15 **Re-confirmed 2026-11-28** on train 16 (the last Finance train, five steps joined on kin `db4a66e447d`; no spec change, all 17 rules hold over 1,554,826 states in 422 s; 28/28 variants caught in 40 s). The one covered file the line changes, `reply/classify.ts`, differs from kin only by bills fixed by talking (step 5, as its line above says): working-line labels for `bills_list`, `bill_set` and `bill_recut`. Every message still ends in a reply, a plain failure line or the person's own Stop. **Re-confirmed 2026-11-29** for the session carry clocks and cost gate (base `bc0259ac6be`; no spec change; all 17 rules hold over 1,554,826 states, 28/28 broken variants caught). `WakeupRunner` uses the previous provider completion to age a session and can start a fresh provider context when carry costs more. It still takes the same claim, audience, delivery, rescue, requeue and Stop paths; the extra wake-up stamp fields do not feed those paths. + +**Re-confirmed 2026-11-29** on train 16 of 29 Nov (the cache fixes and the Finance follow-through, five steps joined on kin `bc0259ac6be`; no spec change, all 17 rules hold over 1,554,826 states in 649 s; 28/28 variants caught in 46 s). The one covered file the line changes, `lead/WakeupRunner.ts`, differs from kin only by the carry clocks and cost gate (the line above), which now price with the turn provider's real `cacheWeights(driver, model)` table, so the shim that waited for it is gone. A carried session that costs more only starts fresh; it takes the same claim, audience, delivery, rescue, requeue and Stop paths. diff --git a/verification/kin/tasks/README.md b/verification/kin/tasks/README.md index f84ff7aca258..361f7afdbd8b 100644 --- a/verification/kin/tasks/README.md +++ b/verification/kin/tasks/README.md @@ -65,3 +65,5 @@ On 2026-11-27, against the advertised record-writer core (`perf/kin-advertised-c **Re-confirmed 2026-11-28** for the bills chat card (train 13 base `5ec5553ef2b`; all 10 rules hold over 244,584 states; 12/12 variants caught). `KinRecords.update` refreshes only an expense's bill-batch card. Task authority, assignment, hand-back and notices are unchanged. **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 10 rules hold over 244,584 states; 12/12 variants caught). `work/KinRecords.ts` differs from kin only by the bills chat card's refresh in `update` (step 2, above); the other steps touch no covered file. Task authority, assignment, hand-back and notices are unchanged. + +**Re-confirmed 2026-11-29** on train 16 of 29 Nov (the cache fixes and the Finance follow-through, five steps joined on kin `bc0259ac6be`; no spec change, all 10 rules hold over 244,584 states in 7 s; 12/12 variants caught in 9 s). The line changes no covered file. `LeadPrompt.ts`, named above, now leaves the memory index's leading "As of" line out of a carried session's change list and fingerprint only; fresh prompts still show it. Task authority, assignment, hand-back and notices are unchanged.