Skip to content

feat(apps): hold adoption until a built-in's legacy state move seals - #37464

Merged
bolichen97 merged 2 commits into
mainfrom
feat/app-seam-adopt-after-state-move
Nov 15, 2026
Merged

bolichen97 merged 2 commits into
mainfrom
feat/app-seam-adopt-after-state-move

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: When Notes (or any built-in whose state core still moves) is adopted onto its own repository, the user's token, vaults and settings arrive with it, even if the app was disabled at the upgrade or an older sandbox was still running.

Pre-#36365 hosts keep the Notes state (GitHub PAT, vaults.json, settings.json) in <home>/md-notebook-staging/. Only md_notebook_state.move_state_to_app_data moves it into apps/md-notebook/data/state/, and its only caller ran from the shipped Notes backend's start. Adoption APPLY runs at a later boot, so the move ran only if the shipped backend had started and sealed it before then. Two hosts lose it: Notes disabled at the upgrade (the backend never spawns, nothing moves, the adopted backend opens an empty data/state/: no vaults, no PAT, auto-sync off, and nothing retries), and a host where a sandbox of an older build held the move on boot 1 (boot 2 adopted anyway). The files stay masked in md-notebook-staging/, but to the user the data is gone. Found in the #37450 round, verified on origin/main 4a3697d.

Why it matters

Pinning md-notebook for adoption would silently empty Notes for every upgrading user who had it disabled, or who had a long-running older sandbox. The owner ruling for #26967 (comment 6841699202) is that adoption must not affect anyone's normal use. This has to land before the md-notebook pin row does.

Not a goal

  • Adding the md-notebook pin row, touching adoption-pins.json or the catalog, or deleting any built-in.
  • Running the move at boot for a built-in that is not pinned. Today's hosts keep exactly today's behaviour: the move still runs only from the shipped Notes backend's start.
  • Removing core's knowledge of the old Notes layouts (masks, stubs, sweeps). Those rows stay in the decoupling gate until no supported upgrade path can hold them.

What changed (motivation → approach → change)

Root cause: the second move was reachable only from the shipped backend's start, and adoption never checked that it had sealed. The fix gives core one table, apps/legacy_state_moves.LEGACY_STATE_MOVES, with one data row per app whose state core moves (today only Notes). A row is two callables of the core module that owns the move: seal() and start_refusal(). No manifest field reads or adds a row.

  • APPLY holds the swap. Before copying the staged tree, APPLY runs the row's move. Until it seals, the outcome is state_move_pending: the ledger stays staged, a grant left by a crash is rolled back like the other holds, the built-in keeps running, and the next boot tries again. The move runs whether or not the app is enabled, under its existing checks (no live older sandbox masking only the old dir, crash-safe order, no second hard link on the token).
  • Adopted records still get it. For a record adopted under pin trust (adopted_under_pin_trust), APPLY runs the move at every boot. A third-party record under the name, or a grant bound elsewhere, gets neither the move nor the wait, so the token is never written into another app's data dir.
  • The backend spawn uses the row's start gate instead of an md-notebook branch, on the shipped built-in's provenance or pin trust. Both Notes refusals keep their exact log wording; their logic moved to md_notebook_state.backend_start_refusal.
  • The row key is a stated exception, not a hidden one. It is the one place adoption names an app: core's own move out of a layout core created, which the built-in cannot declare because its package leaves the wheel while an adopted host still needs the move. The key is a literal; both name gates list it, and it goes with the old layouts (§33 and §34 say so).
  • Second commit, fix(md-notebook): a first move hard-killed after copying the legacy PAT and before its seal left the bare workspace/md-notebook/pat holding the token for good. The next pass now empties it when the destination holds the same bytes. The stop-at-each-step tests found it.

Docstrings that said only the shipped start checks the second move (src/kiro_crew/sandbox_staging.py, md_notebook_state.py) now name the row's callers.

Host-side gate only, nothing an app can reach, so no APP_SDK_LEVEL bump. Specs: app-kit-platform.md §33 ("A legacy state move holds the swap") and §34, md-notebook.md (State Layout, Tests). Authority: #26967 comment 6841699202. The 2026-11-07 rulings (comment 6713005850) are untouched: no sandbox exemption and no widening.

