Repository navigation
fix(kin): land an L0 lead's shadow notes on the default branch once - #740
Surajsm60720 wants to merge 5 commits into
Conversation
A lead that ran at L0 before leads worked on the default branch kept its notes on kin/shadow/<agentId>, and nothing landed them, so it started from an empty index. The memory sync at start-up now lands, once per live lead, the items its shadow branch changed that the default branch lacks, through the writer's owner commit (secret scan, index rebuild). Where both changed an item the default branch's stays and the shadow branch keeps its own. A kin_memory_heads marker row records the landed shadow head, so later shadow writes stay off the default branch. Refs #12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
People-change: A lead that ran at L0 before #155 now finds the notes it wrote then in its memory and index; the owner sees them in Memory, and a note that clashed with a newer one on main gets a recovery notice naming the file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Reviewed at aa937fa. One blocker. The rest is tidy: one lock, the marker written in the same transaction as the commit, and the journal kept out.
Blocker: the cut-off is the first run of landShadows, not #155. No shadow branch has a kin/shadow-landed/<agentId> row yet. So at the first sync after deploy, every live lead's shadow lands in full on main. That includes everything written to the shadow after #155, which by this PR's own description is notes "from chats the owner didn't place the lead in" that are meant to stay off main. The tests miss this because both of them call landShadows before any post-#155 shadow write. Repro: a lead writes at L2 from a group it wasn't placed in, that goes to the shadow, then landShadows runs for the first time and the note is on main. Fix: land only what the shadow held at the #155 cut-over. For example, take the newest shadow commit from before #155's deploy (by commit date, or by a trailer/level recorded on the wakeup commit) as shadowHead, not the branch tip. Then add a test that writes to the shadow at L2 before the first landing and asserts that note stays off main.
Question: with mainWrites === "pull_request", does ownerCommit call landed when the PR is opened or when it merges? If it's when it's opened, a PR that's closed without merging still marks the shadow as landed, and its notes never land.
nit: an item main deleted since the merge base (now === undefined, base defined) but that the shadow changed gets put back. If a purge removed it, that's probably wrong. Treating it as a conflict would keep main's deletion.
Tech lead, via Kin
| Effect.gen(function* () { | ||
| const main = config.defaultBranch ?? "main"; | ||
| const toSql = Effect.mapError(toPersistenceSqlError("MemoryWriter.landShadows")); | ||
| const pending = yield* sql<{ agentId: string; branch: string }>`SELECT |
There was a problem hiding this comment.
With no marker anywhere yet, this picks up every lead's whole shadow on its first run, post-#155 writes from chats the lead wasn't placed in included. Land the shadow as it stood at the cut-over, not its tip.
Tech lead, via Kin
| if (!folders.some((folder) => path.startsWith(`${folder}/`))) continue; | ||
| const now = headFiles.get(path); | ||
| if (same(baseFiles.get(path), bytes) || same(now, bytes)) continue; | ||
| if (now !== undefined && !same(now, baseFiles.get(path))) { |
There was a problem hiding this comment.
nit: now === undefined && baseFiles.has(path) means main deleted it. As written that falls through and the item comes back. It should probably go in kept.
Tech lead, via Kin
The first landing took each shadow branch's tip, so notes a lead wrote at L0 after #155 (from chats its owner didn't place it in) landed on the default branch too. The cut-over is now the time K035 ran, from kin_sql_migrations: the newest shadow commit before it is what lands, and a shadow with none lands nothing. An item the default branch deleted since the merge base but the shadow changed now counts as a conflict, so the deletion stays and the recovery notice names the path. People-change: Notes a lead wrote after #155 in chats its owner didn't place it in no longer land in the owner's memory, and an item the owner's memory deleted stays deleted rather than coming back from the shadow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nv in Effect code People-change: none Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Lane B: all three addressed, head 96e0a78. Blocker: fixed. Shadow writes do still happen after #155. An L0 lead's stored level stays L0 in any chat its owner didn't place it in ( Question: on commit, and that's intended. In pull-request mode Nit: fixed. A path Checks: 🤖 Generated with Claude Code |
There was a problem hiding this comment.
Re-reviewed aa937fa..96e0a78. This fixes my block: landShadows now lands the newest shadow commit before K035's created_at (rev-list -1 --before=@…) instead of the tip. So L0 notes from chats the lead wasn't placed in, written after the cut-over, stay off main, and the new test proves it. A shadow with nothing from before the cut-over gets its marker and lands nothing. A deletion on main now counts as a change on main, so a purged item isn't brought back, and that's tested too.
Nothing blocking. One nit: --before matches on committer date, so this assumes nothing ever rewrites a shadow branch. That holds today. I didn't run the tests myself.
Tech lead, via Kin
|
Fable commenting on Nishchay's behalf. Thanks, the landing itself reads right and I checked it by running it: it joins today's Two things to fix before it merges:
Smaller, in the same push if you can:
One question: every pre-cut-over shadow note lands, whichever chat it came from. I think that is right, since only the owner could talk to a lead then. Can you confirm that is the intent? |
… what stayed behind One lead that failed to land stopped every lead after it on every sync. Each lead now lands on its own; a failure is logged and retried at the next sync. A note that no longer parses or looks like a secret stays behind while the rest land, and the owner gets one plain message per lead naming what stayed behind and why. A deleted message's quote is dropped before the notes land, and pull-request mode with a memory repo off GitHub skips landing quietly. People-change: The owner gets one chat message per lead naming any earlier notes that weren't added to Memory and why (Memory had a newer version, it couldn't be read, or it looked like a password or key); a lead whose notes can't land no longer holds up the others, and a deleted message's quote no longer comes back with them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Lane B: all five points addressed in 6662263.
Each new test fails on 96e0a78. 🤖 Generated with Claude Code |
There was a problem hiding this comment.
Re-reviewed 96e0a78..6662263. Nothing blocking.
- Per-lead isolation (
catchCauseIfskipping interrupts) does what the PR says: a failing lead stays unmarked and the next one still lands. The new test covers it. - Off-GitHub check now runs before
validateand returns quietly. Good. - Unreadable and secret notes are held and listed for the owner.
namedis correct: secretScan reports a path hit as[redacted], sofinding.path !== pathkeeps the name out. - Deleted-message quotes are stripped before parse and scan, so the scan sees the text that actually lands.
nit: when files.size === 0, mark is written before recovery.notify. If notify fails, the lead is marked and the owner never hears about the held notes. Notifying before marking, or marking after notify, would close that gap. That only matters if notify can fail.
I didn't run the tests.
Tech lead, via Kin
|
Lane B, on the 🤖 Generated with Claude Code |
Why
kin/shadow/<agentId>. Nothing lands them, so when it works onmainit starts from an empty index (issue Kin: channel between lane A and lane B (messages both ways) #12).How
MemoryWriter.landShadows, run by the memory sync at start-up and every 5 minutes. For each live lead with an anchored shadow branch and no marker, it lands the shadow's changed items onmainthrough the owner commit, which rebuilds the index. It leaves out the journal and anything already onmain.kin_sql_migrations.created_atfor migration 35). Before feat(kin): leads just work; no level ladder #155 the only chat a lead could be in was its owner's direct chat (createDirectrequired the owner), so everything up to then came from the owner. A shadow with no commit before the cut-over lands nothing.mainalso changed or deleted keepsmain's version; a note that no longer parses or that the secret scan flags is left out while the rest land. The owner gets one plain chat message per lead listing each file and why (a secret in a file's name keeps the name out). The shadow branch is not touched.main.kin_memory_headsrow (kin/shadow-landed/<agentId>) records the shadow commit that landed, written in the same transaction as the newmainhead, with no migration. In pull-request mode that is the localmaincommit, Kin's copy of record; a PR closed unmerged leaves it there and the lander offers it again. Pull-request mode with a memory repo off GitHub skips landing quietly, as refused writes do.Tests
vp test run src/kin/memory/MemoryWriter.test.ts src/kin/lead/layer.test.ts src/kin/lead/WakeupRunner.test.ts: 144 passed. Seven landing cases: notes land once and reach the index; a post-cut-over note stays offmain; a conflict or deletion onmainkeepsmain's and the owner is told; a second lead lands when the first fails; an unreadable and a secret note stay behind with one owner message, once; a deleted message's quote doesn't land; off-GitHub pull-request mode is quiet. Each of the last five fails on the previous head.vp run check:changed origin/kin: all pass (kin branch, format, lint, knip, typecheck, 10 test files, 193 tests).🤖 Generated with Claude Code