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
49 changes: 46 additions & 3 deletions apps/server/src/kin/memory/MemoryPullRequests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const scenarios = [
"stall-body",
"run-from-fork",
"no-pull-requests",
"off-github-local-save",
"off-github-strip-quotes",
"batched",
"restart",
"repeat-edit",
Expand Down Expand Up @@ -175,6 +177,18 @@ it.effect.each(scenarios)("memory writes through PRs: %s", (scenario) =>
yield* workflow(scenario === "decision-then-journal" ? buildCommit : oldPin),
);
}
if (scenario === "off-github-strip-quotes") {
yield* fs.makeDirectory(`${source}/claims`);
yield* fs.writeFileString(
`${source}/claims/said.md`,
fixtureItem({
id: "said",
kind: "claim",
source: "kin:chat:cleared-chat:message:m-cleared",
quote: FIXTURE_QUOTE,
}),
);
}
yield* git(source, ["add", "--", "."]);
yield* git(source, [...identity, "commit", "-m", "fixture"]);
yield* git(root, ["clone", "--bare", "--", source, remote]);
Expand Down Expand Up @@ -499,8 +513,10 @@ it.effect.each(scenarios)("memory writes through PRs: %s", (scenario) =>
return { status: 201, body: {} };
return { status: 404, body: { message: "Not Found" } };
}).pipe(Effect.orDie);
// GitHub as the owner's `gh` login, or as Kin's GitHub App in `merged`, over `route`.
const asApp = scenario === "merged";
// GitHub requests go through `route` as the owner or as the GitHub App.
const offGitHub =
scenario === "off-github-local-save" || scenario === "off-github-strip-quotes";
const asApp = scenario === "merged" || offGitHub;
const github = { requests: [] as Array<RecordedRequest> };
const callAs =
(as: "app" | "owner"): KinGitHubApi["Service"]["call"] =>
Expand Down Expand Up @@ -558,7 +574,9 @@ it.effect.each(scenarios)("memory writes through PRs: %s", (scenario) =>
const config = Layer.succeed(MemoryConfig, {
baseDirectory: root,
...(scenario === "code-owner-refusal" ? {} : { buildCommit }),
repositories: [{ orgId, repoUrl: remote, path: "state", githubRepo: repo }],
repositories: [
{ orgId, repoUrl: remote, path: "state", ...(offGitHub ? {} : { githubRepo: repo }) },
],
});
const auth = Layer.succeed(Writer.MemoryWriterAuthority, {
resolve: (_org, wakeupId) =>
Expand Down Expand Up @@ -653,6 +671,31 @@ it.effect.each(scenarios)("memory writes through PRs: %s", (scenario) =>
).length;
const toldOwner = () => notices.flatMap((notice) => notice.owner ?? []);

if (offGitHub) {
if (scenario === "off-github-local-save") {
yield* writer.stage(orgId, "wake1", claim("new"));
const { commit } = yield* journal("wake1");
expect(yield* localMain()).toBe(commit);
expect((yield* memory.readItem(orgId, KinMemoryItemId.make("new"))).head.id).toBe("new");
} else {
const localFile = () => git(paths.writer, ["show", "main:claims/said.md"]);
expect(yield* localFile()).toContain(`quote: "${FIXTURE_QUOTE}"`);
yield* writer.stripQuotes(orgId);
const stripped = yield* localFile();
expect(stripped).not.toContain("quote:");
expect(stripped).toContain("Invented fixture body.");
}
const head = yield* localMain();
expect(head).not.toBe(original);
expect(yield* memory.anchor(orgId, "main")).toBe(head);
expect(yield* Queue.take(outcomes)).toEqual({ _tag: "idle" });
yield* lander.sweep(orgId);
expect(github.requests).toEqual([]);
expect(yield* bare("rev-parse", "refs/heads/main")).toBe(original);
expect(yield* bare("for-each-ref", "--format=%(refname)")).toBe("refs/heads/main");
return;
}

if (scenario === "decision-then-journal") {
// A decision saved by code, then a wake-up's journal: both land, no review asked.
expect(yield* writer.recordDecision(orgId, decision("decision-0001"))).toEqual({
Expand Down
27 changes: 3 additions & 24 deletions apps/server/src/kin/memory/MemoryWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as MemoryCache from "./MemoryCache.ts";
import {
KinChatError,
MemoryItemFrontMatter,
RepoSlug,
type KinAgentId,
type KinChatId,
type KinMemoryItemId,
Expand Down Expand Up @@ -313,7 +312,6 @@ export class MemoryWriter extends Context.Service<
readonly stripQuotes: (orgId: KinOrgId) => Effect.Effect<void, Failure>;
}
>()("t3/kin/memory/MemoryWriter") {}
const isRepoSlug = Schema.is(RepoSlug);
const dreamBranch = /^dream\/\d{4}-\d{2}-\d{2}$/;
const folders = [
"objectives",
Expand Down Expand Up @@ -364,6 +362,8 @@ const make = Effect.gen(function* () {
const app = yield* gitHubApp;
const cache = yield* MemoryCache.MemoryCache;
const pullRequests = yield* Effect.serviceOption(MemoryPullRequests);
// Pull request mode saves the default branch locally without pushing it.
// The lander stays idle when there is no GitHub target, so no pull request is attempted.
const mainWrites = Option.isSome(pullRequests)
? "pull_request"
: config.directMainPush === true
Expand Down Expand Up @@ -788,16 +788,6 @@ const make = Effect.gen(function* () {
return yield* new MemoryConfigError({ orgId, operation: "writer", reason: "Unknown org" });
return repo;
});
// Checked before committing: a commit no PR could ever land would only sit on this server.
const refuseOffGitHub = Effect.fn("MemoryWriter.refuseOffGitHub")(function* (orgId: KinOrgId) {
const repo = yield* repoFor(orgId);
if (repo.githubRepo === undefined || !isRepoSlug(repo.githubRepo))
return yield* new MemorySyncConflict({
orgId,
operation: "push",
reason: "The memory repo is not on GitHub, so Kin cannot open its PR",
});
});
const refuseMainWrite = Effect.fn("MemoryWriter.refuseMainWrite")(function* (orgId: KinOrgId) {
const reason =
"Memory writes to the default branch land through a pull request, which isn't set up here (TRIG-15); this one was not committed";
Expand Down Expand Up @@ -1201,7 +1191,6 @@ const make = Effect.gen(function* () {
const onMain = branch === (config.defaultBranch ?? "main");
if (onMain && mainWrites === "refused") return yield* refuseMainWrite(orgId);
const viaPullRequest = onMain && mainWrites === "pull_request";
if (viaPullRequest) yield* refuseOffGitHub(orgId);
const recorded = yield* branchHead(orgId, writer, branch);
const unpushedKey = `${orgId}\u0000${branch}`;
const push = (sha: string) =>
Expand Down Expand Up @@ -1341,7 +1330,6 @@ const make = Effect.gen(function* () {
}),
),
);
// The wake-up is done once its commit is here; GitHub gets it in the background.
if (viaPullRequest) yield* lander.signal(orgId);
else yield* push(commit);
return { commit };
Expand Down Expand Up @@ -1495,7 +1483,6 @@ const make = Effect.gen(function* () {
operation: "push",
reason: "Memory writes to the default branch are refused",
});
if (mainWrites === "pull_request") yield* refuseOffGitHub(orgId);
const head = yield* branchHead(orgId, writer, main);
const headFiles = yield* filesAt(orgId, writer, head);
if (head !== input.base) {
Expand Down Expand Up @@ -1554,7 +1541,6 @@ const make = Effect.gen(function* () {
const repo = yield* repoFor(orgId);
const onMain = input.branch === main;
if (onMain && mainWrites === "refused") return yield* refuseMainWrite(orgId);
if (onMain && mainWrites === "pull_request") yield* refuseOffGitHub(orgId);
const stale = { _tag: "stale" } as const;
// A purge rewrites history, so the wake-up's commits may be gone.
for (const sha of [input.base, input.commit])
Expand Down Expand Up @@ -1632,7 +1618,6 @@ const make = Effect.gen(function* () {
yield* refuseDuringPurge(orgId);
const repo = yield* repoFor(orgId);
if (mainWrites === "refused") return yield* refuseMainWrite(orgId);
if (mainWrites === "pull_request") yield* refuseOffGitHub(orgId);
const item = yield* memory.readItemQuietly(orgId, input.itemId);
const head = yield* branchHead(orgId, writer, main);
const headFiles = yield* filesAt(orgId, writer, head);
Expand Down Expand Up @@ -1686,7 +1671,6 @@ const make = Effect.gen(function* () {
operation: "push",
reason: "Memory writes to the default branch are refused",
});
if (mainWrites === "pull_request") yield* refuseOffGitHub(orgId);
const item = yield* memory.readItemQuietly(orgId, input.itemId);
const head = yield* branchHead(orgId, writer, main);
const headFiles = yield* filesAt(orgId, writer, head);
Expand Down Expand Up @@ -1732,7 +1716,6 @@ const make = Effect.gen(function* () {
yield* refuseDuringPurge(orgId);
const repo = yield* repoFor(orgId);
if (mainWrites === "refused") return yield* refuseMainWrite(orgId);
if (mainWrites === "pull_request") yield* refuseOffGitHub(orgId);
const item = yield* memory.readItemQuietly(orgId, input.itemId);
const head = yield* branchHead(orgId, writer, main);
const headFiles = yield* filesAt(orgId, writer, head);
Expand Down Expand Up @@ -1779,7 +1762,6 @@ const make = Effect.gen(function* () {
operation: "push",
reason: "Memory writes to the default branch are refused",
});
if (mainWrites === "pull_request") yield* refuseOffGitHub(orgId);
const path = `decisions/${input.itemId}.md`;
yield* safePath(orgId, writer, path);
const head = yield* branchHead(orgId, writer, main);
Expand Down Expand Up @@ -1859,10 +1841,7 @@ const make = Effect.gen(function* () {
]))
.split("\n")
.filter((branch) => branch !== "");
const mainWritable =
mainWrites === "direct" ||
(mainWrites === "pull_request" &&
(yield* refuseOffGitHub(orgId).pipe(Effect.result))._tag === "Success");
const mainWritable = mainWrites !== "refused";
let failure: MemoryWriteFailure | undefined;
const [clears] = yield* sql<{ mark: number }>`SELECT
COALESCE(SUM(cleared_change_seq), 0) AS mark FROM kin_chats WHERE org_id = ${orgId}`.pipe(
Expand Down
2 changes: 1 addition & 1 deletion evals/mcp-tool-use/changed/surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const runnerHash = () =>
);

/** The runner this file's part list was checked against. */
export const REVIEWED_RUNNER = "c8540495b72662c3";
export const REVIEWED_RUNNER = "ce614a0494695af4";

export const CaseSurface = Schema.Struct({
/** The case as run.json hashes it, and its first request as run.json hashes it. */
Expand Down
2 changes: 2 additions & 0 deletions verification/kin/people/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ On 2026-11-26, against the visibility-rule fix (#906, kin `6c18694fa04`; every r
**Re-confirmed 2026-11-28** on train 11 (the search fence, joined on kin `252c46ce43d`; no spec change, all rules hold; 10/10 variants caught). `teamView.ts` gains one notes rule (`notesSeenBy`): a project's notes match only for the owner, a co-owner and that project's lead, a client's notes only with Clients on; Search and the Work list's text filter both ask it. It narrows what a teammate finds and widens nothing.

**Re-confirmed 2026-11-28** against the facts-and-answers wording (`fix/kin-end-words-facts-and-answers`, on kin `73a62308020`; no spec change, all 9 rules hold over 6,243 states in 1 s; 10/10 variants caught in 9 s). The one covered file changed, `lead/Audience.ts`, changes only the words of `SHARED_REFUSAL`, the answer a refused tool call gets in a chat other people read. Every caller still refuses by the same checks and passes the constant by reference, so no level, removal, link or place changes.

**Re-confirmed 2026-11-28** on train 13 (the wording train, five steps joined on kin `68da5258875`; no spec change, all 9 rules hold over 6,243 states in 1 s; 10/10 variants caught in 7 s). The one covered file, `lead/Audience.ts`, differs from kin only by step 1's words for `SHARED_REFUSAL`; kin changed nothing in it since the step was built, so every caller still refuses by the same checks and no level, removal, link or place changes.
2 changes: 2 additions & 0 deletions verification/kin/reply/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ The guard "Steer waits after a Stop" (rule 12) now rests on code, from kin's `15
**Re-confirmed 2026-11-28** against the facts-and-answers wording (`fix/kin-end-words-facts-and-answers`, on kin `73a62308020`; no spec change, all 17 rules hold over 1,554,826 states in 495 s; 28/28 variants caught in 45 s). The one covered file changed, `lead/Audience.ts`, changes only the words of `SHARED_REFUSAL`, the answer a refused tool call gets in a chat other people read. No claim, reply, failure line, rescue, requeue or Stop step changes.

**Re-confirmed 2026-11-28** against the notice words (`fix/kin-end-words-notices`, on kin `73a62308020`; no spec change, all 17 rules hold over 1,554,826 states in 490 s; 28/28 variants caught in 45 s). The one covered file it changes, `KinReplyBridge.ts`, changes only words: the last-resort chat line after an unexpected refusal (`WITHHELD_ANY`) and a separate fallback for an agent's update refused with no reason. The plain failure line is still posted once, at the same step and with the same Retry id, so no reply, failure line, rescue, requeue or Stop step changes.

**Re-confirmed 2026-11-28** on train 13 (the wording train, five steps joined on kin `68da5258875`; no spec change, all 17 rules hold over 1,554,826 states in 533 s; 28/28 variants caught in 36 s). Of the covered files, `lead/Audience.ts` differs from kin only by step 1's words for `SHARED_REFUSAL`, and `KinReplyBridge.ts` only by step 4's words (`WITHHELD_ANY` and the agent's own update fallback); kin changed neither since the steps were built. No reply, failure line, rescue, requeue or Stop step changes.
Loading