Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d499cb1
chore(kin): merge reviewed change-note wording
GLDRoger Nov 29, 2026
1de9267
fix(kin): carry sessions through company data edits
GLDRoger Nov 29, 2026
0b81ed0
chore(kin): record the reviewed eval runner boundary
GLDRoger Nov 29, 2026
b3dc47f
chore(kin): merge reviewed cache upkeep
GLDRoger Nov 29, 2026
91d59fa
chore(kin): merge protocol-neutral cache upkeep
GLDRoger Nov 29, 2026
b3e2dcc
test(kin): a standing part besides the rules still starts fresh
GLDRoger Nov 29, 2026
a5e01eb
fix(kin): end a carried session when a standing part besides the rule…
GLDRoger Nov 29, 2026
54ace52
test(kin): a rule note names no git author, and a long rulebook edit …
GLDRoger Nov 29, 2026
0e63bda
chore(kin): merge reviewed instruction-block attachment guard
GLDRoger Nov 29, 2026
726b3db
fix(kin): a rule note names no git author and carries a rulebook of a…
GLDRoger Nov 29, 2026
7513821
test(kin): a rule note past the hook's bound arrives in the message, …
GLDRoger Nov 29, 2026
fb50204
feat(kin): keep owner chat sessions across restarts and long gaps
GLDRoger Nov 29, 2026
c53df75
fix(kin): merge reviewed session carry safeguards
GLDRoger Nov 29, 2026
4fb98e8
fix(kin): preserve the missed carry-hook diagnosis
GLDRoger Nov 29, 2026
630ea8d
test(kin): pin two J3b carry faults the review found
GLDRoger Nov 29, 2026
e91ad99
fix(kin): size cold sessions from the shared part and keep summary marks
GLDRoger Nov 29, 2026
c010fa3
revert(kin): keep the builder's cold-size base; state its arithmetic
GLDRoger Nov 29, 2026
eda4f7a
feat(kin): carry sessions for confined chats
GLDRoger Nov 29, 2026
1946ccb
fix(kin): merge the J3b session review
GLDRoger Nov 29, 2026
a9df5b3
fix(kin): measure cold carry from the first request
GLDRoger Nov 29, 2026
9dd85db
fix(kin): reset confined sessions after native compaction
GLDRoger Nov 29, 2026
8dcddbc
merge: one stored session per chat that survives restarts and long ga…
GLDRoger Nov 29, 2026
7ac1d45
chore(kin): join this step onto kin as the checked train holds it
GLDRoger Nov 29, 2026
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
1 change: 1 addition & 0 deletions apps/server/src/kin/chat/clearedChatPrompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const memory = Layer.succeed(
historyGeneration: () => Effect.die("Unused"),
items: () => Effect.die("Unused"),
snapshotItems: () => Effect.die("Unused"),
standingChange: () => Effect.die("Unused"),
readPromptSnapshot: () =>
Effect.succeed({
rules: "Invented rules",
Expand Down
8 changes: 5 additions & 3 deletions apps/server/src/kin/chat/ownMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { KinEventQueue } from "../lead/KinEventQueue.ts";
import { KinChatHub } from "./KinChatHub.ts";
import { isContinuation, KinChatRepository, replyGroupKey } from "./KinChatRepository.ts";
import { encodeNames, nameKeys, nameThreads } from "./messageLinks.ts";
import { historyFloor } from "./sharing.ts";
import { historyFloor, visibleToPeople } from "./sharing.ts";

/** Unread messages of its own an agent's turn lists, newest first; older ones are counted. */
export const OWN_UNREAD_SHOWN = 20;
Expand Down Expand Up @@ -62,9 +62,11 @@ export const amendable = (sql: SqlClient.SqlClient) => sql`m.author_kind = 'agen
AND m.status = 'posted' AND m.silent = 0 AND m.kind = 'text' AND ${wordsOnly(sql)}
AND ${onlyOwnOpenQuestion(sql)} AND NOT ${everAnswered(sql)}`;

/** In a shared turn, `m` is at or past its chat's history floor (`historyFloor`). */
/** A shared turn sees only the messages people can see, at or past its history floor. */
const withinView = (sql: SqlClient.SqlClient, shared: boolean) =>
shared ? sql`m.seq >= ${historyFloor(sql, sql`m.org_id`, sql`m.chat_id`)}` : sql`1 = 1`;
shared
? sql`m.seq >= ${historyFloor(sql, sql`m.org_id`, sql`m.chat_id`)} AND ${visibleToPeople(sql, "m")}`
: sql`1 = 1`;

export interface OwnUnread {
readonly messageId: KinMessageId;
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/kin/host/cacheParts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ export const recordUse = Effect.fn("KinCacheParts.recordUse")(function* (
readonly startedAt: number;
readonly lastRequestAt: number;
readonly freshUsage?: CacheUsage;
readonly maintenance?: boolean;
},
) {
const sql = yield* SqlClient.SqlClient;
yield* sql.withTransaction(
Effect.gen(function* () {
if (turn.maintenance) {
yield* sql`UPDATE kin_cache_parts SET last_request_at = MAX(last_request_at, ${turn.lastRequestAt})
WHERE fingerprint = ${part.fingerprint} AND org_id = ${part.orgId} AND agent_id = ${part.agentId}`;
return;
}
const usage = turn.freshUsage === undefined ? null : yield* encodeUsage(turn.freshUsage);
const stamped = yield* sql`UPDATE kin_wakeups SET cache_part = ${part.fingerprint},
cache_request_started_at = ${turn.startedAt},
Expand Down
21 changes: 21 additions & 0 deletions apps/server/src/kin/host/cacheSessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import type {
} from "../../orchestration-v2/Adapters/ClaudeAdapterV2.ts";
import { KinServer } from "../KinServer.ts";
import { instructionVersion } from "../lead/instructions.ts";
import { sdkCostOf, totalsOf, type SessionUsage } from "./sessionUsage.ts";
import { storedRoster } from "./sessionRoster.ts";
import { recordUse, type CachePart, type CacheUsage } from "./cacheParts.ts";

export const CACHE_LIFETIME_MS = 60 * 60_000;
Expand All @@ -43,6 +45,8 @@ interface Observation {
readonly usage: CacheUsage | undefined;
}

type SessionTotals = SessionUsage & { readonly sessionId: string };

interface Prepared {
readonly options: ClaudeAgentSdkQueryOptions;
readonly block: LeadingBlock;
Expand All @@ -56,6 +60,7 @@ interface Prepared {
observed: Observation | undefined;
offeredAt: number | undefined;
fresh: boolean;
totals?: SessionTotals;
}

interface Lease extends ObservedList {
Expand All @@ -72,6 +77,7 @@ interface WarmSession extends ObservedList {
readonly modelsJson: string;
readonly configHash: string;
readonly expiresAt: number;
readonly totals?: SessionTotals;
}

const configHash = (settings: ServerSettings) => hash(JSON.stringify(settings.providerInstances));
Expand Down Expand Up @@ -186,6 +192,12 @@ const make = () => {
messages: query.messages.pipe(
Stream.tap((message) =>
Effect.sync(() => {
if (message.type === "result")
entry.totals = {
sessionId: message.session_id,
counts: totalsOf(message),
cost: sdkCostOf(message.total_cost_usd),
};
if (entry.offeredAt === undefined || entry.observed !== undefined) return;
const usage = measure(message);
if (usage === undefined) return;
Expand Down Expand Up @@ -265,9 +277,18 @@ const make = () => {
block: entry.block,
modelsJson: lead.modelsJson,
configHash: entry.configHash,
...(entry.totals === undefined ? {} : { totals: entry.totals }),
expiresAt: row.lastRequestAt + CACHE_LIFETIME_MS,
});
}),
roster: (threadId: ThreadId) => {
const launch = prepared.get(threadId);
const list = lists.get(threadId);
const mcp = launch?.options.mcpServers?.["t3-code"];
return list?.authHash === launch?.authHash && list !== undefined && mcp?.type === "http"
? storedRoster(list.scope, mcp.url, list.sha)
: undefined;
},
current: (part: CachePart, modelsJson: string, settings: ServerSettings) => {
const current = sessions.get(slot(part));
return current?.modelsJson === modelsJson && current.configHash === configHash(settings)
Expand Down
Loading
Loading