Skip to content

refactor(builder-sidecar): ephemeral builder containers launched from host - #162

Merged
acorn421 merged 74 commits into
mainfrom
feat/125-sidecar
Apr 15, 2026
Merged

acorn421 merged 74 commits into
mainfrom
feat/125-sidecar

Conversation

@azchin

@azchin azchin commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Refactors the builder sidecar architecture per #125. Instead of CRS-declared long-running builder containers with snapshot configs (snapshot: true / run_snapshot: true), the framework now:

  • Injects builder and runner sidecars automatically during the run phase — CRS developers no longer declare them in crs.yaml
  • Launches ephemeral containers per rebuild from the preserved builder image, matching OSS-Fuzz's fresh-container-per-build lifecycle
  • Adds --incremental-build flag (operator-controlled) to build-target and run for Docker snapshot-based fast rebuilds
  • Renames run-test to apply-patch-test — patches are now applied in a fresh container rather than reusing a stateful build

Breaking changes

  • snapshot and run_snapshot fields removed from crs.yaml
  • OSS_CRS_SNAPSHOT_IMAGE env var removed
  • libCRS run-test replaced by libCRS apply-patch-test
  • --build-id in sidecar commands replaced by --rebuild-id
  • Response dir fields: build_exit_code → retcode, build_id → rebuild_id

Test plan

  • test_builder_sidecar_full — E2E: prepare → build-target → run with patch, POV, and test.sh through the full sidecar pipeline. Tests multiple builder configs (default-build + coverage-build) to verify custom/multi-builder support, coverage instrumentation verification, and rebuild artifact download.
  • test_builder_sidecar_lite — E2E: prepare → build-target → run with patch verification (build, rebuild, POV, test)
  • test_sidecar_lifecycle — Ephemeral container lifecycle: start, build, snapshot creation/reuse, cleanup on failure
  • test_env_policy — Framework injects BUILDER_MODULE and CRS cannot override it
  • crs-codex smoke test produces patch end-to-end (local, with apply-patch-build / run-pov / apply-patch-test)

Comment thread libCRS/libCRS/local.py Resolved
Comment thread oss-crs-infra/builder-sidecar/server.py Resolved
Comment thread oss-crs-infra/builder-sidecar/server.py Resolved
Comment thread oss_crs/src/target.py
repo_hash = self.__get_repo_hash()
return f"{self.name}:{repo_hash}-{sanitizer}-snapshot"

def _snapshot_lock_path(self, snapshot_tag: str) -> Path:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to restore this locking logic?

Comment thread oss_crs/src/target.py
cached_hash = cache_file.read_text().strip()
return cached_hash == base_image_hash and self._snapshot_exists(snapshot_tag)

def create_snapshot(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, seems odd we're completely removing snapshot logic from this module.

Comment thread oss_crs/src/ui.py Resolved
Comment thread oss_crs/src/utils.py Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acorn421 Can you check out these verify-patch-* scripts and make something similar using CRSBench for E2E testing?

@azchin
azchin force-pushed the feat/125-sidecar branch from 3b977a0 to f94fc6b Compare April 3, 2026 15:14
0xdkay added 2 commits April 3, 2026 17:33
…s context conflict)

Signed-off-by: Dongkwan Kim <0xdkay@gmail.com>
…source

Signed-off-by: Dongkwan Kim <0xdkay@gmail.com>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acorn421 Testing logic here for rebuild sidecar

azchin added 24 commits April 7, 2026 00:45
Builder-sidecar: FastAPI server that spawns ephemeral Docker containers
for builds and tests via Docker socket. Extracts build CMD from image
via docker inspect, disables REPLAY_ENABLED, uses oss_crs_handler.sh
for both build (image CMD) and test (test.sh).

Runner-sidecar: FastAPI server on base-runner for POV reproduction
via OSS-Fuzz reproduce script.

Simplify oss_crs_handler.sh to: git apply + run $OSS_CRS_BUILD_CMD.

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…-test

- apply-patch-build: submit patch to builder-sidecar, poll for result
- apply-patch-test: renamed from run-test, takes patch_path explicitly
- run-pov: submit POV to runner-sidecar
- download-build-output: fetch versioned artifacts as zip
- Remove _last_patch_path stateful hack (broken across CLI invocations)

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…builder

- Sidecar injection triggered by any CRS with snapshot builds
- Remove _builder_crs property and "at most one builder" restriction
- Remove is_builder gates from LLM, bug-finding, and compose template
- Fix BASE_IMAGE to use snapshot image instead of raw target
- Add get_rebuild_out_dir to workdir for sidecar artifact storage

Signed-off-by: Andrew Chin <achin34@gatech.edu>
- Unit tests for builder-sidecar, runner-sidecar, and libCRS sidecar methods
- Integration tests for sidecar lifecycle
- sandbox/crs-sidecar-test: manual e2e test CRS with ground-truth patch
- Remove old builder/ directory (replaced by builder-sidecar)

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…g properties

- Remove snapshot: bool from BuildConfig
- Remove run_snapshot: bool from CRSRunPhaseModule
- Update validate_dockerfile_requirement: all modules always require dockerfile
- Remove snapshot_builds, has_snapshot, has_builder_module properties from CRSConfig
- Delete test_snapshot_flag, test_snapshot_module_can_omit_dockerfile tests
- Add test_module_requires_dockerfile_always test

Signed-off-by: Andrew Chin <achin34@gatech.edu>
- Remove _any_needs_snapshot property from CRSCompose
- Remove snapshot creation block from CRSCompose.build_target()
- Remove snapshot image check and snapshot_image_tag assignment from CRSCompose.run()
- Replace non_snapshot_builds filter with plain builds in CRS.build_target() and is_target_built()
- Remove snapshot_image_tag attr, create_snapshot(), get_snapshot_image_name(),
  _snapshot_lock_path(), _snapshot_exists(), _is_snapshot_reusable(), _get_base_image_hash() from Target
- Remove tempfile import (no longer needed)
- Update renderer.py: disable sidecar injection (has_sidecar=False), remove snapshot_image_tag
  from target reference, remove run_snapshot logic from module env computation
- Update Jinja2 template: remove run_snapshot conditional blocks
- Delete test_crs_compose_snapshot_sanitizer.py and test_target_snapshot.py

Signed-off-by: Andrew Chin <achin34@gatech.edu>
- Remove has_sidecar conditional; sidecars now always injected as infra
- Compute rebuild_out_dir unconditionally from crs_list[0]
- Remove snapshot_image_tag, has_sidecar, sidecar_crs_name from context
- Template: replace single sidecar_crs_name alias with crs_list loop
- Template: BASE_IMAGE uses target.get_docker_image_name() unconditionally
- Sandbox crs.yaml: remove inc-builder snapshot build entry

Signed-off-by: Andrew Chin <achin34@gatech.edu>
- Add --incremental-build store_true arg to build-target subcommand
- Add --incremental-build store_true arg to run subcommand
- Pass incremental_build=args.incremental_build in both CLI dispatch sites
- Add incremental_build: bool = False to CRSCompose.build_target() signature
- Add incremental_build: bool = False to CRSCompose.run() signature
- Thread incremental_build through __run(), __run_local(), __prepare_local_running_env()
- 4 unit tests verify flag parsing on both subcommands (present/absent)

Signed-off-by: Andrew Chin <achin34@gatech.edu>
- get_test_image() signature drops builder_name parameter per D-05
- run_ephemeral_test() snapshot_tag and commit tag use test-{build_id}
- server.py _handle_test() updated to call get_test_image() without builder_name
- All sidecar tests updated to assert test-{build_id} format (no builder_name)

Signed-off-by: Andrew Chin <achin34@gatech.edu>
- Add docker/requests.exceptions imports to crs_compose.py
- _snapshot_one(): helper to run a container from base_image and commit on success
- _create_incremental_snapshots(): commit builder snapshots (build-{name}-{build_id}) and
  project image snapshot (test-{build_id}) with all-or-nothing cleanup on failure (D-04/D-05/D-06)
- _check_snapshots_exist(): pre-run validation returning clear error with oss-crs build-target
  --incremental-build instructions when any snapshot is missing (SNAP-05/D-09)
- Wire _create_incremental_snapshots into build_target() after success, gated by incremental_build
- Wire _check_snapshots_exist into run() before compose starts, gated by incremental_build
- 9 unit tests passing with mocked Docker SDK

Signed-off-by: Andrew Chin <achin34@gatech.edu>
- _handle_test() now reads PROJECT_BASE_IMAGE env var directly (not BASE_IMAGE_*)
- Raises ValueError if PROJECT_BASE_IMAGE is not set (clear error message)
- Template unconditionally emits PROJECT_BASE_IMAGE on builder-sidecar service
- Module docstring documents the new env var

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…ts on --incremental-build flag

- Bundle oss_crs_handler.sh in sidecar image and bind-mount into ephemeral
  build/test containers via HANDLER_SCRIPT_PATH env var
- Sidecar only uses snapshot images when INCREMENTAL_BUILD=true (fresh base
  image otherwise), enforcing SNAP-04
- Forward OSS-Fuzz env vars (FUZZING_ENGINE, SANITIZER, ARCHITECTURE,
  FUZZING_LANGUAGE) from sidecar to ephemeral containers
- Stream ephemeral container logs to sidecar stdout with [build:name]/[test:id]
  prefix while still capturing for response
- Extract OSS_FUZZ_TARGET_ENV constant in env_policy.py to dedup env var definitions

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…rce limits

- Replace v1/v2 versioning with rebuild_id (auto-incrementing int, optional
  override). Output dir: /rebuild_out/{crs_name}/{rebuild_id}/
- Merge download_rebuild_output into download_build_output: with rebuild_id
  fetches from sidecar, without uses local filesystem. Ephemeral containers
  auto-try sidecar via OSS_CRS_REBUILD_ID env var, fallback to local.
- Rename build_id to rebuild_id on sidecar endpoints; add crs_name form field
- Forward CRS resource limits (cpuset, mem_limit) per-request to ephemeral containers
- Replace sequential job queue with ThreadPoolExecutor (MAX_PARALLEL_JOBS=4)
- Remove dead include_snapshot code from env_policy and renderer

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…ardized response files

- builder defaults to BUILDER_MODULE env var; run_pov defaults to runner-sidecar
- builder_name param separates service routing from image resolution
- submit_build_output validates OSS_CRS_CURRENT_PHASE: local at build-target, sidecar upload at run
- response dir files standardized: retcode, stdout.log, stderr.log, rebuild_id
- run_pov takes rebuild_id (int) instead of build_id (str)

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…_output_dir

- POST /upload-build-output on builder sidecar for run-phase artifact pre-staging
- rebuild_output_dir() extracted as shared path helper
- runner-sidecar: build_id -> rebuild_id, stdout added to POVResult

Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
…OSS_CRS_PROJ_PATH/test.sh)

- New run_tests.sh script resolves test script with fallback chain
- Mounted into both sidecar ephemeral containers and orchestrator snapshot containers
- Replaces hardcoded test.sh references in docker_ops.py and crs_compose.py
- Test snapshot is optional (skip if no test script found)

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…ecified

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…{crs_name}/{rebuild_id}/

- Replace /out bind mount with container.get_archive() to preserve snapshot
  state + new files (bind mount was shadowing snapshot's prebuilt /out)
- Runner sidecar takes crs_name, resolves harness at /out/{crs_name}/{rebuild_id}/
- libCRS run_pov sends crs_name to runner

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…compile)

Signed-off-by: Andrew Chin <achin34@gatech.edu>
…(OOM on compile)"

This reverts commit 1f5a6bd0ee7f10b973f54c63806ed0c3a1660cb5.

Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
acorn421 added 2 commits April 8, 2026 23:57
…iner

Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
acorn421 and others added 12 commits April 9, 2026 01:13
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
…e RTS in content key

Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
…call in verify_patch

Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
…gistry entries

Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
refactor: replace download-source with mount-based API
Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
…mits

Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
acorn421 and others added 10 commits April 11, 2026 03:59
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Andrew Chin <achin34@gatech.edu>
… does mkdir

Signed-off-by: Andrew Chin <achin34@gatech.edu>
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
…ail configurable

Signed-off-by: Youngjoon Kim <acorn421@gmail.com>
@acorn421
acorn421 merged commit 21fbf0b into main Apr 15, 2026
6 checks passed
@acorn421
acorn421 deleted the feat/125-sidecar branch April 15, 2026 05:55
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.

5 participants