Skip to content

fix(kin): land an L0 lead's shadow notes on the default branch once - #740

Open
Surajsm60720 wants to merge 19 commits into
kinfrom
fix/kin-l0-shadow-landing
Open

Surajsm60720 wants to merge 19 commits into
kinfrom
fix/kin-l0-shadow-landing

Conversation

@Surajsm60720

@Surajsm60720 Surajsm60720 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

How

  • New 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 landing recorded in kin_shadow_landings, it lands the shadow's changed items on main through the owner commit, which rebuilds the index. It leaves out the journal and anything already on main.
  • Cut-over: only what the shadow held when feat(kin): leads just work; no level ladder #155 took effect can land: the newest shadow commit dated strictly before the second K035 ran (kin_sql_migrations.created_at for migration 35). A shadow with no commit before then lands nothing.
  • Git dates alone can't prove where a note came from (a shadow may come from another host), so each note's stored provenance must: this lead's own wake-up or event that started before K035 ran on this database, or a direct chat of only the owner and this lead, citing a message this database still holds that was said before K035 ran (a cleared chat's messages are gone with their times, so those notes stay behind). Ending what retired notes were shared as happens in the same transaction that marks the lead landed, so a failed commit leaves sharing as it was. A member's word, a shared item, or a chat, wake-up or event this database doesn't know stays behind.
  • No landing without one verified merge base: none, several, or a merge-base error refuses the lead and leaves it unmarked, so a replaced or recovered main can't get notes back it removed on purpose. A note whose id another note would have in the tree that lands stays behind (two would fail every read with MemoryDuplicateId). Ids are counted only for files Memory's reader admits, by its own rule (Memory.admittedId: path, mode, size, UTF-8, lenient parse, kind matching folder), for main's files and for the tree that would land. So an older note with a non-text quote still reserves its id, and a backup like people/sam.md.bak reserves nothing. The check repeats whenever holding a note back puts main's note back at that path.
  • Quotes stay out of this import. Clearing a chat shares no lock with the writer, so a clear could land between a check and the push; dropping every quote removes that window.
  • Each lead lands on its own: a lead that fails is logged and retried at the next sync, and the leads after it still land.
  • What stays behind: an item main also changed keeps main's ("Memory had a different version, so Kin kept it."), one main deleted stays deleted ("This note was removed from Memory, so Kin left it out."), and notes that don't parse, that Memory's reader gives no id (a person note filed under claims/, say), that look like a secret, clash, or can't be traced are left out. The shadow branch is not touched.
  • The owner hears once per lead: a kin_held_posts row keyed per company and lead, written in the same transaction as the landing mark and the new main head, so a restart can't lose it. The existing deliverHeld posts it as its own message (never grouped with another lead's), after quiet hours, with the stable id kin-held:shadow-landed:<org>:<lead>. Every file name in that message or in the log is secret-scanned first; a flagged one shows as "One note".
  • Runs once, recorded in kin_shadow_landings (migration K247, one row per lead, written only by landShadows). The commit message carries no marker. Before a landing's commit can reach the default branch's record, Kin saves that exact commit and the held notes with their reasons. The lead counts as landed when landed_at is set. That happens in the same transaction as the new main head, the end of retired notes' sharing, and the owner's notice.
  • This changes every pull-request-mode owner commit, not only landings. In pull-request mode the record is main's SQLite anchor, which the lander and branchHead both read. So the owner commit records the anchor, with any landing mark, before it moves the local ref, and it always signals the lander. A failed record leaves local main and the anchor where they were, so the retry plans again from a consistent main. A local ref that fails to move is logged, not failed, for any owner commit, and catches up to the anchor at the next write. The ordinary pull-request write path stays covered by MemoryPullRequests.test.ts (49 passed). A PR closed unmerged leaves the commit on local main, and the lander offers it again. A memory repo off GitHub now lands on local main, as other writes there do since kin made memory off GitHub stay local.
  • On a retry with a saved commit, Kin checks that exact commit against the record for the write mode. In pull-request mode that's the anchor. For direct pushes it's the remote main, fetched first, and Kin decides nothing that round if it can't fetch. If the saved commit is on that record, the lead is marked and the saved notice is sent, with each note's original reason. If it isn't, the landing is planned again. Nothing is inferred from commit messages or the current tree, so a commit that copies a landing's message is just another commit. Retired notes of a landing the remote took end their sharing through reconcileSharing, which sweeps main before every landing.

Tests

  • vp test run src/kin/memory src/kin/chat/KinRefreshHub.test.ts src/kin/lead/layer.test.ts src/kin/lead/WakeupRunner.test.ts src/kin/persistence/KinMigrations.test.ts src/kin/people/leaver.test.ts src/kin/wireBudget.test.ts src/kin/mcp/layer.test.ts, under TZ=UTC and TZ=Asia/Kolkata: 930 passed, 21 skipped in each, on 8e8b6b415b (merged with kin at 00ece848e9).
  • New this round: an interrupted landing in pull-request mode (the SQLite step fails) leaves local main on its anchor and lands at the next sync with no reset notice. With 1e997e8d41's landing code on the merged base it fails, because local main is left ahead of the anchor. A pull-request landing whose local ref can't move is still recorded on the anchor for the lander, and the ref catches up at the next write. A person note filed under claims/ stays behind as unreadable; without the fix it lands. Off-GitHub pull-request mode now lands on local main.
  • Budgets unchanged (wireBudget.test.ts, mcp/layer.test.ts pass with no edits).
  • vp run check:changed origin/kin --timeout 3600: all pass.
  • node scripts/kin-branch-checks.ts origin/kin: clean.

🤖 Generated with Claude Code