Backwards compatibility

Compatible: nothing main accepts is rejected, renamed or removed; with no pin for md-notebook APPLY never asks the table, and the shipped Notes start runs the same moves with the same refusals and wording.

One change does reach today's hosts, pinned or not, and it is its own commit: the first move (every sandbox spawn prep, and the shipped Notes start) now empties the bare workspace/md-notebook/pat when md-notebook-staging/pat already holds the same bytes, as it already did right after a fresh copy. That is tighter, not looser: it takes away a second copy of the token and keeps the one the backend reads. A different destination PAT keeps the legacy one, as before.

Reader: src/kiro_crew/md_notebook_state.py:migrate_legacy_state -- release -- the token is read from md-notebook-staging/pat, which holds the same bytes; test_a_pat_an_interrupted_pass_copied_is_emptied_by_the_next
Reader: src/kiro_crew/sandbox_precreate.py:_MD_NOTEBOOK_PRECREATE_CONTENT -- chat|cron|subagent -- the emptied legacy PAT is the zero-byte absent-equivalent stub its mask mounts on; test_the_legacy_pat_is_emptied_in_place_not_unlinked
Reader: docs/system-specs/modules/md-notebook.md:Rollback loses the PAT -- release -- an older build reading the bare name finds no token, the same documented outcome as an uninterrupted pass

Tests

test/test_legacy_state_moves.py (new) runs STAGE and APPLY end to end with the real Notes moves on the adoption fixture app:

  • a disabled built-in's state moves before the swap and the swap carries it;
  • an older-build sandbox, or an unreadable process table, holds the swap on every boot with no tree copied; the next boot adopts once it ends;
  • a stop at each of eight steps of both moves, as an error and as a hard kill, holds the swap and loses nothing; the next boot adopts with all three files and both old PATs emptied;
  • a second hard link on the old PAT holds the swap;
  • a crash-surviving grant is rolled back while the move holds;
  • an adopted record whose move never ran gets it at the next boot (enabled or disabled), waits for an older sandbox too, and its backend start asks the row (real pin trust).

Those cases run the real moves, so they are POSIX-only, like test_md_notebook_state.py's move tests. A fake-row test of the same hold, release and per-boot ask runs on every platform.

test/test_app_backend_spawn_env.py::TestTheSpawnAsksALegacyStateMoveOnProvenance drives the real backend spawn, so the provenance it passes is pinned by behaviour, not by source text: the shipped built-in is held while its row refuses (with the App md-notebook: <reason> log line) and starts once it answers None; another app under the name is never asked and starts; a record adopted under pin trust is held; and Notes' real row holds the shipped built-in for an older sandbox with the built-in's exact wording. Mutating the call site to builtin=True or builtin=False, or dropping the pin-trust branch of backend_start_refusal, now fails 1, 3 and 2 tests respectively.

Negative tests, so nothing reaches past what the row declares:

  • a record adopted under another trust gets no move and no start wait;
  • an app without a row is never held, and Notes' pending move runs for no other app;
  • a third-party record gets neither the move nor the wait;
  • the table is immutable core data naming only Notes;
  • a manifest key cannot declare a move.

Name gates: test_builtin_adoption_pins.py now scans apps/legacy_state_moves.py as an adoption module, allows only its listed key, and compares the live keys to that list; test_core_md_notebook_decoupling.py lists the key (and drops the apps/backend.py row). test/test_md_notebook_state.py adds the interrupted-pass PAT cases (fix commit).

Locally, on main 4c530d0: 4745 passed, 7 skipped across the 94 test files that reference the touched modules or the Notes app, under -n 8. One earlier run of the same set had one red, test_md_notebook_real_sandbox.py::test_the_move_waits_for_a_sandbox_that_masks_only_the_old_dir[leader-exited]: the unchanged process-table probe answered None on a busy host; it passes alone and passed on the rerun. mypy (4687 files), flake8, isort, black gate, subprocess-encoding, comment-history, brand, line cap, harness parity, docs-lint and the flake-pattern ratchet are clean. Semgrep is not installed on this host, so the SAST job is the first semgrep run.

