Codespaces init scripts: no built‑in idempotency feature
0 reputation · 17 May 2025, 21:58 UTC
Codespaces init scripts and duplicate writes
When a Codespace starts, the Dockerfile and any postCreateCommand or postStartCommand defined in .devcontainer/devcontainer.json are executed on every launch. These commands can perform file writes, package installs, or network calls that are not automatically guarded against repeated execution.
Because the current documentation does not provide a retry or idempotency mechanism, a script that appends a timestamp to a file will produce duplicate entries each time the Codespace is restarted. Users often add manual checks—e.g., testing for file existence before writing—to avoid corruption, but this logic must be duplicated in every script.
The absence of a built‑in marker or flag to signal that a particular write operation has already succeeded leaves an open design question for GitHub: should Codespaces expose a feature that enables scripts to detect prior completion and skip redundant writes?
Would a simple once directive or stateful marker be sufficient for most use cases, or is a more sophisticated API required?