Surajsm60720 and others added 2 commits November 23, 2026 07:32
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>

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Surajsm60720 and others added 2 commits November 25, 2026 18:57
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>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

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 (KinLevels.effectiveLevel), and the writer sends L0 writes to the shadow (MemoryWriter.ts stage/commit). The cut-over now comes from a recorded time rather than the first run: kin_sql_migrations.created_at for migration 35 (K035, #155's migration). landShadows lands the newest shadow commit dated before that, not the tip. A shadow with nothing before it lands nothing and is marked. Wake-up commits carry no level trailer, so the migration row is the one recorded signal. New test: a note is written to the shadow after the cut-over and before the first landing, and it stays off main and its index. The test fails when the tip lands.

Question: on commit, and that's intended. In pull-request mode ownerCommit moves local main and records the head (with the marker, in one transaction) before lander.signal opens the PR. Local main is Kin's copy of record; agents and the index read from it. A PR closed unmerged doesn't roll it back. The lander says memory "is still saved on this server" and offers the whole local tree again in its next batch (MemoryLander.ts refuse / landBatch). So the notes are on main when they're marked, the same as for wake-ups and landDream. No change.

Nit: fixed. A path main deleted since the merge base but the shadow changed is now a conflict. main's deletion stays, and the recovery notice names the path. It's covered in the conflict test, which fails without the change.

Checks: check:changed origin/kin all pass; MemoryWriter tests 68 passed; MemoryWriter, Memory, lead/layer and WakeupRunner tests 190 passed. PR body updated.

🤖 Generated with Claude Code

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@GLDRoger

Copy link
Copy Markdown
Owner

Fable commenting on Nishchay's behalf.

Thanks, the landing itself reads right and I checked it by running it: it joins today's kin cleanly, the memory tests pass on the merged tree (488 passed), and breaking the cut-over or the "default branch also changed" rule makes your new tests fail. It never writes over a file the default branch changed, the marker is saved with the new head, and the secret scan runs on what lands.

Two things to fix before it merges:

  1. One lead that fails stops every lead after it, on every sync. Any error inside the for over pending (a secret finding, a shadow with an anchor but no local branch, a refused push) ends landShadows for the whole org. The failing lead gets no marker, so the next sync stops at the same place, and the leads after it never land. Please run each lead's pass on its own, the way stripQuotes does per branch (catch, log, go on). For a secret finding, leave the flagged files out, name them, land the rest and set the marker. One test row: the second lead lands when the first fails.
  2. The owner is never told about a held-back note. The notice is sent without owner words, and the owner-notice layer only logs those. The PR text and the People-change line say a person gets a notice naming the file. Please give it plain words for the owner, one message per lead, listing what stayed behind and why (the newer one was kept, it could not be read, it looked like a secret). A shadow note that no longer parses is skipped with no trace today and then the marker is set, so include those. If log-only is what you want, say so in the PR text and in a People-change line.

Smaller, in the same push if you can:

  1. In pull-request mode with a memory repo that is not on GitHub, refuseOffGitHub fails the call and logs a warning every five minutes while a lead is pending. Return quietly there, as you do when writes are refused.
  2. stripQuotes runs before landShadows, and what lands is the shadow as it was at the cut-over, so a deleted message's quote can come back onto the default branch until the next sync strips it. Land first and strip second, or run the quote check over the files before the commit.

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>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B: all five points addressed in 6662263.

  1. Each lead lands on its own now (MemoryWriter.ts ~1932-2018): a failure is logged and that lead retries next sync, the rest carry on. A note the secret scan flags stays behind, is named to the owner, and the rest land with the marker set. New test: a second lead lands when the first fails.
  2. The owner now gets one plain chat message per lead, e.g. "Some of Lead's earlier notes weren't added to Memory:" followed by each file and why: Memory already had a newer version, it couldn't be read, or it looked like a password or key. Notes that no longer parse are included. If a secret is in the file's name, the message says "One note" instead. It goes through the owner words the restart notice already uses. Test covers it, and checks the message is sent only once. The People-change line matches.
  3. Pull-request mode with a memory repo off GitHub now returns quietly (MemoryWriter.ts ~1916). Tested.
  4. I put the quote check in before the commit instead of changing the order: deletedQuotes runs over the files about to land, so a deleted message's quote never reaches the default branch. Tested.
  5. Confirmed. Before feat(kin): leads just work; no level ladder #155, the only way to make a chat was KinChatService.createDirect, which required the person to be the lead's owner. Group chats existed in the schema but nothing in production created one. So every pre-cut-over shadow note came from the owner's DM, or from a non-chat wake-up such as a routine or a GitHub event. Landing all of them is the intent.

Each new test fails on 96e0a78. check:changed origin/kin passes, and the three touched test files pass (144 tests). No dependency, UI, or budget changes. The branch still merges cleanly into kin, so I didn't merge.

🤖 Generated with Claude Code

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 96e0a78..6662263. Nothing blocking.

  • Per-lead isolation (catchCauseIf skipping 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 validate and returns quietly. Good.
  • Unreadable and secret notes are held and listed for the owner. named is correct: secretScan reports a path hit as [redacted], so finding.path !== path keeps 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

@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B, on the mark-before-notify nit: MemoryRecoveryHooks.notify is typed Effect<void> (Memory.ts:153-162), so it can't fail with an error. Only a defect could stop it. A defect there would be a bug in the hook, and it would show up in the log through the per-lead catchCauseIf. That's why I left the order as it is: the marker stays tied to the landing, and the notice goes out after it.

🤖 Generated with Claude Code

@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B, a pointer in case it got lost in last night's merge run (#12 says #740 is still waiting on its fixes): all five points from Fable's review are in 6662263fb9, the PR's current head. My reply above lists each one.

  1. Each lead lands on its own.
  2. The owner gets one plain message per lead, naming what stayed behind and why.
  3. Off-GitHub pull-request mode returns quietly.
  4. Quotes from deleted messages are stripped before the commit.
  5. The pre-cut-over shadow notes are confirmed as coming from the owner's chat or wake-ups.

The tech lead re-reviewed 6662263 and found nothing blocking. GitHub still shows the PR as blocked only because its first review (aa937fa) requested changes and nobody has dismissed it. If anything is still missing, tell me which point and I'll pick it up.

🤖 Generated with Claude Code

@GLDRoger

Copy link
Copy Markdown
Owner

Lane A, to @Surajsm60720: the independent re-review of 6662263fb9 is done. First, the wait since 26 Nov was mine, not yours: sorry. Your five points are in, and the reviewer confirmed two of them by removing the fix and watching the test fail. The branch joins today's kin with no conflict, and the memory tests pass on the joined tree (469 passed).

It still found five things, because this path writes into a company's default-branch memory once and cannot be taken back. Verdict: merge after these fixes. Line numbers are at 6662263fb9.

High

  1. The cut-off can admit newer notes. MemoryWriter.ts:1924–1945 uses the local install time of migration K035 as the boundary, and git rev-list --before=@<stamp> is inclusive, so a commit stamped at exactly that second is taken; a shadow that came from another host can also hold later writes that predate this database's K035. Make the boundary strictly earlier, check owner / direct-chat origin from stored provenance where history is ambiguous, and leave behind what cannot be verified. Test the equal-second case and a note from a non-owner source.
  2. No copy without a verified merge base, and no duplicate ids. MemoryWriter.ts:1946–1963, 1970–1998 treats any merge-base error as "no common ancestor", so after main was recovered or replaced, a stale shadow re-imports notes that were removed on purpose. Refuse and leave it unmarked when there is no single verified base. With a good base, two notes at different paths can still carry the same id (people/onboarding.md and claims/onboarding.md): comparing by path accepts both, and reads then fail with MemoryDuplicateId. Check ids, not only paths.
  3. A chat cleared while the landing runs. MemoryWriter.ts:1964–1999 checks for deleted messages before it scans, writes and pushes. If the owner clears the source chat after that read, the quote goes into permanent default-branch history, and the later sweep can only add a removal commit on top. Serialize the landing decision with clear through one shared boundary (a second unlocked check only narrows the window), or leave structured quotes out of this one-time import. Add a controlled clear-while-landing test.

Medium

  1. A restart can lose the owner's message for good. MemoryWriter.ts:1987–2008 writes the marker, then asks for the notice. A crash or a caught SQL error between the two means no notice and no retry. Keep the marker with the anchored head, and in the same transaction store a retryable notice intent with a stable key per company and lead; deliver from that. Today two leads' lines can also be grouped into one quiet-hours message, and the message id is random.
  2. File names and the "newer version" sentence. A conflicting note is put in the held list before its path is scanned (MemoryWriter.ts:1955–1979), so a legacy file name that holds a credential goes raw into the chat message and the log. Scan every file name that is emitted. And "Memory already had a newer version, so that one stays." is not true for a note that was deleted from Memory, and no times are compared: say "Memory had a different version, so Kin kept it." or "This note was removed from Memory, so Kin left it out."

One smaller thing: the off-GitHub test passes even with the guard deleted; assert the local anchor and the marker did not move.

What the review could not do: no live memory repository or GitHub memory pull request was exercised; the crash, clear-race and id-collision findings come from reading the code, and only git's inclusive cut-off was run.

This is now W-79 in your Tasks in Kin. Push the fixes as new commits and I will have it re-read the same day.

🤖 Generated with Claude Code

Surajsm60720 and others added 2 commits November 27, 2026 16:21
People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d keep the owner's notice

The one-time landing writes permanent default-branch history, so what it
can't verify now stays behind:

- The K035 cut-off is strictly earlier: `rev-list --before` takes its own
  second, so a commit in K035's second no longer lands.
- Each note's stored provenance must prove it: this lead's own wake-up or
  event from before K035 ran here, or a direct chat of only the owner and
  this lead. A member's word, a shared item, or a chat, wake-up or event
  this database doesn't know (another host's) stays behind.
- No single merge base (none, several, or an error) refuses the lead and
  leaves it unmarked, so a replaced default branch can't get removed notes
  back. A note whose id another note already has stays behind.
- Quotes stay out of this import: a clear has no lock shared with the
  writer, so one could land between the check and the push.
- The owner's line is a `kin_held_posts` row written in the transaction
  that records the marker and the new head, keyed per company and lead,
  so a restart can't lose it; `deliverHeld` posts it on its own, after
  quiet hours, as `kin-held:shadow-landed:<org>:<lead>`.
- Every file name shown to the owner or logged is secret-scanned first,
  and the conflict sentences say what happened.

People-change: The owner's message about a lead's earlier notes now survives a restart, comes as its own message per lead after quiet hours, never names a file whose name looks like a key, and says "Memory had a different version, so Kin kept it.", "This note was removed from Memory, so Kin left it out.", "It clashes with another note in Memory, so Kin left it out." or "Kin couldn't confirm where it came from, so it left it out."; notes from a member, a group chat or another host, notes at K035's own second, and quotes no longer land, and nothing lands when Memory's history was replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B: all six points from the re-review are in, head 220745f. I merged today's kin first (it merged cleanly) because kin had changed the notice and quiet-hours code this fix depends on, so the fix is built and tested against current code.

  1. Cut-off. A commit dated in the same second K035 ran no longer lands. Each note's stored origin must now also check out: it came from this lead's own wake-up or event that started before K035 ran here, or from a direct chat with only the owner and this lead. A member's words, a shared item, or a chat, wake-up or event this database has no record of (for example from another host) stays behind, and the owner is told "Kin couldn't confirm where it came from, so it left it out." I didn't hold back every non-chat note: notes from the lead's own wake-ups can be checked against stored rows, and holding them all would have left most leads with nothing.
  2. Merge base and ids. If there's no single merge base (none, more than one, or git errors), nothing lands and the lead stays unmarked. Ids are now checked as well as paths: a note whose id another note already uses stays behind ("It clashes with another note in Memory, so Kin left it out."), and reading that id still works.
  3. Chat cleared mid-landing. Clearing a chat only uses its own SQL transaction and shares no lock with the memory writer. Making a clear wait on git pushes wasn't reasonable, so I took the other option: quotes are left out of this one-time import entirely. The notes still land, just without quotes.
  4. Owner's message. It's now a row in kin_held_posts, written in the same transaction as the marker and the new head, with one key per company and lead. The existing deliverHeld posts it after quiet hours. Each lead gets its own message, with a stable id kin-held:shadow-landed:<org>:<lead>, so a restart can't lose it or post it twice. It goes to that lead's own chat with the owner.
  5. File names and wording. Every file name is scanned for secrets before it goes into the message or the log, including notes held back because of a conflict. If a name is flagged, the message just says "One note". The sentences are now "Memory had a different version, so Kin kept it." and "This note was removed from Memory, so Kin left it out."
  6. Off-GitHub test. It now checks that the local anchor and the marker don't move. With the guard deleted, it fails.

Tests that failed before the fix. I swapped in the previous MemoryWriter.ts for one run:

  • A commit at K035's own second.
  • Notes from a member, a group chat, an unknown chat or an unknown wake-up.
  • No shared base.
  • Same id at another path.
  • A chat cleared mid-landing (the quote ended up in main's history).
  • A held note whose name holds a token (the token appeared in the notice).
  • A restart before delivery (no stored notice).
  • The two existing notice tests, because of the new wording.

The off-GitHub test fails with the guard removed.

Checks:

  • Memory and lead tests: 252 passed.
  • vp run check:changed origin/kin --timeout 3600: all pass.
  • node scripts/kin-branch-checks.ts origin/kin: clean.
  • The budget tests pass and the budget files are unchanged, so no label is needed.

The People-change line on the new commit gives the new wording. The PR body is updated.

Not covered: like the review, this didn't exercise a live memory repository or a GitHub memory pull request.

🤖 Generated with Claude Code

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-read the whole diff at 220745f. Nothing blocking: the merge-base guard, the --before=@(ceil-1) cut-over, dropping quotes and the per-lead held post in the marker's transaction all hold up, and the 14 cases cover what they claim. Checked that kin_events.queued_at and kin_wakeups.started_at (ms) exist as the provenance queries assume (K002). Tests not run by me.

Two nits, neither blocking:

  • provenOrigin, MemoryWriter.ts: a kin:chat:<owner-chat>:message:<id> source is accepted on the chat's membership alone. The message's own created_at isn't checked against the cut-over, so for chat-cited notes the only time bound is the git date the PR says it can't trust. A kin_messages lookup with created_at < cutOver (or a missing message counting as unverified, unless it was cleared) would close that.
  • landShadows: endSharing(orgId, ending) runs before ownerCommit. If the commit fails, sharing for those retired ids is already ended while the lead stays unmarked and retries. Probably idempotent and harmless, but moving it into landed (or after the commit) keeps it all-or-nothing.

Tech lead, via Kin

…end sharing only once landed

A note citing the owner's chat now lands only when that message is stored and was said before
K035 ran; a message that's gone (a cleared chat's included, since clearing deletes the rows and
their times) leaves the note behind as unverified. Ending what retired notes were shared as now
runs in the transaction that marks the lead landed, so a failed commit leaves it untouched.

People-change: The owner's message about a lead's earlier notes now survives a restart, comes as its own message per lead after quiet hours, never names a file whose name looks like a key, and says "Memory had a different version, so Kin kept it.", "This note was removed from Memory, so Kin left it out.", "It clashes with another note in Memory, so Kin left it out." or "Kin couldn't confirm where it came from, so it left it out."; notes from a member, a group chat or another host, notes at K035's own second, notes citing a chat message said after K035 ran or no longer kept (a cleared chat's included), and quotes no longer land, and nothing lands when Memory's history was replaced.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B: both nits fixed in 7d8a3a6.

  1. Chat-cited notes now check the message's own time. For a kin:chat:<chat>:message:<id> source, Kin looks up the message in kin_messages and lands the note only if created_at is before K035 ran. The two times are stored differently (kin_sql_migrations is YYYY-MM-DD HH:MM:SS UTC, messages are ISO), so both are parsed to milliseconds before comparing. A deleted message keeps its row and its time, so it still counts. A missing message stays behind as "Kin couldn't confirm where it came from". That includes cleared chats: clearing deletes the rows, and kin_chats only keeps cleared_seq/cleared_change_seq, with no time. Kin can't prove when a cleared message was said, so those notes stay behind too. New test: a note citing a message from before the cut-over lands, and notes citing a message from later that second or a missing one stay behind. The stay-behind cases fail on 220745f. The lands case passes on both, as it should. Older tests that cited messages with no row now insert them, and the cleared-chat test clears at the commit's scan, after the notes were checked.
  2. endSharing now runs inside ownerCommit's landed transaction, before the mark, so it happens only once the commit is recorded. New test: someone else moves main on, so the push is rejected. Sharing stays set, the lead stays unmarked and main is unchanged. This fails on 220745f.

Checks: vp test run src/kin/memory/ 459 passed; vp run check:changed origin/kin all pass (format was fixed before the commit); node scripts/kin-branch-checks.ts origin/kin clean. Already up to date with kin. The PR body's provenance line is updated.

🤖 Generated with Claude Code

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of 220745f..7d8a3a6: nothing blocking, both review fixes hold.

The chat-cited bound is correct. CHAT_SOURCE (quoteAccess.ts:11) has both groups and isn't /g, so the destructure is safe. If a message is missing, deleted or cleared, the note fails closed. The 12:42:41.500 case is the right edge, and the test pins it.

Moving endSharing into landed is also right. ownerCommit runs landed inside the withTransaction that records the new head, after the push. So a rejected push leaves sharing untouched, and the moved-main test proves it.

nit (MemoryWriter.ts:2023): the cut-over normalises created_at with replace(" ", "T") + "Z", but the message time goes through a bare Date.parse(said.at). I didn't confirm that production writes kin_messages.created_at as ISO with Z. If it writes SQLite's YYYY-MM-DD HH:MM:SS, that parses as server-local time and the bound moves by the TZ offset. Parsing it the same way as the cut-over would close that off.

I didn't run the tests.

Tech lead, via Kin

The cut-over and a cited message's time now go through one parse. SQLite's
zoneless YYYY-MM-DD HH:MM:SS is read as UTC, not as the server's local time.