Proof: not provable -- other: prove.py reverts every production hunk at once, which removes legacy_state_moves and fails collection (and its per-hunk run hit an environment error); reverting only the fix commit's hunks by hand fails test_a_pat_an_interrupted_pass_copied_is_emptied_by_the_next and test_a_move_stopped_at_any_step_holds_the_swap_and_loses_nothing[first-copy-kill].

Manual verification

N/A — the fixture boots exercise STAGE, APPLY and the real moves against an isolated data home, which is the path an upgrading host takes; no UI changes.

Related Issues

Part of #26967. Owner ruling: #26967 comment 6841699202 (no impact on existing users). Data-loss finding from the #37450 round. Only lane in this batch: adopt-after-state-move. apps/backend.py is also touched by #35334 (different hunk) and app-kit-platform.md §33 by #37450 and #37411 (different paragraphs).

Sibling sweep

Swept: git grep -nE "_empty_in_place|_empty_moved_pat" -- src/
Sibling: src/kiro_crew/md_notebook_state.py:368 -- not affected -- the second move's sealed pass empties a still-full old PAT on every call (_empty_moved_pat)

Pattern harvest

Rule candidate: review-prompt
Pattern: a resumable copy-then-delete that skips a destination it finds already written also skips the delete, so a pass stopped between the two leaves the source copy for good.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 15, 2026 02:31
@bolichen97
bolichen97 enabled auto-merge (squash) November 15, 2026 02:31
@bolichen97

Copy link
Copy Markdown
Contributor Author

Decisions taken under the #26967 owner ruling (comment 6841699202, "users' normal use is not affected"), for reviewers:

  1. Where the move runs. It runs at APPLY, for a pinned built-in-owned record and for a record adopted under pin trust, and at backend start as before. It does not run at every gateway start for an unpinned built-in. That keeps today's hosts byte-identical, and an older-build rollback is not exposed to the PAT move before adoption actually needs it.
  2. No APP_SDK_LEVEL bump. Nothing here is reachable from an app: there is no manifest field and no ctx attribute. The pin table that would name md-notebook ships in the same wheel as this gate, so no host can adopt without it.
  3. The linked-workspace/md-notebook start refusal moves with the row. It is part of the same legacy-layout start gate. Without it, an adopted Notes would start on a degraded layout and lose writes. The log wording is unchanged and pinned.
  4. An interrupted first move empties the legacy PAT. This is a defect in the move that the stop-at-each-step tests exposed. A hard kill between the PAT copy and the seal left the token at the bare legacy name for good. The fix is narrow: empty it only when the destination holds identical bytes, and only after the directory sync.

Not in this PR (per the batch brief): the md-notebook pin row, adoption-pins.json, the catalog. After this opens, the app repo's PORTING.md "Remaining gaps 1" is corrected separately. It currently says spawn prep gives an external backend the move.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

No design-level concerns: the new hold blocks the swap until the core-owned state move seals, the new table is the only place adoption names an app, and both name gates cover it.

Notes

  • If a sandbox from an older build never exits, state_move_pending keeps adoption on hold at every boot, and the only sign is a warning. The built-in keeps running, so this is safe and reversible. Before the md-notebook pin row lands, consider giving the operator a status line they can see.

[DESIGN-REVIEWED] 8c3ddcb

Description read

[DESCRIPTION-READ] a768f3e1c47a30ddd403fbabd5935935f0a0a7743c938954399d67077e69c2c4

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

One note: a registry built for a single row.

Notes

  • Item 1 — one consumer, generalized: LEGACY_STATE_MOVES holds one row ("md-notebook"). The LegacyStateMove dataclass, the legacy_state_move() lookup and the claim to cover "any built-in whose state core still moves" wrap that one key. The pattern I grepped ("md-notebook"|MD_NOTEBOOK_APP_NAME under src/kiro_crew/apps) finds no second core-owned move; the auto_research migrate_legacy_db is app-local, not a core layout. Subtraction: drop the dataclass and the mapping, and have the three helpers branch on name == MD_NOTEBOOK_APP_NAME and call md_notebook_state directly. The "stated exception" name gate stays the same.

