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
2 changes: 1 addition & 1 deletion apps/server/src/kin/lead/WakeupRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
Expand Down
9 changes: 1 addition & 8 deletions apps/server/src/kin/lead/WakeupRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down
45 changes: 37 additions & 8 deletions apps/server/src/kin/lead/turn/providers/claude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions apps/server/src/kin/lead/turn/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,26 @@ export interface KinProvider<Seam> {
readonly capabilities: Partial<Readonly<Record<KinCapability, ReadonlyArray<string>>>>;
readonly install: <E, R>(base: Layer.Layer<Seam, E, R>) => Layer.Layer<Seam, unknown, unknown>;
}

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;
}
};
2 changes: 2 additions & 0 deletions verification/kin/discussion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions verification/kin/money/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions verification/kin/reply/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions verification/kin/tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading