Repository navigation
feat(apps): hold adoption until a built-in's legacy state move seals - #37464
Conversation
|
Decisions taken under the #26967 owner ruling (comment 6841699202, "users' normal use is not affected"), for reviewers:
Not in this PR (per the batch brief): the md-notebook pin row, |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of 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
[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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS One note: a registry built for a single row. Notes
What this change shipsInventory (6 items) — 5 justifiedIntent: 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.
[FIRST-PRINCIPLES-REVIEWED] 8c3ddcb Description read[DESCRIPTION-READ] 2e10001cc24debcb301e14afa78cff9a7e7f192a69034d3190833318d1a510ff That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
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>
afde7ff to
f7c6bbf
Compare
|
Review round on afde7ff: all four findings fixed. The branch is now two commits, rebased on main: 1. The spawn's provenance was only covered by source-string tests. Fixed. Added
2. A core table keyed on an app id that no name gate could see. Fixed. The key is now the literal
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:
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, I did not edit the 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 |
Sensitive Change ReviewSensitive files changed:
|
Sensitive change review
|
|
|
Code change approver recommendation: A person should decideWhy: 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 |
buluoray
left a comment
There was a problem hiding this comment.
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
|
Status on f7c6bbf:
|
|
|
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
f7c6bbf to
8c3ddcb
Compare
Sensitive change review
|
|
Rebased f7c6bbf onto main 4c530d0 as 8c3ddcb (no conflict;
The Sensitive Change Review reasoning template for 8c3ddcb is posted above. CI is re-running on the new head. |
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
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
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/. Onlymd_notebook_state.move_state_to_app_datamoves it intoapps/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 emptydata/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 inmd-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
adoption-pins.jsonor the catalog, or deleting any built-in.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()andstart_refusal(). No manifest field reads or adds a row.state_move_pending: the ledger staysstaged, 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_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.md-notebookbranch, on the shipped built-in's provenance or pin trust. Both Notes refusals keep their exact log wording; their logic moved tomd_notebook_state.backend_start_refusal.fix(md-notebook): a first move hard-killed after copying the legacy PAT and before its seal left the bareworkspace/md-notebook/patholding 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_LEVELbump. 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/patwhenmd-notebook-staging/patalready 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_nextReader: 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: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::TestTheSpawnAsksALegacyStateMoveOnProvenancedrives 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 theApp md-notebook: <reason>log line) and starts once it answersNone; 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 tobuiltin=Trueorbuiltin=False, or dropping the pin-trust branch ofbackend_start_refusal, now fails 1, 3 and 2 tests respectively.Negative tests, so nothing reaches past what the row declares:
Name gates:
test_builtin_adoption_pins.pynow scansapps/legacy_state_moves.pyas an adoption module, allows only its listed key, and compares the live keys to that list;test_core_md_notebook_decoupling.pylists the key (and drops theapps/backend.pyrow).test/test_md_notebook_state.pyadds 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 answeredNoneon 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_movesand fails collection (and its per-hunk run hit an environment error); reverting only the fix commit's hunks by hand failstest_a_pat_an_interrupted_pass_copied_is_emptied_by_the_nextandtest_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.pyis 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)