Clean Worktree Integration from Dirty Main
When to use
Use this when:
- the primary repo checkout on
main has unrelated local changes
- one or more issues were implemented and validated in separate worktrees
- you need a clean landing path without disturbing the dirty main checkout
- you want a reproducible integration branch before push/closeout
Typical trigger:
git status on the main checkout shows many unrelated modified/untracked files
- issue worktrees are clean and contain the validated commits you actually want to land
Why this pattern exists
Trying to land work directly from a dirty main checkout risks:
- mixing unrelated files into the landing set
- accidental staging of local audit/docs/session artifacts
- difficult rollback if cherry-pick/integration validation fails
A fresh integration worktree gives you a clean room for landing only the approved commits.
Workflow
- Confirm issue worktrees are clean and validated
- In each issue worktree, ensure
git status --short is clean.
- Record the exact implementation commits to land.
- If there are planning-marker commits in the issue worktree, do not include them in the final landing set unless they are intentionally repo-tracked deliverables.
- Record the clean integration base
- Capture the intended base commit from the main repo:
- Do this from the main checkout, not from an issue worktree.
Critical preflight: verify the landing set is still unlanded
Before you create an integration worktree, check the exact target file set you think needs landing.
Recommended pattern:
git status --short -- <target files...>
git diff --stat -- <target files...>
Interpretation rules:
- If both commands are empty for the target set, do not assume you still need a landing branch for those files. That often means the edits already landed on the current base via another session/commit.
- In that case, switch from landing mode to reconciliation mode:
- identify which intended artifacts are already on
HEAD
- isolate any truly new files from this session (for example a new runbook or prompt pack)
- create a worktree only for the still-unlanded residue, or skip the worktree entirely if nothing remains
Why this matters:
- in parallel agent sessions, plan/doc edits may be committed to
main between drafting and integration
- creating a fresh worktree and copying files can reveal that the only remaining delta is a newly-created artifact, not the full landing set you expected
- this prevents duplicate commits for files that are already identical to the integration base
- Create a fresh integration worktree
- Example:
git worktree add -b integration-<issue-set> /path/to/integration-worktree <base-commit>
- This avoids interference from the dirty main checkout.
- Cherry-pick only the implementation/fix commits
- Cherry-pick the validated issue commits into the integration worktree in dependency order.
- Example pattern:
- schema feature commit
- schema fix commit(s)
- resolver feature commit
- resolver fix commit(s)
- Exclude local-only approval-marker commits unless they must land.
- Run combined validation in the integration worktree
- Re-run the exact targeted tests for each issue.
- Also run a nearby regression set that covers touched consumers.
- Do not assume per-worktree validation is enough; the combined landing set needs its own green run.
- Pre-landing already-landed check (critical)
Before you prepare push/closeout artifacts or cherry-pick into the integration worktree, explicitly verify the issue has not already landed elsewhere.
Topology-aware validation after cherry-picks (critical)
After the integration worktree contains the intended commits, validate in layers instead of trusting the first failing command:
- Run the targeted test suite for the landed surface.
- If tests depend on generated/local fixture repos, explicitly bootstrap those fixtures before classifying failures as code defects.
- Separate code/import validation from topology validation:
- direct module invocation / package import health
- wrapper/cron behavior in the intended runtime topology
- Do not treat wrapper failures in a clean integration worktree as proof the feature code is broken if the wrapper begins with topology-sensitive commands like
git pull --ff-only origin main.
Observed reusable pattern:
- In a clean integration worktree, ecosystem-sync tests initially failed because fixture repos under
tests/.../fixtures/repos/ had not been built yet.
- After running the fixture builder, the full targeted suite passed, proving the failure was a fixture-bootstrap gap rather than a regression in the integrated code.
- The cron wrapper still failed in the integration worktree because
git pull --ff-only origin main is expected to fail in a diverged landing branch/worktree; that is a topology issue, not necessarily an implementation issue.
- A direct
uv run path/to/script.py ... invocation may fail with ModuleNotFoundError even when uv run python -m package.module ... works. When the landed script imports from the repo package root, verify both invocation styles before declaring the integration broken.
Practical rule:
- classify failures as one of:
- fixture/bootstrap gap
- import/invocation-path bug
- topology-specific wrapper failure
- real functional regression
- only the last category should automatically block the landing set as broken code.
Documentation-update guardrail learned in live use:
- when adjusting operator/docs artifacts inside the integration worktree, do NOT reconstruct whole files from line-numbered
read_file output and then write_file them back; that can accidentally persist the line-number prefixes into the file contents.
- prefer targeted
patch edits for command swaps or narrow wording fixes, especially in markdown/shell handoff artifacts.
- after any scripted doc rewrite, immediately sanity-check the first few lines of the file before committing.
Check all of:
git fetch origin main --quiet
git log --oneline origin/main -5
gh issue view <issue> --json state,comments,labels,url
- if useful,
git log --oneline --grep='#<issue>' origin/main
Interpretation rules:
- If
origin/main already contains an implementation commit for the issue, treat the issue as potentially already landed.
- If the GitHub issue is already CLOSED with a landed-summary comment, treat that as strong evidence the work is already upstream.
- If your local isolated worktree re-implemented the same issue independently, stop before push and switch from landing mode to verification/reconciliation mode.
What to do if already landed upstream:
- do NOT push a duplicate implementation branch
- do NOT post duplicate closeout comments
- compare your local worktree against
origin/main and determine whether it contains any extra learnings or fixes not upstream
- if your work is fully superseded, keep it as local evidence only and clean up the redundant worktree after documenting the discovery
- if your work contains additional value beyond upstream, create a fresh follow-up issue/branch for just that delta instead of re-landing the full issue
Why this matters:
- parallel agent execution can cause an issue to land on
origin/main while your isolated worktree is still implementing
- a late cherry-pick conflict in the clean integration worktree is often the first signal that the issue was already landed elsewhere
- checking issue state + origin/main before landing avoids duplicate pushes and misleading second closeouts
- Prepare landing artifacts before push
Create:
- an integration runbook with:
- issue links
- commits included
- validation commands/results
- exact branch/worktree path
- closeout comment drafts with:
- result
- change summary
- acceptance criteria mapping
- validation evidence
- git evidence
- residual risk
- Push/close only after user approval for side effects
- Pushing, posting GH comments, and closing issues are external side effects.
- If user approval for execution existed but not explicit approval for external landing side effects, stop and ask for final go-ahead.
Multi-wave landing rule (important)
If the isolated worktree contains more than one class of change, split the landing into waves instead of blindly cherry-picking everything at once.
Recommended order:
- narrow repo-wide governance/enforcement fix first
- core feature/implementation commits in dependency order
- docs / handoff / operator artifacts last
Why:
- a small governance fix often has value beyond the feature branch that discovered it
- validating the narrow fix first reduces blame surface if later feature integration fails
- docs bundles should not be allowed to obscure whether code integration itself is healthy
Example trigger:
- a feature worktree contains both a verified enforcement-hook fix and a larger feature implementation
- the main checkout is dirty, so you need a clean integration worktree anyway
Validation rule by wave:
- after wave 1, run the targeted regression for the governance fix before continuing
- after wave 2, run the feature-targeted test suite before adding doc commits
- after wave 3, do a final status + regression pass
Also explicitly exclude planning-marker / approval-marker commits unless they are intentional repo-tracked deliverables.
Recommended command pattern
# from dirty main checkout
BASE=$(git rev-parse HEAD)
git worktree add -b integration-2151-2155 \
/mnt/local-analysis/worktrees/workspace-hub-integration-2151-2155 \
"$BASE"
# in integration worktree
# wave 1: narrow governance fix
# git cherry-pick <governance-fix-commit>
# run targeted validation
# wave 2: feature commits in dependency order
# git cherry-pick <issue1-commit-1> <issue1-commit-2> ... <issue2-commit-1>
# wave 3: docs / handoff commits
# git cherry-pick <docs-commit-1> <docs-commit-2>
uv run pytest \
tests/analysis/test_readiness_bundle_schema.py \
tests/workstations/test_machine_path_resolver.py \
tests/analysis/test_provider_session_ecosystem_audit.py \
tests/analysis/test_claude_session_ecosystem_audit.py \
tests/workstations/test_registry.py \
tests/workstations/test_dispatch.py \
tests/cron/test_provider_session_ecosystem_audit_wrapper.py \
-q
Selection rules for cherry-picks
Include:
- feature commits for the issue
- follow-up fix commits from adversarial review
Exclude by default:
- local approval-marker commits (
chore(planning): approve issue #...) unless they are intentionally meant to be tracked in the final landing branch
- unrelated docs/planning/session artifacts
Dirty/diverged main with a valid local commit
If the active main checkout already contains a valid local implementation commit but cannot push because origin/main advanced and the checkout also has unrelated dirty/untracked files:
- Do not rebase/reset/stash the dirty main checkout just to land the issue.
- Record both SHAs:
- local equivalent implementation commit (
git rev-parse HEAD or the specific commit SHA)
- current remote base (
git ls-remote origin refs/heads/main or origin/main after fetch)
- Create a temporary clean worktree directly from
origin/main:
git worktree add /tmp/<repo>-<issue>-push origin/main
- Cherry-pick only the scoped implementation/review commit(s) into that clean worktree.
- Validate in the clean worktree, then push
HEAD:main from there.
- Treat the new remote commit SHA as canonical; the dirty main commit is only an equivalent local patch unless/until reconciled later.
- After successful remote verification, remove the temporary worktree and explicitly report that the original checkout may still be dirty/diverged with an equivalent local commit.
This avoids destructive cleanup of unrelated session state while still producing a clean, auditable landing commit on top of the current remote branch.
Validation standard
Before declaring integration-ready, verify:
- integration worktree is clean after cherry-picks and tests
- all issue-targeted tests pass
- nearby regression tests pass
- no unrelated files were introduced
- if the landing set includes CLI/wrapper entrypoints, validate the real invocation mode, not just imported/unit-tested behavior
Additional runtime-entrypoint check learned from ecosystem-sync integration:
- distinguish three layers of validation:
- unit/integration tests
- direct runtime entrypoint invocation
- wrapper/topology invocation
- a clean integration worktree can reveal a real entrypoint bug even when tests are green. Example pattern:
- tests pass
python -m package.module --doctor passes
- wrapper or documented
tool/path.py invocation fails because imports assume module/package context
- when this happens, record it as a real blocker, fix the invocation contract, and re-run tests before push
- separately, do not misclassify expected topology failures (for example wrapper
git pull --ff-only origin main failing in a non-main integration worktree) as code regressions. Isolate entrypoint correctness from topology-specific behavior.
Output checklist
Before final push, prepare:
- integration worktree path
- integration branch name
- exact included commits
- exact validation commands and results
- draft GH closeout comments for each landed issue
- explicit note for any still-blocked issue
Example reusable outcome
This pattern worked well for landing two approved issues from isolated worktrees while the main checkout had many unrelated modified files:
- issue A: schema + contract fixes
- issue B: shared resolver + normalization fix
- integration branch created from clean base
- only implementation commits cherry-picked
- combined regression suite re-run successfully
- push/closeout artifacts prepared separately from the dirty main checkout
Pitfalls
- Do not cherry-pick from the dirty main checkout itself.
- Do not assume worktree-local green tests imply combined landing-set green tests.
- Do not silently include approval-marker commits.
- Do not push or close issues without explicit side-effect approval.
- If a blocked issue depends on missing upstream foundations, keep it open and document the blocker rather than forcing fixture work against an invented contract.
- Fresh integration worktrees may fail pre-push hooks for reasons unrelated to the landing commit. In workspace-hub, a clean worktree created outside the normal repo topology triggered repo-wide tier-1 checks that expected sibling repos at matching relative paths and failed before push. Practical recovery pattern:
- First try pushing from a topology-compatible checkout/worktree where the hook environment already matches the repo's assumptions.
- If the hook still fails only because of unrelated ecosystem debt (for example tier-1 quality failures in other repos) and the landing branch is a narrowly scoped docs-only or low-risk artifact change, consider an audited bypass push rather than mutating the clean worktree to satisfy unrelated checks.
- In this repo,
GIT_PRE_PUSH_SKIP=1 git push ... is a soft bypass that logs to logs/hooks/pre-push-bypass.jsonl. Use it only when the branch scope is truly isolated and you can justify that the pre-push failures are unrelated to the landing artifact.
- Before bypassing, confirm the branch diff is exactly the intended scoped artifact set (for example a single docs runbook file) and preserve the clean non-bypass landing branch so you still have a normal-path provenance record.
Pre-push topology mismatch on clean worktrees (important live lesson)
A fresh integration worktree can still fail at push time even when the landing diff is correct, because workspace-level pre-push hooks may assume the full repo ecosystem exists at paths relative to that checkout.
Observed failure mode:
- a clean worktree contained only
workspace-hub/
git push triggered the repo pre-push hook
- the hook tried to run tier-1 checks for sibling repos like
assetutilities, digitalmodel, worldenergydata, and assethold
- those paths did not exist under the clean worktree root, so the push failed before evaluating the actual landing diff
- a later attempt from the topology-compatible main checkout got past the path-mismatch but still failed because the same hook enforces unrelated tier-1 quality debt across the ecosystem
Practical rule
For docs-only or narrow governance landings in workspace-hub:
- Validate the diff in the clean integration worktree first.
- Before push, inspect the repo's pre-push hook assumptions:
- does it expect sibling repos under the checkout root?
- does it run ecosystem-wide tier-1 checks unrelated to the landing diff?
- If yes, treat the clean worktree as a validation/integration room, not necessarily the final push location.
- Recreate the landing commit in a topology-compatible checkout (for example the main workspace checkout where sibling repos exist) or cherry-pick it there.
- If the push still fails only because of unrelated ecosystem-wide checks, consider an explicit audited bypass for the docs-only branch rather than mutating the clean worktree to fake the missing topology.
Recommended sequence for this case
- Create and validate the clean worktree landing commit.
- Create a topology-compatible branch in the real workspace checkout.
- Commit or cherry-pick the same narrow landing there.
- Attempt a normal push once.
- If the only remaining blocker is unrelated repo-wide pre-push debt, use the repo's audited bypass mechanism (for example
GIT_PRE_PUSH_SKIP=1) for the narrow docs-only branch.
- Record that the bypass was environmental/governance-driven, not required by the change itself.
This avoids wasting time debugging a perfectly good clean worktree that simply lacks the filesystem topology expected by repo hooks.
- In workspace-hub, a brand-new clean worktree may NOT be push-ready even for docs-only branches. Pre-push hooks can assume the full tier-1 repo topology exists relative to the current checkout (for example sibling dirs like
assetutilities/, digitalmodel/, worldenergydata/, assethold/) and may also require local Python deps such as yaml for config-drift checks. A skeletal worktree containing only workspace-hub can therefore fail pre-push despite a clean, valid commit.
- The topology-compatible fallback can still fail for unrelated reasons: even in the real workspace checkout, pre-push may run cross-repo quality gates across tier-1 repos and block your docs-only branch on unrelated failures (observed:
assetutilities ruff/mypy failures blocked a push for a one-file runbook branch).
- Practical rule: before planning to push from a fresh integration worktree, do a real push probe (with side-effect approval) or inspect the pre-push hook assumptions. If hooks expect multi-repo topology, prefer one of three paths: (1) cherry-pick the clean commit into a topology-compatible checkout/worktree where hooks already pass, (2) recreate the expected sibling-repo layout for that worktree, or (3) use an explicit user-approved bypass for the docs-only push.
- Workspace-hub's current pre-push hook supports an audited soft bypass via
GIT_PRE_PUSH_SKIP=1. It logs a JSONL record to logs/hooks/pre-push-bypass.jsonl and exits 0 before running the heavy tier-1 checks. For isolated docs/plans branches that are clean and intentionally low-risk, this can be the fastest safe landing path once the user approves the bypass. Example:
GIT_PRE_PUSH_SKIP=1 git push -u origin <branch>
- When using that bypass, capture in your landing notes: the exact branch pushed, the exact commit SHA, and the bypass log path. This preserves auditability and keeps the bypass scoped to the already-validated low-risk branch rather than normalizing bypass use for broader implementation work.
- In workspace-hub, a brand-new clean worktree may NOT be push-ready even for docs-only branches. Pre-push hooks can assume the full tier-1 repo topology exists relative to the current checkout (for example sibling dirs like
assetutilities/, digitalmodel/, worldenergydata/, assethold/) and may also require local Python deps such as yaml for config-drift checks. A skeletal worktree containing only workspace-hub can therefore fail pre-push despite a clean, valid commit.
- The topology-compatible fallback can still fail for unrelated reasons: even in the real workspace checkout, pre-push may run cross-repo quality gates across tier-1 repos and block your docs-only branch on unrelated failures (observed:
assetutilities ruff/mypy failures blocked a push for a one-file runbook branch).
- Practical rule: before planning to push from a fresh integration worktree, do a real push probe (with side-effect approval) or inspect the pre-push hook assumptions. If hooks expect multi-repo topology, prefer one of three paths: (1) cherry-pick the clean commit into a topology-compatible checkout/worktree where hooks already pass, (2) recreate the expected sibling-repo layout for that worktree, or (3) use an explicit user-approved bypass for the docs-only push.
- Workspace-hub's current pre-push hook supports an audited soft bypass via
GIT_PRE_PUSH_SKIP=1. It logs a JSONL record to logs/hooks/pre-push-bypass.jsonl and exits 0 before running the heavy tier-1 checks. For isolated docs/plans branches that are clean and intentionally low-risk, this can be the fastest safe landing path once the user approves the bypass. Example:
GIT_PRE_PUSH_SKIP=1 git push -u origin <branch>
- When using that bypass, capture in your landing notes: the exact branch pushed, the exact commit SHA, and the bypass log path. This preserves auditability and keeps the bypass scoped to the already-validated low-risk branch rather than normalizing bypass use for broader implementation work.
1---2name: clean-worktree-integration-from-dirty-main3description: Land validated issue work from isolated worktrees when the main checkout is dirty by creating a fresh integration worktree, cherry-picking only implementation commits, re-running combined validation, and preparing push/closeout artifacts.4license: MIT5---67# Clean Worktree Integration from Dirty Main89## When to use1011Use this when:12- the primary repo checkout on `main` has unrelated local changes13- one or more issues were implemented and validated in separate worktrees14- you need a clean landing path without disturbing the dirty main checkout15- you want a reproducible integration branch before push/closeout1617Typical trigger:18- `git status` on the main checkout shows many unrelated modified/untracked files19- issue worktrees are clean and contain the validated commits you actually want to land2021## Why this pattern exists2223Trying to land work directly from a dirty main checkout risks:24- mixing unrelated files into the landing set25- accidental staging of local audit/docs/session artifacts26- difficult rollback if cherry-pick/integration validation fails2728A fresh integration worktree gives you a clean room for landing only the approved commits.2930## Workflow31321. Confirm issue worktrees are clean and validated33- In each issue worktree, ensure `git status --short` is clean.34- Record the exact implementation commits to land.35- If there are planning-marker commits in the issue worktree, do not include them in the final landing set unless they are intentionally repo-tracked deliverables.36372. Record the clean integration base38- Capture the intended base commit from the main repo:39 - `git rev-parse HEAD`40- Do this from the main checkout, not from an issue worktree.4142### Critical preflight: verify the landing set is still unlanded4344Before you create an integration worktree, check the exact target file set you think needs landing.4546Recommended pattern:47- `git status --short -- <target files...>`48- `git diff --stat -- <target files...>`4950Interpretation rules:51- If both commands are empty for the target set, do **not** assume you still need a landing branch for those files. That often means the edits already landed on the current base via another session/commit.52- In that case, switch from landing mode to **reconciliation mode**:53 - identify which intended artifacts are already on `HEAD`54 - isolate any truly new files from this session (for example a new runbook or prompt pack)55 - create a worktree only for the still-unlanded residue, or skip the worktree entirely if nothing remains5657Why this matters:58- in parallel agent sessions, plan/doc edits may be committed to `main` between drafting and integration59- creating a fresh worktree and copying files can reveal that the only remaining delta is a newly-created artifact, not the full landing set you expected60- this prevents duplicate commits for files that are already identical to the integration base61623. Create a fresh integration worktree63- Example:64 - `git worktree add -b integration-<issue-set> /path/to/integration-worktree <base-commit>`65- This avoids interference from the dirty main checkout.66674. Cherry-pick only the implementation/fix commits68- Cherry-pick the validated issue commits into the integration worktree in dependency order.69- Example pattern:70 - schema feature commit71 - schema fix commit(s)72 - resolver feature commit73 - resolver fix commit(s)74- Exclude local-only approval-marker commits unless they must land.75765. Run combined validation in the integration worktree77- Re-run the exact targeted tests for each issue.78- Also run a nearby regression set that covers touched consumers.79- Do not assume per-worktree validation is enough; the combined landing set needs its own green run.80816. Pre-landing already-landed check (critical)82Before you prepare push/closeout artifacts or cherry-pick into the integration worktree, explicitly verify the issue has not already landed elsewhere.8384### Topology-aware validation after cherry-picks (critical)8586After the integration worktree contains the intended commits, validate in layers instead of trusting the first failing command:87881. Run the targeted test suite for the landed surface.892. If tests depend on generated/local fixture repos, explicitly bootstrap those fixtures before classifying failures as code defects.903. Separate code/import validation from topology validation:91 - direct module invocation / package import health92 - wrapper/cron behavior in the intended runtime topology934. Do not treat wrapper failures in a clean integration worktree as proof the feature code is broken if the wrapper begins with topology-sensitive commands like `git pull --ff-only origin main`.9495Observed reusable pattern:96- In a clean integration worktree, ecosystem-sync tests initially failed because fixture repos under `tests/.../fixtures/repos/` had not been built yet.97- After running the fixture builder, the full targeted suite passed, proving the failure was a fixture-bootstrap gap rather than a regression in the integrated code.98- The cron wrapper still failed in the integration worktree because `git pull --ff-only origin main` is expected to fail in a diverged landing branch/worktree; that is a topology issue, not necessarily an implementation issue.99- A direct `uv run path/to/script.py ...` invocation may fail with `ModuleNotFoundError` even when `uv run python -m package.module ...` works. When the landed script imports from the repo package root, verify both invocation styles before declaring the integration broken.100101Practical rule:102- classify failures as one of:103 - fixture/bootstrap gap104 - import/invocation-path bug105 - topology-specific wrapper failure106 - real functional regression107- only the last category should automatically block the landing set as broken code.108109Documentation-update guardrail learned in live use:110- when adjusting operator/docs artifacts inside the integration worktree, do NOT reconstruct whole files from line-numbered `read_file` output and then `write_file` them back; that can accidentally persist the line-number prefixes into the file contents.111- prefer targeted `patch` edits for command swaps or narrow wording fixes, especially in markdown/shell handoff artifacts.112- after any scripted doc rewrite, immediately sanity-check the first few lines of the file before committing.113114Check all of:115- `git fetch origin main --quiet`116- `git log --oneline origin/main -5`117- `gh issue view <issue> --json state,comments,labels,url`118- if useful, `git log --oneline --grep='#<issue>' origin/main`119120Interpretation rules:121- If `origin/main` already contains an implementation commit for the issue, treat the issue as potentially already landed.122- If the GitHub issue is already CLOSED with a landed-summary comment, treat that as strong evidence the work is already upstream.123- If your local isolated worktree re-implemented the same issue independently, stop before push and switch from landing mode to verification/reconciliation mode.124125What to do if already landed upstream:126- do NOT push a duplicate implementation branch127- do NOT post duplicate closeout comments128- compare your local worktree against `origin/main` and determine whether it contains any extra learnings or fixes not upstream129- if your work is fully superseded, keep it as local evidence only and clean up the redundant worktree after documenting the discovery130- if your work contains additional value beyond upstream, create a fresh follow-up issue/branch for just that delta instead of re-landing the full issue131132Why this matters:133- parallel agent execution can cause an issue to land on `origin/main` while your isolated worktree is still implementing134- a late cherry-pick conflict in the clean integration worktree is often the first signal that the issue was already landed elsewhere135- checking issue state + origin/main before landing avoids duplicate pushes and misleading second closeouts1361377. Prepare landing artifacts before push138Create:139- an integration runbook with:140 - issue links141 - commits included142 - validation commands/results143 - exact branch/worktree path144- closeout comment drafts with:145 - result146 - change summary147 - acceptance criteria mapping148 - validation evidence149 - git evidence150 - residual risk1511528. Push/close only after user approval for side effects153- Pushing, posting GH comments, and closing issues are external side effects.154- If user approval for execution existed but not explicit approval for external landing side effects, stop and ask for final go-ahead.155156## Multi-wave landing rule (important)157158If the isolated worktree contains more than one class of change, split the landing into waves instead of blindly cherry-picking everything at once.159160Recommended order:1611. narrow repo-wide governance/enforcement fix first1622. core feature/implementation commits in dependency order1633. docs / handoff / operator artifacts last164165Why:166- a small governance fix often has value beyond the feature branch that discovered it167- validating the narrow fix first reduces blame surface if later feature integration fails168- docs bundles should not be allowed to obscure whether code integration itself is healthy169170Example trigger:171- a feature worktree contains both a verified enforcement-hook fix and a larger feature implementation172- the main checkout is dirty, so you need a clean integration worktree anyway173174Validation rule by wave:175- after wave 1, run the targeted regression for the governance fix before continuing176- after wave 2, run the feature-targeted test suite before adding doc commits177- after wave 3, do a final status + regression pass178179Also explicitly exclude planning-marker / approval-marker commits unless they are intentional repo-tracked deliverables.180181## Recommended command pattern182183```bash184# from dirty main checkout185BASE=$(git rev-parse HEAD)186187git worktree add -b integration-2151-2155 \188 /mnt/local-analysis/worktrees/workspace-hub-integration-2151-2155 \189 "$BASE"190191# in integration worktree192# wave 1: narrow governance fix193# git cherry-pick <governance-fix-commit>194# run targeted validation195196# wave 2: feature commits in dependency order197# git cherry-pick <issue1-commit-1> <issue1-commit-2> ... <issue2-commit-1>198199# wave 3: docs / handoff commits200# git cherry-pick <docs-commit-1> <docs-commit-2>201202uv run pytest \203 tests/analysis/test_readiness_bundle_schema.py \204 tests/workstations/test_machine_path_resolver.py \205 tests/analysis/test_provider_session_ecosystem_audit.py \206 tests/analysis/test_claude_session_ecosystem_audit.py \207 tests/workstations/test_registry.py \208 tests/workstations/test_dispatch.py \209 tests/cron/test_provider_session_ecosystem_audit_wrapper.py \210 -q211```212213## Selection rules for cherry-picks214215Include:216- feature commits for the issue217- follow-up fix commits from adversarial review218219Exclude by default:220- local approval-marker commits (`chore(planning): approve issue #...`) unless they are intentionally meant to be tracked in the final landing branch221- unrelated docs/planning/session artifacts222223### Dirty/diverged main with a valid local commit224225If the active main checkout already contains a valid local implementation commit but cannot push because `origin/main` advanced and the checkout also has unrelated dirty/untracked files:2261. Do **not** rebase/reset/stash the dirty main checkout just to land the issue.2272. Record both SHAs:228 - local equivalent implementation commit (`git rev-parse HEAD` or the specific commit SHA)229 - current remote base (`git ls-remote origin refs/heads/main` or `origin/main` after fetch)2303. Create a temporary clean worktree directly from `origin/main`:231 - `git worktree add /tmp/<repo>-<issue>-push origin/main`2324. Cherry-pick only the scoped implementation/review commit(s) into that clean worktree.2335. Validate in the clean worktree, then push `HEAD:main` from there.2346. Treat the new remote commit SHA as canonical; the dirty main commit is only an equivalent local patch unless/until reconciled later.2357. After successful remote verification, remove the temporary worktree and explicitly report that the original checkout may still be dirty/diverged with an equivalent local commit.236237This avoids destructive cleanup of unrelated session state while still producing a clean, auditable landing commit on top of the current remote branch.238239## Validation standard240241Before declaring integration-ready, verify:242- integration worktree is clean after cherry-picks and tests243- all issue-targeted tests pass244- nearby regression tests pass245- no unrelated files were introduced246- if the landing set includes CLI/wrapper entrypoints, validate the real invocation mode, not just imported/unit-tested behavior247248Additional runtime-entrypoint check learned from ecosystem-sync integration:249- distinguish three layers of validation:250 1. unit/integration tests251 2. direct runtime entrypoint invocation252 3. wrapper/topology invocation253- a clean integration worktree can reveal a real entrypoint bug even when tests are green. Example pattern:254 - tests pass255 - `python -m package.module --doctor` passes256 - wrapper or documented `tool/path.py` invocation fails because imports assume module/package context257- when this happens, record it as a real blocker, fix the invocation contract, and re-run tests before push258- separately, do not misclassify expected topology failures (for example wrapper `git pull --ff-only origin main` failing in a non-main integration worktree) as code regressions. Isolate entrypoint correctness from topology-specific behavior.259260## Output checklist261262Before final push, prepare:263- integration worktree path264- integration branch name265- exact included commits266- exact validation commands and results267- draft GH closeout comments for each landed issue268- explicit note for any still-blocked issue269270## Example reusable outcome271272This pattern worked well for landing two approved issues from isolated worktrees while the main checkout had many unrelated modified files:273- issue A: schema + contract fixes274- issue B: shared resolver + normalization fix275- integration branch created from clean base276- only implementation commits cherry-picked277- combined regression suite re-run successfully278- push/closeout artifacts prepared separately from the dirty main checkout279280## Pitfalls281282- Do not cherry-pick from the dirty main checkout itself.283- Do not assume worktree-local green tests imply combined landing-set green tests.284- Do not silently include approval-marker commits.285- Do not push or close issues without explicit side-effect approval.286- If a blocked issue depends on missing upstream foundations, keep it open and document the blocker rather than forcing fixture work against an invented contract.287- Fresh integration worktrees may fail pre-push hooks for reasons unrelated to the landing commit. In workspace-hub, a clean worktree created outside the normal repo topology triggered repo-wide tier-1 checks that expected sibling repos at matching relative paths and failed before push. Practical recovery pattern:288 1. First try pushing from a topology-compatible checkout/worktree where the hook environment already matches the repo's assumptions.289 2. If the hook still fails only because of unrelated ecosystem debt (for example tier-1 quality failures in other repos) and the landing branch is a narrowly scoped docs-only or low-risk artifact change, consider an audited bypass push rather than mutating the clean worktree to satisfy unrelated checks.290 3. In this repo, `GIT_PRE_PUSH_SKIP=1 git push ...` is a soft bypass that logs to `logs/hooks/pre-push-bypass.jsonl`. Use it only when the branch scope is truly isolated and you can justify that the pre-push failures are unrelated to the landing artifact.291- Before bypassing, confirm the branch diff is exactly the intended scoped artifact set (for example a single docs runbook file) and preserve the clean non-bypass landing branch so you still have a normal-path provenance record.292293## Pre-push topology mismatch on clean worktrees (important live lesson)294295A fresh integration worktree can still fail at push time even when the landing diff is correct, because workspace-level pre-push hooks may assume the full repo ecosystem exists at paths relative to that checkout.296297Observed failure mode:298- a clean worktree contained only `workspace-hub/`299- `git push` triggered the repo pre-push hook300- the hook tried to run tier-1 checks for sibling repos like `assetutilities`, `digitalmodel`, `worldenergydata`, and `assethold`301- those paths did not exist under the clean worktree root, so the push failed before evaluating the actual landing diff302- a later attempt from the topology-compatible main checkout got past the path-mismatch but still failed because the same hook enforces unrelated tier-1 quality debt across the ecosystem303304### Practical rule305306For docs-only or narrow governance landings in workspace-hub:3071. Validate the diff in the clean integration worktree first.3082. Before push, inspect the repo's pre-push hook assumptions:309 - does it expect sibling repos under the checkout root?310 - does it run ecosystem-wide tier-1 checks unrelated to the landing diff?3113. If yes, treat the clean worktree as a validation/integration room, not necessarily the final push location.3124. Recreate the landing commit in a topology-compatible checkout (for example the main workspace checkout where sibling repos exist) or cherry-pick it there.3135. If the push still fails only because of unrelated ecosystem-wide checks, consider an explicit audited bypass for the docs-only branch rather than mutating the clean worktree to fake the missing topology.314315### Recommended sequence for this case3163171. Create and validate the clean worktree landing commit.3182. Create a topology-compatible branch in the real workspace checkout.3193. Commit or cherry-pick the same narrow landing there.3204. Attempt a normal push once.3215. If the only remaining blocker is unrelated repo-wide pre-push debt, use the repo's audited bypass mechanism (for example `GIT_PRE_PUSH_SKIP=1`) for the narrow docs-only branch.3226. Record that the bypass was environmental/governance-driven, not required by the change itself.323324This avoids wasting time debugging a perfectly good clean worktree that simply lacks the filesystem topology expected by repo hooks.325- In workspace-hub, a brand-new clean worktree may NOT be push-ready even for docs-only branches. Pre-push hooks can assume the full tier-1 repo topology exists relative to the current checkout (for example sibling dirs like `assetutilities/`, `digitalmodel/`, `worldenergydata/`, `assethold/`) and may also require local Python deps such as `yaml` for config-drift checks. A skeletal worktree containing only workspace-hub can therefore fail pre-push despite a clean, valid commit.326- The topology-compatible fallback can still fail for unrelated reasons: even in the real workspace checkout, pre-push may run cross-repo quality gates across tier-1 repos and block your docs-only branch on unrelated failures (observed: `assetutilities` ruff/mypy failures blocked a push for a one-file runbook branch).327- Practical rule: before planning to push from a fresh integration worktree, do a real push probe (with side-effect approval) or inspect the pre-push hook assumptions. If hooks expect multi-repo topology, prefer one of three paths: (1) cherry-pick the clean commit into a topology-compatible checkout/worktree where hooks already pass, (2) recreate the expected sibling-repo layout for that worktree, or (3) use an explicit user-approved bypass for the docs-only push.328- Workspace-hub's current pre-push hook supports an audited soft bypass via `GIT_PRE_PUSH_SKIP=1`. It logs a JSONL record to `logs/hooks/pre-push-bypass.jsonl` and exits 0 before running the heavy tier-1 checks. For isolated docs/plans branches that are clean and intentionally low-risk, this can be the fastest safe landing path once the user approves the bypass. Example:329 - `GIT_PRE_PUSH_SKIP=1 git push -u origin <branch>`330- When using that bypass, capture in your landing notes: the exact branch pushed, the exact commit SHA, and the bypass log path. This preserves auditability and keeps the bypass scoped to the already-validated low-risk branch rather than normalizing bypass use for broader implementation work.331- In workspace-hub, a brand-new clean worktree may NOT be push-ready even for docs-only branches. Pre-push hooks can assume the full tier-1 repo topology exists relative to the current checkout (for example sibling dirs like `assetutilities/`, `digitalmodel/`, `worldenergydata/`, `assethold/`) and may also require local Python deps such as `yaml` for config-drift checks. A skeletal worktree containing only workspace-hub can therefore fail pre-push despite a clean, valid commit.332- The topology-compatible fallback can still fail for unrelated reasons: even in the real workspace checkout, pre-push may run cross-repo quality gates across tier-1 repos and block your docs-only branch on unrelated failures (observed: `assetutilities` ruff/mypy failures blocked a push for a one-file runbook branch).333- Practical rule: before planning to push from a fresh integration worktree, do a real push probe (with side-effect approval) or inspect the pre-push hook assumptions. If hooks expect multi-repo topology, prefer one of three paths: (1) cherry-pick the clean commit into a topology-compatible checkout/worktree where hooks already pass, (2) recreate the expected sibling-repo layout for that worktree, or (3) use an explicit user-approved bypass for the docs-only push.334- Workspace-hub's current pre-push hook supports an audited soft bypass via `GIT_PRE_PUSH_SKIP=1`. It logs a JSONL record to `logs/hooks/pre-push-bypass.jsonl` and exits 0 before running the heavy tier-1 checks. For isolated docs/plans branches that are clean and intentionally low-risk, this can be the fastest safe landing path once the user approves the bypass. Example:335 - `GIT_PRE_PUSH_SKIP=1 git push -u origin <branch>`336- When using that bypass, capture in your landing notes: the exact branch pushed, the exact commit SHA, and the bypass log path. This preserves auditability and keeps the bypass scoped to the already-validated low-risk branch rather than normalizing bypass use for broader implementation work.