fix(wave_init): atomic kahuna bootstrap + plan persist (resequence)#401
Merged
bakeb7j0 merged 1 commit intokahuna/390-bug-drainfrom May 5, 2026
Merged
fix(wave_init): atomic kahuna bootstrap + plan persist (resequence)#401bakeb7j0 merged 1 commit intokahuna/390-bug-drainfrom
bakeb7j0 merged 1 commit intokahuna/390-bug-drainfrom
Conversation
Resequence so the kahuna branch is created on remote BEFORE
`wave-status init` persists the plan. Kahuna failure now leaves no
half-state: nothing on disk, nothing on remote.
Two-phase bootstrap in `lib/wave_init_plan.ts`:
1. `bootstrapKahunaBranchRemote` — pre-check + create branch (no
state.json writes; safe to run before `wave-status init`).
2. `recordKahunaBranchInState` — `wave-status set-kahuna-branch`
write, runs after `wave-status init` creates state.json.
Behavior change: when state has no kahuna_branch but the remote has
the EXACT desired `kahuna/<plan_id>-<slug>` branch, claim it as
idempotent reuse rather than refusing as orphan. This makes retry
converge after a `wave-status init` failure that left the branch on
remote but never persisted state.
Tests cover: ordering (create-branch → init → set-kahuna), kahuna
failure paths blocking init, retry-after-init-failure orphan claim,
extend-mode wave-ID-collision absence after kahuna fail.
Pre-#378 single-phase `bootstrapKahunaBranch` retained as deprecated
back-compat for any external caller; updated to use `previously_recorded`.
Closes #378
This was referenced May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resequences
wave_initto make kahuna bootstrap + plan persist atomic. The reversible step (kahuna branch creation) now happens BEFORE the irreversible step (plan persist to disk), so kahuna failures cannot leave a half-state requiring--forceto recover.Background
Per #378:
wave_initwas non-atomic across its two intended steps. When kahuna bootstrap failed for any reason after plan persist succeeded, the wave plan ended up on disk but the kahuna didn't exist. Subsequentwave_init --extendcalls failed with wave-ID-collision errors because the persisted plan blocked retry.Changes
handlers/wave_init.ts— resequenced to: validate → kahuna remote bootstrap → wave-status init → set-kahuna-branch. Atomicity comment block added (lines 4-26).lib/wave_init_plan.ts— splitbootstrapKahunaBranchintobootstrapKahunaBranchRemote(no state writes) +recordKahunaBranchInState(state-only). Addedpreviously_recordedfield. Orphan-with-matching-name now claimed as idempotent reuse rather than refused.tests/wave_init.test.ts— 6 new atomicity tests + 1 existing test updated.Tests
validate.shBehavior Changes
Orphan-with-matching-name (state empty + remote has exact
kahuna/<plan_id>-<slug>) is now claimed as idempotent reuse instead of refused. This is necessary for retry semantics to converge after awave-status initmid-flow failure. Safe because(plan_id, slug)is a deterministic mapping per plan.Closes #378