A pinned CPU does not keep a Codespace alive
The machine was working as hard as it is possible for it to work, and it was stopped anyway. top reporting 0.0% idle is the obvious evidence that a Codespace is in use, and it is evidence of nothing — the idle timer is counting your connection, not the load.
The claim being tested
A Codespace created with --idle-timeout 5m has a job pinning both its cores. Does the timeout fire?
The documentation does not promise either answer. GitHub defines inactivity as "the absence of activity indicative of a user's presence", and says that "Personal interaction with a codespace, such as typing or using the mouse, resets the idle timeout period" and that "Terminal activity, either input or output, also resets the idle timeout period." The lifecycle page adds that "When you stop a codespace, any running processes are stopped", but nowhere says whether a running process resets the timer. "Terminal activity, either input or output" is easy to read as covering a busy job, so this is worth measuring rather than assuming.
Measured: it fires. Twice, within three seconds of each other.
Setup
One Codespace, basicLinux32gb, two cores. The API confirms the timeout was actually applied rather than silently defaulted to 30 minutes:
state=Available idle=5min machine=basicLinux32gb
The load is four busy-loops plus a heartbeat logger, started with nohup setsid so they are detached from the SSH session and survive it:
nohup setsid bash -c 'for i in 1 2 3 4; do (while :; do :; done) & done;
while :; do printf "%s load=%s running=%s\n" "$(date -u +%H:%M:%SZ)" \
"$(cut -d" " -f1 /proc/loadavg)" "$(cut -d" " -f4 /proc/loadavg)" \
>> /workspaces/spin.log; sleep 10; done' >/dev/null 2>&1 &
Three seconds before disconnecting, the machine is saturated:
top - 01:02:26 up 12 min, 0 user, load average: 5.09, 5.25, 2.45
Tasks: 18 total, 6 running, 12 sleeping, 0 stopped, 0 zombie
%Cpu(s): 95.7 us, 4.3 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
0.0 id. Load 5.09 on two cores. Note 0 user — no logged-in user, which is the whole point: the work is real and nobody is watching it.
The result
Disconnected at 01:02:23Z. Polled from outside the machine, every 26 seconds:
01:02:28Z Available
01:02:54Z Available
01:03:20Z Available
01:03:46Z Available
01:04:12Z Available
01:04:38Z Available
01:05:04Z Available
01:05:30Z Available
01:05:56Z Available
01:06:22Z Available
01:06:52Z Available
01:07:18Z ShuttingDown
4 minutes 55 seconds after the SSH session closed. The first run, with the same setup, gave 4 minutes 58 seconds. The timer is clearly anchored on the connection, and the load contributed nothing.
Proving the CPU was still busy at the moment it was stopped
This is the part the first attempt got wrong, and it is the difference between a measurement and a story.
Attempt one logged heartbeats to /tmp. After the restart the file was gone:
tail: cannot open '/tmp/spin.log' for reading: No such file or directory
/tmp does not survive a stop; only the workspace volume does. So the first run proved the machine was saturated *at the moment I disconnected* and said nothing about the four minutes after — which is exactly the interval in question. Re-run, logging to the persisted workspace instead:
--- heartbeat lines written while disconnected ---
30
--- first 2 ---
01:02:04Z load=5.32 running=7/402
01:02:14Z load=5.20 running=6/408
--- last 4 before the stop ---
01:06:24Z load=4.96 running=7/392
01:06:34Z load=4.89 running=5/392
01:06:44Z load=4.84 running=6/395
01:06:54Z load=5.40 running=8/414
Thirty heartbeats, unbroken, load never below 4.8 on a two-core box, the last one written 24 seconds before ShuttingDown was observed. The work was running at full tilt right up to the stop, and the stop happened on schedule.
The control: can this test detect a Codespace staying alive?
A test that reports "stopped" is worthless if it would report "stopped" regardless. So the same Codespace, restarted, with the load removed and a single SSH connection held open doing nothing at all:
01:08:25Z holding connection open for 480s, no load
01:16:39Z connection closed
Eight minutes fourteen seconds — well past the five-minute timeout — with zero CPU load, no terminal output and no keystrokes. State checked afterwards:
01:17:29Z
state=Available last_used=2026-11-27T19:07:53-06:00
Still Available. So:
| condition | duration | outcome |
|---|---|---|
| disconnected, both cores at 100% | 4m55s | stopped |
| disconnected, both cores at 100% (run 1) | 4m58s | stopped |
| connected, completely idle | 8m14s | still running |
The idle connection survived nearly twice as long as the saturated one. The test can distinguish the two cases, so the two stops mean something.
The diagnostic gives the opposite answer from the one that matters. top, uptime and /proc/loadavg all say this machine is as busy as it can be. The timer is not reading any of them. An empty connection outlives a saturated disconnected machine.
A field that looks like the timer and is not
last_used_at is the obvious candidate for "what the timeout counts from". It is not. Through the whole of run one — an SSH session, four busy loops, five minutes of elapsed time — it never moved off the creation timestamp:
00:55:27Z state=Available last_used=2026-11-27T18:53:18-06:00
00:58:50Z state=Available last_used=2026-11-27T18:53:18-06:00
00:59:21Z state=ShuttingDown last_used=2026-11-27T18:53:18-06:00
Created 18:53:18, still 18:53:18 at shutdown. After the restart it became 19:07:53 — the restart time. It tracks when the Codespace was started, not when it was last touched, so it cannot be used to predict a shutdown and a monitor built on it will look healthy right up to the stop.
An aside that cost twenty minutes
Immediately after the first restart, the load average read 12.35 and I briefly believed the busy loops had survived the stop. They had not. Process ages settle it:
PID ELAPSED %CPU COMMAND
78 57 1.7 dockerd --containerd /run/containerd/containerd.sock ...
77 57 0.2 /usr/bin/containerd --config /etc/containerd/config.toml
1 58 0.0 /sbin/docker-init -- /bin/sh -c echo Container started ...
36 57 0.0 sshd: /usr/sbin/sshd [listener] 0 of 10-100 startups
Every process is 58 seconds old or younger: the container was rebuilt, and the 12.35 was its own startup burst. A load average is a decaying mean over the previous minutes and it does not care that the machine it was measured on is, in effect, a different machine. ELAPSED is the artefact; the load average is an impression.
What to do about it
Set the timeout for the job, before you start it
gh codespace create ... --idle-timeout 90m
The documented range is 5 to 240 minutes, and the API field confirms what was applied — idle=5min above was read back, not assumed. Pick a number that covers the work, deliberately, and remember there is also a hard 12-hour lifetime no setting changes.
Do not keep a connection alive purely to defeat the timeout. The timeout is a spending control on a machine somebody is billed for; the fix for "my job needs four hours" is to ask for four hours, or to run it somewhere built for unattended work. A trick that silently converts a 5-minute idle policy into an all-night bill is the wrong fix even when it works.
Write results where they survive
Measured above: /tmp was empty after the stop, the workspace volume was intact. Anything a long job produces should land in the workspace, or be pushed somewhere, before the job ends — not left in /tmp to be collected later.
Make the job resumable rather than long
A stop is not a failure you can prevent, only one you can be ready for. A job that appends progress to a persisted file and can restart from it loses minutes; a job that holds four hours of state in memory loses four hours.
Check state from outside, not from inside
The machine cannot tell you it is about to be stopped, and the field that looks like it would — last_used_at — does not move. The only reliable signal is the state field, polled externally.
Why this one is worth a page
- Every local signal says the opposite. 0.0% idle, load 5, processes
running. None of it is an input to the decision.
- The documentation is silent rather than wrong. It never says a busy
process keeps the machine alive, and it never says it does not. "Terminal activity, either input or output" is a sentence you can read either way, which is precisely when measuring beats reading.
- The obvious monitoring field is inert.
last_used_atstays frozen
through the entire countdown.
- The loss is silent and total. Processes are stopped,
/tmpis gone, and
nothing in the Codespace recorded why.
The general form: when a resource is reclaimed on "inactivity", find out whose activity is being measured. It is rarely the work. It is usually the person.
Measured on
One GitHub Codespace, machine type basicLinux32gb (2 cores, 8 GB), --idle-timeout 5m confirmed via the API as idle_timeout_minutes: 5, Ubuntu container, accessed over gh codespace ssh from Windows 11 Git Bash with GitHub CLI 2.92.0, on 2026-11-28 UTC. All timestamps are UTC as printed by the machines that produced them. Two independent runs of the load case and one connected control; the Codespace was deleted immediately afterwards and gh codespace list confirmed empty. The Codespace's generated name and its repository are not given here and are not needed to reproduce any of this; /workspaces is the real persisted mount point. Quoted documentation is from GitHub's pages on setting the timeout period and on the Codespace lifecycle, read the same day. Three runs is not a distribution — the two load runs agreed to within three seconds, which is enough to say the timer is not reading the CPU, and not enough to say anything precise about its resolution.