Skip to content

fix(router): skip git fetch/checkout when /workspace has uncommitted changes#65

Merged
mrsimpson merged 1 commit into
mainfrom
fix/init-script-resilient-to-local-changes
May 17, 2026
Merged

fix(router): skip git fetch/checkout when /workspace has uncommitted changes#65
mrsimpson merged 1 commit into
mainfrom
fix/init-script-resilient-to-local-changes

Conversation

@mrsimpson
Copy link
Copy Markdown
Owner

@mrsimpson mrsimpson commented May 17, 2026

Summary

  • Session pods crashloop in Init:0/1 when the PVC at /workspace carries uncommitted edits from a prior session — git checkout aborts with error: Your local changes to the following files would be overwritten by checkout.
  • Detect a dirty workspace (any tracked diff or non-ignored untracked file) in the init script and skip the git fetch + checkout phase entirely when present.
  • The workspace was initialized on an earlier pod start so the pod can come up against the existing state. To get back onto the session branch the user commits/discards the changes from inside the pod and restarts.

Why this approach (vs. auto-stash)

Considered stashing the uncommitted work and either popping it or leaving it in the stash list. Rejected because:

  • Auto-pop can hit merge conflicts after the checkout, leaving the workspace in an unmerged state that opencode then has to work in.
  • Stash without pop preserves work but pollutes git stash list on every restart and makes it non-obvious to the user where their edits went.
  • Skip-on-dirty preserves the user's mental model ("my work is right where I left it"), needs no stash bookkeeping, and is a smaller diff. A fresh-clone workspace is never dirty so the first-start path is unchanged.

Trade-off: if the session annotation says branch X but the workspace was left on branch Y, the pod silently starts on Y. In practice this is unlikely because each session pod is hash-scoped to a single branch — but worth knowing.

Repro

Init container logs from a pod hitting this in production:

error: Your local changes to the following files would be overwritten by checkout:
	packages/opencode-router-app/src/api.ts
	packages/opencode-router-app/src/app.tsx
	...
Please commit your changes or stash them before you switch branches.
Aborting

Test plan

  • bun test src/pod-manager.test.ts — 67 pass (1 new test added asserting the dirty-workspace guard wraps fetch and both checkout branches)
  • bun run typecheck — clean
  • Manual: kill an existing session pod with uncommitted edits in its PVC, confirm the new pod starts and the init container logs opencode-init: uncommitted changes detected in /workspace; skipping git fetch/checkout to preserve work

🤖 Generated with Claude Code

…changes

Session pods crashloop in Init:0/1 when the PVC at /workspace carries
uncommitted edits from a prior session — `git checkout` aborts with
"local changes would be overwritten" and the user is locked out of their
session.

Detect a dirty workspace (any tracked diff or non-ignored untracked
file) and skip the git fetch + checkout phase entirely when present. The
workspace was initialized on an earlier pod start so the pod can come up
against the existing state. To get back onto the session branch the
user commits or discards the changes from inside the pod and restarts.

This preserves the user's mental model ("my work is where I left it")
with no surprising stash entries piling up and no risk of pop-time
conflicts. A fresh-clone workspace is never dirty so the first-start
path is unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mrsimpson mrsimpson force-pushed the fix/init-script-resilient-to-local-changes branch from 45dc68d to b34f8e0 Compare May 17, 2026 17:09
@mrsimpson mrsimpson changed the title fix(router): auto-stash uncommitted PVC work so init container survives pod restart fix(router): skip git fetch/checkout when /workspace has uncommitted changes May 17, 2026
@mrsimpson mrsimpson merged commit 3faaa8a into main May 17, 2026
4 checks passed
@mrsimpson mrsimpson deleted the fix/init-script-resilient-to-local-changes branch May 17, 2026 17:18
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.

1 participant