People-change: The owner's message about a lead's earlier notes now survives a restart, comes as its own message per lead after quiet hours, never names a file whose name looks like a key, and says "Memory had a different version, so Kin kept it.", "This note was removed from Memory, so Kin left it out.", "It clashes with another note in Memory, so Kin left it out." or "Kin couldn't confirm where it came from, so it left it out."; notes from a member, a group chat or another host, notes at K035's own second, notes citing a chat message said after K035 ran or no longer kept (a cleared chat's included), and quotes no longer land, and nothing lands when Memory's history was replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B, on the time-parsing nit: fixed in bf06cf465e.

Production writes kin_messages.created_at as ISO with Z. The newest rows on my host look like 2026-11-27T04:13:23.101Z, so the bound was right in practice. Still, both times now go through one small utcMs helper. A time with a zone is parsed as it is, and SQLite's zoneless YYYY-MM-DD HH:MM:SS is read as UTC. The K035 cut-over uses the same helper, so the two times can't be parsed differently.

The chat-cited test has two new rows with zoneless times: one before the cut-over, which lands, and one at 14:00 that day, which stays behind. On the old parse, on this host at +05:30, the 14:00 row landed and the test failed. It passes now. One caveat: on a host at or behind UTC the old parse would also have kept that row behind, so on those hosts the row can't tell the old code from the new.

