Skip to content

fix(examples): background-process and entrypoint examples no longer race their sandbox - #113

Merged
bchatelard merged 2 commits into
mainfrom
example-races
Nov 5, 2026
Merged

bchatelard merged 2 commits into
mainfrom
example-races

Conversation

@bchatelard

Copy link
Copy Markdown
Member

Two examples race the sandbox they create and fail intermittently when they run as automated tests: 13_background_processes.py kills a process that may have ended, and 19_entrypoint_and_command.py reads the file its image writes before the image has written it.

Why

We run every example as an automated test, many times a day. Over a week of runs:

  • 6 failures of 13_background_processes.py with 400 {"success":false,"error":"process is not running (status: completed)"}. Process 2 runs for 5 s and is killed after a 2 s sleep plus a few API round trips; when those take over 3 s it has already ended. The two sleep 5 processes killed by kill_all_processes() have the same race (assert killed_count >= 2).
  • 19_entrypoint_and_command.py has the race its JavaScript twin fails on (11 times in the same week, Expected 'yes', got ''): a sandbox is ready once its executor answers, and the image's own command (the custom command or entrypoint under test) may not have written its marker file yet.

What changed

  • examples/13_background_processes.py: process 2 and the two sleep processes run for 60 s. Every one of them is killed, so the example takes no longer.
  • examples/19_entrypoint_and_command.py: both checks wait up to 10 s (every 0.2 s, in the sandbox's shell) for the file before reading it.

The same 19_entrypoint_and_command change goes into the JavaScript SDK's example.

How it was verified

  • Both examples run against a test environment: they pass, every process in 13_background_processes.py ends killed, and their sandboxes are deleted.
  • black --check passes on both files.

…lled

Process 2 ran for 5 s and was killed after a 2 s sleep plus a few API
round trips; when those took over 3 s it had already ended, and the kill
failed with 400 "process is not running (status: completed)". The two
"sleep 5" processes killed by kill_all_processes had the same race. Let
them run for 60 s: every one is killed, so the example takes no longer.
…mand

A sandbox is ready once its executor answers; the image's own command
(the custom command or entrypoint under test) may not have written its
file yet, so the first read could come back empty. Wait up to 10 s for
the file before reading it.
@bchatelard
bchatelard marked this pull request as ready for review November 5, 2026 20:55
@bchatelard
bchatelard merged commit ee96109 into main Nov 5, 2026
10 checks passed
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