What this change ships

Inventory (6 items) — 5 justified

Intent: when Notes is adopted onto its own repository, the user's PAT, vaults and settings arrive with it, even if Notes was disabled at the upgrade or an older sandbox was still running. FIX.

  1. Adoption of a built-in waits, outcome state_move_pending, until its legacy state move seals — one consumer, generalized
  2. An adopted record gets the pending move run at every boot when it holds pin trust — justified
  3. The Notes backend start gate moved out of backend.py into md_notebook_state.backend_start_refusal, with the same wording — justified
  4. The backend start gate is now also asked for records adopted under pin trust — justified
  5. A legacy PAT left behind by a move that was killed mid-way is now emptied when the destination holds the same bytes (second commit) — rides along
  6. New public sealed_legacy_state(state_dir, legacy_dir, app_state_dir) that takes the directories as parameters — justified

[FIRST-PRINCIPLES-REVIEWED] 8c3ddcb

Description read

[DESCRIPTION-READ] 2e10001cc24debcb301e14afa78cff9a7e7f192a69034d3190833318d1a510ff

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8c3ddcb

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8c3ddcb

Verdict parsed from the review's SHA-scoped output markers for commit 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 8c3ddcb0c0c3ddbdeab18752cd59b34ce258a6e2 false-positive: <reason, 20 to 500 characters>

KiroCrewCaptain added a commit to KiroCrewCaptain/kirocrew-app-md-notebook that referenced this pull request Nov 15, 2026
Spawn prep runs only the first move. The move into data/state ran only
from the shipped backend's start, so an adopted backend got neither the
move nor the wait. kirodotdev/KiroCrew#37464 closes it in core.

Co-authored-by: Bolin Chen <bolichen@amazon.com>
@bolichen97
bolichen97 force-pushed the feat/app-seam-adopt-after-state-move branch from afde7ff to f7c6bbf Compare November 15, 2026 03:29
@bolichen97

Copy link
Copy Markdown
Contributor Author

Review round on afde7ff: all four findings fixed. The branch is now two commits, rebased on main: fix(md-notebook) and then the feat(apps) seam. Head: f7c6bbf.

1. The spawn's provenance was only covered by source-string tests. Fixed. Added test/test_app_backend_spawn_env.py::TestTheSpawnAsksALegacyStateMoveOnProvenance. It runs the real start_app_backend with a recording row in four cases:

  • the shipped built-in is held while its row refuses, with the App md-notebook: <reason> line, and starts once the row answers None;
  • another app installed under the name is never asked, and it starts;
  • a record adopted under pin trust is held;
  • Notes' real row holds the shipped built-in while an older sandbox is alive, with the built-in's exact wording, and the token stays in md-notebook-staging/.

test_legacy_state_moves.py adds a test where a real pin-trust adoption makes backend_start_refusal(name, builtin=False) ask the row. I re-ran your three mutations against these two files. builtin=True now fails 1 test, builtin=False fails 3, and dropping the pin-trust branch fails 2.

2. A core table keyed on an app id that no name gate could see. Fixed. The key is now the literal "md-notebook" in apps/legacy_state_moves.py, and md_notebook_state.APP_NAME is gone (APP_STATE_PARTS is byte-identical to main again). Both gates now see the key:

  • test_builtin_adoption_pins.py adds apps/legacy_state_moves.py to _ADOPTION_MODULES. It allows only the key listed in _STATED_NAME_EXCEPTIONS, with the reason. test_the_legacy_state_move_rows_are_the_stated_exception compares the live keys to that list, so a key spelled through a constant also fails.
  • test_core_md_notebook_decoupling.py gives the key its own row with its own reason.

app-kit-platform.md §33 (the "Core names no app" sentence and the legacy-move paragraph) and §34's intro now state the exception and why it is not a §34 seam. The move's code is core's, because core created the layout. The built-in's package leaves the wheel while an adopted host still needs the move.