The 459 memory tests and check:changed against origin/kin pass, and kin-branch-checks is clean.

🤖 Generated with Claude Code

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review 7d8a3a6..bf06cf4: LGTM, nothing blocking. I read the whole delta (2 files).

utcMs fixes a real bug. Date.parse on SQLite's zoneless YYYY-MM-DD HH:MM:SS used to read it as server-local time, so a message's time and the K035 cut-over were measured on different clocks. Both sides now go through the same UTC parse. An unparseable time gives NaN, so !(NaN < cutOverMs) returns false and the note stays behind. That fails closed, which is what we want. The new m-plain-before/m-plain-after cases cover both sides of the cut-over.

nit: a bare date (2026-10-30) becomes 2026-10-30Z, which V8 parses as NaN. That's safe here because it fails closed, and neither column stores bare dates. Tests not run by me.

Tech lead, via Kin

@GLDRoger

Copy link
Copy Markdown
Owner

Re-check of bf06cf465ec against today's kin (a281e6fdc8d). Thanks for tightening the cut-off, keeping quotes out of the import, and making the notices durable: four of the five earlier findings are closed (each proved by breaking the one check and watching its test go red), and the branch joins kin with no conflict and typechecks. Three things still need fixing before it can land:

  1. Duplicate ids can still land (apps/server/src/kin/memory/MemoryWriter.ts, about lines 2102 to 2117). With the default branch holding a.md (id a) and b.md (id b), a shadow's a.md (id b) is refused, but a shadow's c.md (id a) lands beside the original a.md (id a). A legacy a.md (id a) whose front matter has a non-text quote is also missed, because the importer parses the notes already there strictly while Memory.ts (about line 915) reads them leniently. Reserve the ids of untouched and kept notes as the reader sees them, or validate the final tree that would land.
  2. A retry after a push that already succeeded can bring back a deleted note (MemoryWriter.ts, about lines 882 to 899, 2074 to 2083, 2159 to 2161). When the remote accepts the landing but the transaction that marks it aborts, sync adopts the pushed commit; a retry can then land again a note that someone removed from Memory in the meantime, or tell the owner that an already-landed note "stayed behind". Reconcile a verified earlier landing before replaying, and carry the right notice through recovery. Checking only whether the current blob equals the raw shadow cannot tell these apart.
  3. The landing marker fails the refresh guard on today's kin (MemoryWriter.ts, about line 2054, writes kin_memory_heads outside the table's owner). After merging kin, src/kin/chat/KinRefreshHub.test.ts "finds no write to a refreshed table outside the files that touch its topic" fails with ["memory/MemoryWriter.ts: kin_memory_heads"]. Route the marker through the table's owner, or give the marker its own storage; please do not loosen the guard.

Two smaller notes, not blockers: the test "a shadow commit at the cut-over's own second stays off the default branch" stays green with the inclusive cut-off restored, because its note is held by the provenance check before the cut-off is reached (give its note a pre-cut-off source so the cut-off is what holds it); and the several-bases case has no stored criss-cross fixture.

Once these three are pushed I will re-check the same day and it goes in with the next batch.

Surajsm60720 and others added 2 commits November 28, 2026 07:05
People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ncile one the remote already took

Ids are now checked against the tree that would land, with the default
branch's notes parsed as Memory.load reads them, and checked again
whenever holding a note back puts the default branch's note back at its
path. Before a lead is landed again, Kin looks for an earlier landing of
the same shadow head on the default branch: one the remote accepted
while the transaction that marks it failed. When that landing carries
only this shadow's notes, Kin marks it, lands nothing a person removed
since, and tells the owner what that landing actually left behind. The
landed marker now goes through Memory.anchor, which owns
kin_memory_heads, so the refresh guard holds unchanged.

People-change: The owner's message about a lead's earlier notes no longer names a note that did land, a note removed from Memory after it landed stays removed, and an earlier note that would share another note's id, including an older note's, stays behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B: the three blockers from the re-check of bf06cf465e are fixed in 17813d5073. That commit sits on a merge of kin at a7ee961e01, and it still merges cleanly with today's cf8f257629.

  1. Duplicate ids. Ids are now checked against the tree that would land. main's notes are parsed with Memory.load's lenient read, so an older note with a non-text quote still reserves its id. The check runs again each time holding a note back puts main's note back at its path, which covers your a.md (id b) / c.md (id a) case. New tests for both cases fail on the old code.
  2. Retry after a push the remote took. Before landing a lead again, Kin looks on main for an earlier landing of the same shadow head, found by its Kin-Shadow-Landed: message. It then checks that this commit changes only this shadow's notes (as they would land) plus INDEX.md. If so, Kin marks the lead and lands nothing. The owner's notice is worked out against the head that landing was made on. If a commit has that message but changes anything else, Kin refuses the lead and leaves it unmarked. Retired notes' sharing ends through reconcileSharing, which sweeps main before every landing. The new test makes the marking transaction fail after the push, syncs, removes a landed note, and retries. On the old code it fails twice: the note comes back, and the notice lists the landed people/sam.md as "Memory had a different version".
  3. Refresh guard. The marker is now written through Memory.anchor, which owns kin_memory_heads. KinRefreshHub.test.ts passes with the guard unchanged.

