Codespaces prebuild freshness limits after devcontainer changes
0 reputation · 25 Oct 2020, 14:33 UTC
0 reputation · 25 Oct 2020, 14:33 UTC
GitHub Codespaces prebuilds assemble a dev container image, features and onCreateCommand ahead of time so new codespaces start faster. The prebuild is a snapshot tied to a specific devcontainer.json and repository branch, and its usefulness degrades when the template changes.
Refresh behavior depends on the configured prebuild update trigger. When a codespace is created from a stale prebuild, the container image may be old, while content update steps such as updateContentCommand and postCreateCommand still run against the latest commit. That partial update can mask a stale image without rebuilding changed images or features.
Prebuild storage is billed and availability can be limited by region and machine type, so organizations must balance refresh frequency against cost. The unresolved decision is which template modifications reliably force a prebuild to be considered out of date versus being silently reused, and whether freshness can be confirmed from the UI.
Does a change to the base image or features always invalidate existing prebuilds for the configured branch? Is there a documented way to determine whether a newly created codespace used a current prebuild or a stale snapshot? How do region and machine type limits affect prebuild availability when freshness is required?
Changes to the base image or the features array in devcontainer.json typically invalidate existing prebuilds because these modifications alter the resulting container image hash. When the underlying image definition changes, the snapshot is no longer a valid representation of the environment, triggering a new prebuild process if the configured trigger (such as a push to the tracked branch) is active.
A critical distinction exists between the image state and the content state. Because updateContentCommand and postCreateCommand execute at runtime, a codespace may appear up-to-date regarding application code while running on a stale system image. This happens if a prebuild is reused despite changes to the base image, masking the staleness of system-level dependencies.
There is currently no single "Freshness" indicator in the GitHub UI to confirm if a specific codespace instance used a current or stale prebuild. To verify the environment state, use the following methods:
cat /proc/self/cgroup or check the container runtime logs to see if the image ID matches the most recent successful prebuild run.devcontainer.json change (e.g., node -v or python --version).Prebuild availability is not guaranteed. If a specific region is experiencing capacity limits or if the selected machine type is unavailable for prebuild caching, GitHub may fall back to a full build from scratch. In these cases, the codespace will start slower, but it will be guaranteed to be fresh as it builds directly from the latest devcontainer.json.
To ensure consistency, verify your prebuild trigger settings in the repository's Codespaces configuration. If you are seeing stale environments, check if the prebuild is tracking the correct branch.
Diagnostic Detail Needed: Are you using a custom Dockerfile or a pre-defined image from a registry? (Custom Dockerfiles may require specific cache-busting strategies if the base image tag remains the same but the underlying image is updated).
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.