3. Stale comments still said only the shipped start runs the second move. Fixed, with every site I found:

  • sandbox_staging.py: _migrate_md_notebook_legacy_state and _md_notebook_degraded_mask_dirs;
  • md_notebook_state.py: the module docstring, and move_state_to_app_data, whose one caller is now sealed_legacy_state;
  • test_md_notebook_state.py (the comment you cited) and the docstring in test_sandbox_md_notebook_carveout.py;
  • md-notebook.md "Legacy move", which now says adoption runs the first move too.

Lines that only say "the next spawn" or "the backend does not start" are still true, so I left them.

4. The PAT change was bundled into the feat commit, and the body called it no change. Fixed. It is now its own first commit, fix(md-notebook): empty a legacy pat a stopped first move had copied, with its tests and spec sentence, and it is green on its own. The feat commit's message no longer mentions it. ## Backwards compatibility now says this commit reaches every host, pinned or not, and that it only removes a second copy of the token. The body also gains ## Sibling sweep and ## Pattern harvest for it.

I did not edit the ## Not a goal line. It is frozen, and only a human can ask for that. Its claim is about where the move runs, and that has not changed.

Gates: mypy, flake8, isort, black gate, subprocess-encoding, comment-history, brand, line cap, harness parity, docs-lint and the flake-pattern ratchet all pass. The related set gave 4691 passed and 24 skipped. The only failure is test_the_seatbelt_profile_is_the_golden, which fails the same way on a pristine origin/main tree on this host.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/sandbox_staging.py

  • @bolichen97 posted a complete reasoning template for 8c3ddcb.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: f7c6bbf
  • What rule changed: no sandbox rule changed. src/kiro_crew/sandbox_staging.py is touched only in two docstrings (_md_notebook_degraded_mask_dirs, _migrate_md_notebook_legacy_state), which now name md_notebook_state.backend_start_refusal / sealed_legacy_state (reached through apps/legacy_state_moves) as the callers that check the second Notes move, instead of an inline block in apps/backend.py. No mask, seal, carve-out, disposition or path list changes.
  • Before -> after (what was allowed/blocked, now): sandbox masks and visibility are byte-identical before and after. The start gate those docstrings describe keeps both refusals with the same log wording: the Notes backend still does not start until the state move seals, nor while workspace/md-notebook is reached through a link. The one behaviour change near this file is in md_notebook_state.migrate_legacy_state (the first move that spawn prep runs): when md-notebook-staging/pat already holds the same bytes as the bare legacy workspace/md-notebook/pat, the legacy copy is now emptied in place after the directory sync, as it already was right after a fresh copy. That removes a second copy of the token; it opens nothing.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): the Notes backend refuses to start (its existing "not starting until its one-time state move finishes" line) until the next start, or a byte-equal legacy PAT is emptied while the moved copy remains; no secret becomes visible to an agent, because every mask that covers both PAT names is unchanged.
  • Evidence checked (which sandbox result proves it): on this head, test_sandbox_md_notebook_carveout.py, test_sandbox_governance_mask.py, test_md_notebook_state.py (including test_the_legacy_pat_is_emptied_in_place_not_unlinked and test_a_pat_an_interrupted_pass_copied_is_emptied_by_the_next) and test_app_backend_spawn_env.py::TestTheMdNotebookBackendCanSeeItsOwnStateFiles pass locally; CI's Backend Tests (namespace sandbox) and Backend Tests (crew container) jobs passed on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): the real backend spawn path runs in test_app_backend_spawn_env.py (shipped built-in starts once the row answers None, is held while an older sandbox is alive, another app under the name starts unasked); 985 passed across the seven related files (test_md_notebook_state.py, test_sandbox_md_notebook_carveout.py, test_legacy_state_moves.py, test_app_backend_spawn_env.py, test_sandbox_governance_mask.py, test_builtin_adoption_pins.py, test_core_md_notebook_decoupling.py).
    • Backward compatible (old config / old data / old callers still work, how checked): with no md-notebook pin, APPLY never consults the new table, and the shipped Notes start runs the same two moves with the same refusals and wording (pinned by TestTheSpawnAsksALegacyStateMoveOnProvenance); a host with a different destination PAT keeps its legacy PAT as before; rollback to an older build finds no token at the bare name, the same documented outcome as an uninterrupted pass (md-notebook.md "Rollback loses the PAT").
    • Existing tests (which suites passed on this head): Backend Lint & Type Check (3.12), Backend Ratchets & Boundaries, Backend Tests (namespace sandbox), Backend Tests (crew container), New-test stability (ubuntu-latest and windows-latest), Integration (in-process gateway), E2E Gateway Boot (ubuntu and windows), Windows Fail-Closed Sandbox Contract, SAST (Semgrep); the sharded Backend Tests matrices are still running at the time of this comment.
  • How to undo: revert the two commits of this PR (fix(md-notebook) 3d51560 and feat(apps) f7c6bbf); no data migration needs undoing, since an emptied legacy PAT is the same zero-byte stub an uninterrupted first move leaves.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 7) on f7c6bbf is red on one test, which this diff does not touch: test/test_denied_commands_security_cost.py::TestSelfModuleIndexIsLinear::test_the_scan_is_linear_not_quadratic (AssertionError: 2k tokens took 0.511s; 1 failed, 34844 passed, job, ubuntu). This is the wall-clock flake tracked in #37446, and #37451 (still open) fixes it. I will rerun this one failed job once after the CI run completes, and leave the test alone.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own.