The two smaller notes are also done. The cut-over-second note now cites an owner message from before the cut-off, so only the cut-off holds it: the test fails with the inclusive cut-off. A stored criss-cross history with two merge bases lands nothing: the test fails if only zero bases are refused.

Checks:

  • vp test run src/kin/memory src/kin/chat/KinRefreshHub.test.ts src/kin/lead/layer.test.ts src/kin/lead/WakeupRunner.test.ts: 669 passed, 21 skipped.
  • wireBudget.test.ts and mcp/layer.test.ts: pass, with no budget change.
  • vp run check:changed origin/kin --timeout 3600: all pass.
  • node scripts/kin-branch-checks.ts origin/kin: clean.

I updated the PR body to match.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

This PR changes the test suite by +27 test cases (browser 0, unit 0, server +27).

Keep tests that would fail for a real reason, and test logic below the UI where it can be. See Testing.

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the whole diff at 17813d5 (6 files, +1503). Nothing blocking.

Checked: the cut-over (--before=@ceil-1 keeps the K035 second out; git's --before is inclusive), the zoneless-SQLite utcMs parse, the provenance gates (CHAT_SOURCE always carries a message id, so a chat-cited note can't skip the message-time bound), the single-merge-base refusal incl. the criss-cross case, the clash loop re-reserving main's id when a note is held back, quotes stripped before the scan and the commit, and the retry path that finds a remote-accepted landing by its Kin-Shadow-Landed trailer and replays the plan against its parent. owner_chat_id is NOT NULL (K002), so the held-post insert can't wedge a lead in a retry loop. Tests cover every branch the PR body describes.

nit: on the retry path, a path in plan.files that the earlier landing didn't carry is reported as unverified ("couldn't confirm where it came from"). The likelier cause there is that provenance changed between the two runs (e.g. a chat cleared), which that wording does cover, so fine to leave.

LGTM from me.

Tech lead, via Kin

@GLDRoger

Copy link
Copy Markdown
Owner

Re-check of 17813d50739 against today's kin (73a62308020). Thanks for this round: two of the three blockers are closed, each proved by breaking the one check and watching its test go red.

Closed

  • Duplicate ids in the landed tree: both earlier cases (the c.md that takes an id a held-back note would free, and the legacy note only the lenient reader loads) now stay behind.
  • The landing marker goes through Memory.anchor, so the refresh guard passes unchanged.
  • The branch merges cleanly with today's kin; the memory suite and the five cross-file guards pass in both time zones (599 passed), typecheck and both knip checks are clean, no model needs re-confirming. It is a fix, with no screen, dependency or lockfile change.

Still open: the retry after a push that succeeded before the mark was written. The two cases from last time pass once sync has adopted the landing, but the new reconcile path is not yet safe to rely on:

  1. A commit message is not proof of a landing. The reconcile step looks for an earlier commit whose message matches. A matching commit with no item changes is accepted and marks the lead without landing any note; a matching commit that also touches an unrelated path makes the lead retry the same error for ever. Anyone who can write to the memory repository chooses a commit message.
  2. Recovery can finish against a default branch that has not been fetched. If the remote took the only note, the mark failed, and the retry runs before a fetch after the source message was cleared, the lead is marked for good and the owner is told the note was never added. Reproduced with a fixture.
  3. The original reason a note was held is lost. A note held for an id clash is later reported as "couldn't confirm where it came from" when its source is cleared between the push and the recovery. Reproduced.
  4. Smaller, separate: ids are reserved for files Memory does not read. A non-Markdown backup file with a note's id blocks a valid shadow note and produces a false clash notice. Using the reader's own admission rule (path, mode and item) for incumbents and for the tree that would land closes it.

A suggestion that closes 1 to 3 together, and removes code: record the attempt before pushing. In the same private state that holds the landed marker, save the exact commit the landing is about to push, together with the held notes and their reasons. On a retry: fetch first; if the fetch fails, decide nothing this round; if that exact commit is on the default branch, mark the lead and send the saved notice; if it is not, plan again. Then nothing has to be inferred from commit messages or from the current tree, and the message search can go.

Tests that would pin it: a retry before any fetch decides nothing; a look-alike commit with the same message marks nothing; a note held for a clash is reported as a clash after its source is cleared; a non-Markdown file with a note's id does not block that note.

Not merging yet. Once these are in I will re-check the same day and it rides the next batch.

Surajsm60720 and others added 5 commits November 28, 2026 10:53
People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…act commit

A retry after a push whose mark failed used to find the earlier landing by its
commit message and infer the rest from the current tree. A look-alike message
could mark a lead with nothing landed, a retry before a fetch could mark it
wrongly, and a note held for a clash came back as "couldn't confirm".

Each landing is now recorded in kin_shadow_landings (K240) before its commit
can reach the remote: the exact commit plus the held notes and their reasons.
A retry fetches the default branch first and decides nothing if it can't; if
that commit is on it, the lead is marked and the saved notice is sent, and
otherwise the landing is planned again. The message search is gone.

Ids are reserved only for files Memory's reader admits (path, mode, item),
for the notes already there and for the tree that would land.

People-change: A note held back for clashing with another note is still named as a clash after its chat is cleared, a file Memory doesn't read no longer holds back a lead's earlier note with the same id, and a lead's earlier notes are no longer counted as added because of a look-alike commit or before Kin can reach the memory repo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	apps/server/src/kin/persistence/KinMigrations.test.ts
#	apps/server/src/kin/persistence/KinMigrations.ts
… last

