refactor(router): gate init container first-run setup on explicit marker file - #66
refactor(router): gate init container first-run setup on explicit marker file#66mrsimpson wants to merge 1 commit into
Conversation
…ker file Replaces implicit "is this the first run" heuristics (`[ ! -d /home/opencode/.config/opencode ]`, `[ ! -d /workspace/.git ]`) with an explicit, versioned marker at /home/opencode/.opencode-init.v1. Why: the implicit checks are per-phase and inferred from side-effects. If a prior init partially completed (e.g. config seed succeeded, git clone failed with ENOSPC), one phase saw "already initialized" while the other saw "needs init" — the PVC could get stuck in a half-state that no retry would heal. The marker is written LAST under `set -e`, so any failure before that point leaves FIRST_RUN=1 on the next pod start and the whole first-run block re-runs cleanly. Bumping the version suffix (v1 → v2) forces a re-init on existing PVCs, giving a clean migration path when the seeded defaults change in a breaking way. Drive-by: the no-repoUrl path is now also guarded. Previously `git commit --allow-empty` would add a new empty commit on every pod restart because it ran unguarded. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
mrsimpson
commented
May 18, 2026
Closing — reviewing this with fresh eyes uncovered a migration bug and a weak value proposition. Migration bug: every existing session pod would crashloop on its next restart after this shipped. With no marker present,
Weak value proposition: the marker's main pitch was failure-atomicity. But each init phase is already individually idempotent ( #65 already solved the user-visible crashloop. This refactor is mostly aesthetic — not worth the migration risk. |
Follow-up to #65.
Summary
[ ! -d /home/opencode/.config/opencode ],[ ! -d /workspace/.git ])./home/opencode/.opencode-init.v1, written last underset -e. Any failure before the marker leavesFIRST_RUN=1on the next start and the whole first-run block re-runs..v1) gives a clean migration path: bump to.v2to force re-init on existing PVCs when seeded defaults change in a breaking way.Drive-by fix
The no-repoUrl path (
git init+git commit --allow-empty) used to run unguarded on every pod start, adding a fresh empty commit per restart. Now gated onFIRST_RUN.What stays "every-start"
init-scripts/*.shruns (intentional — covers image updates).gitconfig.lockcleanupConsidered alternatives
.opencode-init.config.v1,.opencode-init.git.v1): more bookkeeping, marginal benefit —set -ealready aborts on the first failure so phases never partially complete in a single run.Test plan
bun test src/pod-manager.test.ts— 69 pass (2 new tests covering marker placement and no-repoUrl guard)bun run typecheck— clean/home/opencode/.opencode-init.v1exists after init; restart the pod, confirm init container completes quickly without re-seeding.config/opencode🤖 Generated with Claude Code