APPLY now waits for Notes' core-owned state move to finish before it swaps the record (state_move_pending, ledger stays staged, crash-left grant rolled back), whether or not the app is enabled. It never runs on today's unpinned hosts, because apply_all only visits pinned apps. seal_adopted and the backend start gate act only on the shipped built-in's provenance or adopted_under_pin_trust. That check is strict and fails closed, so no third-party record gets the token. Refusal wording and home resolution are unchanged. The interrupted-PAT fix empties the old PAT only when the new location holds the same bytes, and only after the directory sync. Tests are thorough: end-to-end runs with the real moves, a stop at each step, provenance checked through the real backend spawn, and negative cases. The CI failures look unrelated flakes; the Coverage Gate cause was not visible, and eight jobs were still pending.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit f7c6bbf6bb · 1180 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 15, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve on f7c6bbf. This PR stops adoption from swapping Notes onto its own repository before core has moved the user's token, vaults and settings into the app's data directory. APPLY now runs the move first and holds the swap until it seals, whether or not Notes is enabled; the built-in keeps running and the next boot tries again. A record already adopted from the wheel's pin gets the move at every boot, and a third-party app under the same name gets neither the move nor the wait. The backend start gate keeps the exact refusals and wording it had. The second commit closes a gap where a first move stopped after copying the token left a second copy of it behind. I ran the touched test files on this head: 288 passed. Removing the APPLY hold turns 21 tests red, including the stop-at-each-step tests that show nothing is lost on an error or a hard kill. Removing the per-boot move for adopted records turns 5 red, removing its pin-trust check turns 2 red, removing the token-emptying fix turns 2 red, and removing the spawn's refusal turns 3 red. The specs are updated in the same commits. Follow-ups, none blocking: a host where the move never seals (an older sandbox that never ends) holds adoption with only a log line each boot, so a later surface for adoption holds would help; and the release that removes Notes from the wheel must handle hosts that are still held. Decisive lines: src/kiro_crew/apps/builtin_adoption_apply.py:517-521, src/kiro_crew/apps/builtin_adoption_apply.py:703, src/kiro_crew/apps/legacy_state_moves.py:104-135, src/kiro_crew/apps/backend.py:1228-1231, src/kiro_crew/md_notebook_state.py:274-316

@bolichen97

Copy link
Copy Markdown
Contributor Author

Status on f7c6bbf:

@bolichen97

Copy link
Copy Markdown
Contributor Author

macOS Tests / Backend Tests (macOS) (4) on f7c6bbf failed on the first run and again on its one rerun (rerun job). Both times the same three tests failed: test_readonly_source_skill_install.py::TestBuiltinSyncFromReadonlySource. This diff touches neither that file nor the skill-sync code. Shard 4 has the same red on more than ten other heads since 2026-11-14 (ledger #37391), and #37476 fixes it. The lane is on demand and not required. Next step: once #37451 and #37476 merge, rebase onto them, push once, and re-post the Sensitive Change Review template for the new head.

A first-move pass hard-killed after copying workspace/md-notebook/pat
into md-notebook-staging/ and before writing its marker left the token
at both names. The next pass found a real destination, skipped the
copy, and so never emptied the bare legacy PAT: a token the user may
revoke stayed at a second name for good.

The next pass now treats a destination PAT holding the legacy bytes as
copied: it syncs the directory and empties the legacy PAT in place, as
after a fresh copy. A different destination PAT keeps the legacy one,
as before. Every host runs this, pinned or not (each sandbox spawn prep
and the shipped Notes start run the first move); it only removes a
second copy of the token.

Part of #26967
Pre-#36365 hosts keep the Notes state in md-notebook-staging/, and only
the shipped Notes backend's start moved it into apps/md-notebook/data/.
Adoption swaps the record at a later boot, so a host whose Notes was
disabled at the upgrade, or had an older-build sandbox alive, would be
adopted onto an empty data/state/ with nothing ever retrying the move.

Add a core-owned table, apps/legacy_state_moves, with one data row per
app whose state core still moves (today only Notes). APPLY runs the
row's move before the swap, enabled or not, and holds the swap with the
ledger left staged until it seals; a record adopted under pin trust gets
the move at every boot; the backend spawn waits for it for the shipped
built-in or a pin-trusted adopted record. No manifest field reaches the
table, and a third-party record under the name gets neither move nor
wait.

The row key is the one place adoption names an app: core's own move
out of a layout core created. It is a literal that both name gates list
as a stated exception, and it goes with the old layouts.

Part of #26967
@bolichen97
bolichen97 force-pushed the feat/app-seam-adopt-after-state-move branch from f7c6bbf to 8c3ddcb Compare November 15, 2026 06:32
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 8c3ddcb
  • What rule changed: no sandbox rule changed. src/kiro_crew/sandbox_staging.py is touched only in two docstrings (_md_notebook_degraded_mask_dirs, _migrate_md_notebook_legacy_state), which now name md_notebook_state.backend_start_refusal / sealed_legacy_state (reached through apps/legacy_state_moves) as the callers that check the second Notes move, instead of an inline block in apps/backend.py. No mask, seal, carve-out, disposition or path list changes.
  • Before -> after (what was allowed/blocked, now): sandbox masks and visibility are byte-identical before and after. The start gate those docstrings describe keeps both refusals with the same log wording: the Notes backend still does not start until the state move seals, nor while workspace/md-notebook is reached through a link. The one behaviour change near this file is in md_notebook_state.migrate_legacy_state (the first move that spawn prep runs): when md-notebook-staging/pat already holds the same bytes as the bare legacy workspace/md-notebook/pat, the legacy copy is now emptied in place after the directory sync, as it already was right after a fresh copy. That removes a second copy of the token; it opens nothing.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): the Notes backend refuses to start (its existing "not starting until its one-time state move finishes" line) until the next start, or a byte-equal legacy PAT is emptied while the moved copy remains; no secret becomes visible to an agent, because every mask that covers both PAT names is unchanged.
  • Evidence checked (which sandbox result proves it): this head is f7c6bbf rebased onto main 4c530d0 with no conflict; git range-diff shows both patches identical. On this head, test_sandbox_md_notebook_carveout.py, test_sandbox_governance_mask.py, test_md_notebook_real_sandbox.py, test_md_notebook_state.py (including test_the_legacy_pat_is_emptied_in_place_not_unlinked and test_a_pat_an_interrupted_pass_copied_is_emptied_by_the_next) and test_app_backend_spawn_env.py::TestTheMdNotebookBackendCanSeeItsOwnStateFiles pass locally; CI's Backend Tests (namespace sandbox) and Backend Tests (crew container) passed on the previous head with the same patches and are re-running on this one.
  • No regression:
    • Tools still work (which tools/commands were run, result): the real backend spawn path runs in test_app_backend_spawn_env.py (shipped built-in starts once the row answers None, is held while an older sandbox is alive, another app under the name starts unasked); the seven related files pass (test_md_notebook_state.py, test_sandbox_md_notebook_carveout.py, test_legacy_state_moves.py, test_app_backend_spawn_env.py, test_sandbox_governance_mask.py, test_builtin_adoption_pins.py, test_core_md_notebook_decoupling.py).
    • Backward compatible (old config / old data / old callers still work, how checked): with no md-notebook pin, APPLY never consults the new table, and the shipped Notes start runs the same two moves with the same refusals and wording (pinned by TestTheSpawnAsksALegacyStateMoveOnProvenance); a host with a different destination PAT keeps its legacy PAT as before; rollback to an older build finds no token at the bare name, the same documented outcome as an uninterrupted pass (md-notebook.md "Rollback loses the PAT").
    • Existing tests (which suites passed on this head): locally, isort, flake8, mypy (4687 files), the black gate, subprocess-encoding, comment-history, brand, line cap, harness parity, docs-lint and the flake-pattern ratchet are clean, and the 94 test files that reference the touched modules pass (one load-only red, see the PR body). On the previous head with the same patches every CI lane passed except two tests this diff does not touch, now fixed on main by test: hold the self-module scan budget to the minimum of five readings #37451 and fix(skills): let a read-only built-in skill source publish on macOS #37476; the CI matrix is re-running on this head.
  • How to undo: revert the two commits of this PR (fix(md-notebook) f3ee79a and feat(apps) 8c3ddcb); no data migration needs undoing, since an emptied legacy PAT is the same zero-byte stub an uninterrupted first move leaves.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased f7c6bbf onto main 4c530d0 as 8c3ddcb (no conflict; git range-diff shows both patches identical), so the head now carries #37451 and #37476:

The Sensitive Change Review reasoning template for 8c3ddcb is posted above. CI is re-running on the new head.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 15, 2026
@bolichen97
bolichen97 merged commit 1d97edc into main Nov 15, 2026
105 checks passed
@bolichen97
bolichen97 deleted the feat/app-seam-adopt-after-state-move branch November 15, 2026 07:50
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 15, 2026
bolichen97 added a commit that referenced this pull request Nov 17, 2026
Notes (md-notebook) now lives in its own repository under
KiroCrewCaptain, ported from the current wheel copy, with green CI on
ubuntu, macOS and Windows. Its row is the output of
scripts/adoption_pin.py compute and is added to adoption-pins.json and
the _SHIPPED_PINS table, so a host whose record is builtin-owned moves
onto the app's own tree at its next restart and keeps data/ (the vaults,
settings and GitHub token in data/state/), the app secret, the grants
and enabled. A host still on the md-notebook-staging/ layout is adopted
only once core's state move has sealed (#37464).

The wheel built-in app.json version moves to the pinned 1.0.2, since a
first-adoption pin must equal it (D12). The repository declares the
same permissions and credentialMasks as the wheel copy, so E9 holds
nothing back. The owning spec records the adoption.

Part of #26967
bolichen97 added a commit that referenced this pull request Nov 17, 2026
Notes (md-notebook) now lives in its own repository under
KiroCrewCaptain, ported from the current wheel copy, with green CI on
ubuntu, macOS and Windows. Its row is the output of
scripts/adoption_pin.py compute and is added to adoption-pins.json and
the _SHIPPED_PINS table, so a host whose record is builtin-owned moves
onto the app's own tree at its next restart and keeps data/ (the vaults,
settings and GitHub token in data/state/), the app secret, the grants
and enabled. A host still on the md-notebook-staging/ layout is adopted
only once core's state move has sealed (#37464).

The wheel built-in app.json version moves to the pinned 1.0.2, since a
first-adoption pin must equal it (D12). The repository declares the
same permissions and credentialMasks as the wheel copy, so E9 holds
nothing back. The owning spec records the adoption.

Part of #26967
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants