Skip to main content

Bootstrap runner for Flywheel provisioned GPU instances

Project description

Bootstrap

This package hosts the BYOC bootstrapper that:

  • Ensures a pinned codex release is available (GitHub release assets).
  • Fetches the bootstrap payload for a run from the Flywheel backend.
  • Launches Codex app-server and streams notifications as logs.
  • Collects artifacts (manifest-on-exit) and reports completion or error back to the backend.

Configuration

Bootstrap reads the user's Codex config.toml (Codex schema). See:

Flywheel adds a small extension under [flywheel] and requires one of:

[flywheel]
# inline instructions (host-specific tips, paths, sandbox notes)
workspace_instructions = """
Use /mnt/work as your workspace. Write artifacts under ./artifacts.
"""

# or: reference a file (relative paths are resolved against the config file directory)
workspace_instructions_file = "workspace_notes.md"

Rules:

  • At least one of workspace_instructions or workspace_instructions_file is required; otherwise bootstrap exits before contacting the server.
  • If both are set, the file wins and the inline value is ignored (warns once).
  • File contents must be non-empty; the path is resolved relative to the config file if not absolute.

Bootstrap also reads a few optional Codex config fields because they affect workspace + sandbox behavior:

  • cd / workspace_dir (run working directory; defaults to ~/.flywheel/runs/<run_id>)
  • sandbox_mode and [sandbox_workspace_write].writable_roots

Prompt assembly (sent as the first Codex turn/start):

  1. Flywheel engineer context (logging/artifact expectations).
  2. Task Description (prompt fetched from the server).
  3. Workspace Instructions (resolved from config as above).

Full example config (recommended starting point):

Update the paths and instructions for your machine.

End-to-end flow (bootstrap.sh → Python bootstrapper)

  1. User runs the bootstrapper on their BYOC machine:

    BOOTSTRAP_PACKAGE="${FLYWHEEL_BOOTSTRAP_PACKAGE:-flywheel-bootstrap}"
    uvx --no-cache --from "$BOOTSTRAP_PACKAGE" flywheel-bootstrap \
      --run-id <id> --token <token> --config /path/to/config.toml [--server <url>]
    

    Optional: if you have this repo checked out, you can run project/bootstrap/bootstrap.sh, which installs uvx if missing and then runs the same command. It defaults FLYWHEEL_BOOTSTRAP_PACKAGE to the local project/bootstrap path.

  2. Python entrypoint (python -m bootstrap):

    • Parses args/env: requires run id + token, required --config, optional --server (default http://localhost:8000).
    • Loads Codex config.toml, enforces presence of workspace instructions (inline or file), extracts workspace/sandbox settings.
  3. Workspace resolution:

    • Uses cd/workspace_dir from config if set; otherwise ~/.flywheel/runs/<run_id>.
    • Creates the workspace and validates the artifact manifest path is inside sandbox writable_roots when sandboxing is enabled; else exits with an error.
  4. Engineer runtime availability:

    • If BOOTSTRAP_MOCK_ENGINEER is set, skips agent launch and runs a mock flow (used in tests).
    • Else, download a pinned Codex release asset and mark it executable.
  5. Fetch bootstrap payload:

    • GET <server>/runs/<run_id>/bootstrap with X-Run-Token; payload contains the task prompt.
  6. Build prompt text:

    • Combine base Flywheel engineer context, “Task Description” (server prompt), and “Workspace Instructions” (user config) into one prompt string.
  7. Launch engineer via Codex app-server:

    • Create a per-run CODEX_HOME directory at <workspace>/.codex_home containing a copied config.toml (with ~/ expanded).
    • Best-effort copy auth credentials from ~/.codex/auth.json into <workspace>/.codex_home/auth.json so Codex can authenticate.
    • Launch codex app-server as a subprocess and speak JSON-RPC over stdio (newline-delimited JSON; "jsonrpc":"2.0" header omitted):
      • initialize + initialized
      • thread/start
      • turn/start (first prompt = full Flywheel prompt; subsequent prompts = autonomous resume)
      • turn/interrupt for takeover/resume
      • Stream turn/*, item/*, and delta notifications (item/agentMessage/delta, item/commandExecution/outputDelta, etc.)
    • Bootstrap auto-accepts command/file approvals (for-session) when Codex requests them.
    • Start a heartbeat thread posting /runs/{id}/heartbeat.
    • Start a run-control polling thread (/runs/{id}/control/poll) to handle:
      • take_over (interrupt autonomous prompt turn; enter interactive mode)
      • send_input (start a new Codex turn with user input in interactive mode)
      • resume_autonomous (return to autonomous mode)
    • Convert thread/tokenUsage/updated totals into a turn.completed usage log for billing.
    • Stream app-server notifications as logs to /runs/{id}/logs.
  8. After the engineer prompt turn ends:

    • If code persistence is enabled, bootstrap commits/pushes non-artifact changes:
      • Excludes manifest-declared artifact paths from the git commit
      • Skips oversized files (default cap: 95 MiB, configurable via FLYWHEEL_GIT_MAX_COMMIT_FILE_SIZE_BYTES)
    • Artifact files referenced by payload.path/payload.file are embedded into artifact payloads when they are below the transfer threshold (default: 16 MiB, configurable via FLYWHEEL_ARTIFACT_BLOB_THRESHOLD_BYTES).
    • Read flywheel_artifacts.json; if missing/malformed/empty, retry up to MAX_ARTIFACT_RETRIES by prompting the engineer to fix/write the manifest.
    • POST artifacts to /runs/{id}/artifacts; POST /complete on exit 0, else /error with the exit code.
    • Stop/join the heartbeat thread.
  9. Mock mode (BOOTSTRAP_MOCK_ENGINEER=1):

    • Sends a heartbeat, a few logs, writes a mock artifact manifest, returns 0 (used in e2e tests).

Next steps

  • Iterate on prompts / general polish.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flywheel_bootstrap-0.1.9.202602102301.tar.gz (70.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flywheel_bootstrap-0.1.9.202602102301-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file flywheel_bootstrap-0.1.9.202602102301.tar.gz.

File metadata

  • Download URL: flywheel_bootstrap-0.1.9.202602102301.tar.gz
  • Upload date:
  • Size: 70.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flywheel_bootstrap-0.1.9.202602102301.tar.gz
Algorithm Hash digest
SHA256 b6a1a46181cdb09dcb57823dbe9471130be2825264301a79f70a1b6f866dddac
MD5 0a4e429e212ad3ff7cf83a232e4158fd
BLAKE2b-256 0e9795efc932e56aefdd52fdb97e642582cf8f97bf52a85eb5e692788d447379

See more details on using hashes here.

File details

Details for the file flywheel_bootstrap-0.1.9.202602102301-py3-none-any.whl.

File metadata

  • Download URL: flywheel_bootstrap-0.1.9.202602102301-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for flywheel_bootstrap-0.1.9.202602102301-py3-none-any.whl
Algorithm Hash digest
SHA256 0e44dcc0236f7dee0eb80b2cd5b81f5172db2fc22bba3a704cfc895d1f495f12
MD5 15de4ce92fd9b811ae972cee9c64a908
BLAKE2b-256 a6c33a46adca8a81608731a76b4dad3e0920bc5698ad3dd0eaf575ca57c3ccbf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page