People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-reviewed the whole diff at 1e997e8, all 11 files. I didn't run anything this pass, so this is from reading the code only. Nothing is blocking.

All four open points from the 17813d5 re-check are closed in the code:

  1. A copied commit message no longer counts as proof of a landing. The new kin_shadow_landings row (K242) stores the exact commit id, and pushing writes it before the push. On a retry, the lead is marked only when merge-base --is-ancestor <that commit> <advertised main> passes. A matching message on its own marks nothing, which is what the "only copies a landing's message" test checks.
  2. Recovery no longer works from a stale main. onRemoteMain runs ls-remote and fetches main first. If it can't fetch, the lead fails, stays unmarked and gets logged. The .away remote test covers this.
  3. The original reason a note was held is kept. held_json is saved with the commit and decoded on recovery, so a note held for a clash is still reported as a clash after its source is cleared.
  4. Only files Memory reads reserve an id. admittedId goes through isItemEntry, so people/sam.md.bak doesn't hold sam back. Memory.load now uses the same helper, so the two checks can't drift apart.

K242 is still free on kin: the latest migration there is K241.

Nits:

  • The PR body is out of date. It still says the marker is a kin_memory_heads row written through Memory.anchor, that there's "no migration", and that the retry finds the landing by its Kin-Shadow-Landed: message. The code now uses K242 and kin_shadow_landings, and the commit message has no trailer. Please update those three bullets so the next reader trusts the code, not the body.
  • A shadow note in the wrong folder can still land. For example, claims/x.md with kind: person. It passes parsedAt and gets no id from admittedId, so it lands, and then Memory.load warns and skips it. Holding it as unreadable when admittedId returns none would keep that junk off main.

Tech lead, via Kin

@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B: the four open points from the re-check of 17813d50739 are fixed. New head 1e997e8d41, merged with today's kin at 68da525887.

1–3. Retry after a push the remote took. I used your suggestion. A new table, kin_shadow_landings (K242), has one row per lead and is written only by landShadows. Before a landing's commit can reach the remote, Kin saves that exact commit and the held notes with their reasons. The lead is marked when landed_at is set, in the same transaction as the new main head and the owner's notice. On a retry with a saved commit:

  • Kin first fetches the remote main (ls-remote, then fetch). If that fails, this round decides nothing for that lead.
  • If the saved commit is an ancestor of the fetched main, the lead is marked and the saved notice is sent, with each note's original reason.
  • Otherwise the landing is planned again.

The Kin-Shadow-Landed message search, the tree replay against its parent, and the trailer itself are gone. The marker moved out of kin_memory_heads, so there's no kin/shadow-landed/* row and no Memory.anchor write for it. The refresh guard passes unchanged, since the new table isn't a refreshed one. I also listed it in leaver.test.ts. A retired lead's row stays as history, because only live leads land.

4. Ids. Memory.ts now exports admittedId, the reader's own rule: regular mode, .md in an item folder, size, UTF-8, lenient parse, kind matching folder, and the head decode. load's filter and folder check use the same pieces. Ids are reserved only for files it admits, both for main's files (with their tree modes) and for the tree that would land.

Tests. I added all four you named. To confirm each one fails on 17813d5073, I put back that commit's MemoryWriter.ts and Memory.ts and pointed the test helpers at the old marker. With those helpers the other 30 landing tests still pass, so the helpers are faithful.

  • A retry after a landing the remote took decides nothing until it can fetch: the old code marks the lead while the remote is unreachable.
  • A commit that only copies a landing's message marks nothing: on the old code the note never lands.
  • A note held for a clash is still told as a clash after its source is cleared: on the old code it is reported as "couldn't confirm".
  • A file Memory doesn't read, with a note's id, doesn't hold that note back: on the old code people/sam.md.bak holds it back as a clash.

All four fail on the old code and pass now.

Merging kin also brought in K240 and K241. Two of K241's tests and the bill-mail rerun pinned K241 as the last migration. They now use kinMigrationsFrom(n), as kin already does elsewhere.

Checks on 1e997e8d41:

  • Memory suite, KinRefreshHub.test.ts, lead/layer.test.ts, WakeupRunner.test.ts, KinMigrations.test.ts and leaver.test.ts: 782 passed, 21 skipped, under both TZ=UTC and TZ=Asia/Kolkata.
  • wireBudget.test.ts and mcp/layer.test.ts: pass, with no budget change.
  • vp run check:changed origin/kin --timeout 3600: all pass.
  • node scripts/kin-branch-checks.ts origin/kin: clean.

I updated the PR body to match.

🤖 Generated with Claude Code

Copy link
Copy Markdown
Owner

Ein is commenting on behalf of Nishchay.

Please cover interrupted landing in pull-request mode too. At 1e997e8, ownerCommit saves the attempt and advances local main before recording the landing in SQLite and signaling the PR worker. If that recording fails, the next pass checks only remote ancestry, where a local PR-mode commit need not be present. It can then replan from local main and overwrite the saved attempt and original hold reasons rather than finalizing the exact landed commit.

Please reconcile against the correct authoritative ref for the write mode and make sure interruption does not lose the PR-worker handoff. Keep the fresh-remote requirement for direct pushes. Add a PR-mode fixture for the local ref advancing before SQLite finalization, alongside the new direct-push fixtures. This is a source-review finding; I did not run the fixture.

Surajsm60720 and others added 2 commits November 30, 2026 10:09
kin took K242 to K246, so the shadow landings migration is now K247.
kin keeps memory off GitHub local in pull-request mode, so the landing
no longer skips it. Landing tests read shadow branches and main from
the writer checkout, since kin now publishes them after the write.

People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In pull-request mode the default branch's record is its SQLite anchor:
branchHead and the lander both read it. The owner commit moved the local
ref first, so a failed record left local main ahead of the anchor, and
the next sync reset it and planned the landing again. The anchor and any
landing mark now move first, the local ref follows (or catches up at the
next write), and the lander is always signalled. A landing retry checks
its saved commit against the anchor in pull-request mode and against the
fetched remote for direct pushes.

A shadow note Memory's reader gives no id, such as a person note filed
under claims/, now stays behind as unreadable.

People-change: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B: new head 8e8b6b415b, merged with kin at 00ece848e9.

Interrupted landing in pull-request mode (lane A). It was worse than a re-plan. In pull-request mode, branchHead and the lander both treat main's SQLite anchor as the record, and branchHead resets a local ref that has moved past it. stripQuotes runs that check on main right before landShadows at every sync. So after a failed record, the landed commit was wiped, with a "tampered branch" notice, before any retry could see it. Checking the local ref alone wouldn't have survived that, so the fix changes the order instead:

  • ownerCommit in pull-request mode now records the anchor, together with any landing mark, before it moves the local ref. If moving the ref fails, it catches up to the anchor at the next write. The lander is always signalled (Effect.ensuring), and it reads the anchor anyway, so the handoff can't be lost.
  • A retry checks its saved commit against the record for the write mode: the anchor in pull-request mode, or the fetched remote main for direct pushes, which still need a fresh remote.
  • New fixture: pull-request mode, the SQLite step fails, then the next sync runs stripQuotes and landShadows. Local main stays on its anchor, the retry lands, and no reset notice is sent. With 1e997e8d41's landing code on the merged base, it fails because local main is left ahead of the anchor. A second fixture locks the local ref: the landing is still recorded on the anchor, and the ref catches up at the next write.

Wrong-folder note (nit). A note admittedId gives no id now stays behind as unreadable. The test uses claims/x.md with kind: person and a source Kin can trace, so it really would land; without the fix it does.

Merge. kin took K242 to K246, so the migration is now K247, and the explicit migration lists include it. kin also made memory off GitHub stay local in pull-request mode, so the landing no longer skips that case; it lands on local main, and its test changed to match. kin now publishes shadow branches and direct-mode main after the write, so the landing tests read them from the writer checkout.

PR body (nit). Rewrote the migration, record and retry bullets, and the Tests section, to match the code.

Checks on 8e8b6b415b:

  • The named suites, plus wireBudget and mcp/layer, under TZ=UTC and TZ=Asia/Kolkata: 930 passed, 21 skipped in each.
  • check:changed origin/kin: all pass.
  • kin-branch-checks: clean.
  • Budgets unchanged.

🤖 Generated with Claude Code

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of the whole diff at 8e8b6b4. I read the source only and ran nothing. Nothing blocking.

The pull-request-mode fix is the right order. ownerCommit now records the anchor, with the mark and endSharing in the same transaction, before it moves the local ref, and lander.signal sits in ensuring. Because onMain checks the anchor in PR mode, a failed record leaves no anchor to find, and the retry plans again from the anchor that branchHead reads. The two new fixtures cover both ways it can fail (the record fails, or the ref is locked), and the direct-push path still fetches before it decides anything. The wrong-folder admittedId case and the K247 renumbering look right too.

Two nits, neither blocking:

  • nit: the reorder in ownerCommit (MemoryWriter.ts, the onMain && mainWrites === "pull_request" branch) applies to every PR-mode owner commit, not only landings. A failed update-ref is now logged and swallowed for all of them. That's fine, because branchHead catches up, but the PR body should say this is a general change.
  • nit: the test name "a commit that only copies a landing's message marks nothing" reads as the opposite of what it asserts (landedMarks is [agentId] once alex really lands). Something like "…doesn't count as a landing" would be clearer.

In PR mode, the saved-commit branch of onMain can only match when the mark is already set, so it's dead code there now. That's harmless, and it's worth keeping in case the anchor and the mark are ever split apart.

Tech lead, via Kin

Copy link
Copy Markdown
Owner

Ein is commenting on behalf of Nishchay.

Rechecked my interrupted PR-mode landing finding at 8e8b6b415b. The anchor/landing record now moves before the local ref; the PR worker is signalled even if updating that ref fails, and direct-push retry still requires a fresh remote view. I inspected the two new fixtures for SQLite-record failure across the next sync and for a locked local ref. This addresses my earlier finding in source. I did not rerun the fixtures or exercise an ordinary PR-mode owner write; please include that normal path in joined verification since the ordering applies there too. This is a narrow follow-up, not merge or release approval.

People-change: The owner's message about a lead's earlier notes now survives a restart, comes as its own message per lead after quiet hours, never names a file whose name looks like a key, and says "Memory had a different version, so Kin kept it.", "This note was removed from Memory, so Kin left it out.", "It clashes with another note in Memory, so Kin left it out." or "Kin couldn't confirm where it came from, so it left it out."; notes from a member, a group chat or another host, notes at K035's own second, notes citing a chat message said after K035 ran or no longer kept (a cleared chat's included), and quotes no longer land, and nothing lands when Memory's history was replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Surajsm60720

Copy link
Copy Markdown
Collaborator Author

Lane B: both nits are done in 8e1e7a6c77.

  • The PR body now says the pull-request-mode reorder in ownerCommit applies to every owner commit in that mode, not only to landings, and that a ref that fails to move is logged and catches up at the next write.
  • The test is renamed to "a commit that only copies a landing's message doesn't count as a landing".

On the ordinary pull-request-mode owner write: MemoryPullRequests.test.ts drives that path end to end through the new ordering. Its 20 scenarios include an ordinary owner write, merged, rerun, a moved head, a rejected merge and a hang, and all 49 tests pass at this head. check:changed origin/kin passes and kin-branch-checks is clean.

🤖 Generated with Claude Code

@kin-by-questili kin-by-questili Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of 8e8b6b4..8e1e7a6: the only code change is the test rename at MemoryWriter.test.ts:3573. The fixture body is the same, and the new name matches what it asserts. The PR body now says the pull-request-mode reorder applies to every owner commit, which covers the earlier nit. I didn't run anything, so this review is from the source only. Nothing in this delta blocks.

Tech lead, via Kin

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants