Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 124 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
name: Smoke test (C)
runs-on: ubuntu-latest
needs: [verify]
timeout-minutes: 30
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v7
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
needs: [verify]
timeout-minutes: 40
timeout-minutes: 20
env:
EXTERNAL_LITELLM_API_BASE: ${{ secrets.EXTERNAL_LITELLM_API_BASE }}
EXTERNAL_LITELLM_API_KEY: ${{ secrets.EXTERNAL_LITELLM_API_KEY }}
Expand Down Expand Up @@ -229,7 +229,7 @@ jobs:
--fuzz-proj-path oss_crs/tests/integration/fixtures/mock-c-project \
--target-source-path oss_crs/tests/integration/fixtures/mock-c-repo \
--target-harness fuzz_parse_buffer \
--timeout 1200 \
--timeout 600 \
--build-id smoke-c-patch \
--run-id bugfixing-c \
--pov-dir oss_crs/tests/integration/fixtures/mock-c-povs \
Expand Down Expand Up @@ -273,11 +273,131 @@ jobs:
if-no-files-found: warn
retention-days: 2

smoke-c-bugfinding-codex:
name: Smoke test (C agentic bug-finding)
if: |
github.actor != 'dependabot[bot]' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
needs: [verify]
timeout-minutes: 20
env:
EXTERNAL_LITELLM_API_BASE: ${{ secrets.EXTERNAL_LITELLM_API_BASE }}
EXTERNAL_LITELLM_API_KEY: ${{ secrets.EXTERNAL_LITELLM_API_KEY }}
steps:
- uses: actions/checkout@v4
Comment thread
azchin marked this conversation as resolved.
Resolved
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- run: uv sync --frozen --dev

- name: Create CI compose (bugfinding - codex)
run: |
mkdir -p /tmp/ci-config
cat > /tmp/ci-config/compose-bugfinding-codex.yaml << 'EOF'
run_env: local
docker_registry: local
oss_crs_infra:
cpuset: "0"
memory: "4G"
crs-bug-finding-codex:
cpuset: "1-3"
memory: "10G"
llm_budget: 5
additional_env:
CRS_AGENT: codex
CODEX_MODEL: gpt-5.2-codex
llm_config:
litellm:
mode: internal
internal:
config_path: /tmp/ci-config/litellm-bugfinding-codex.yaml
EOF

- name: Create CI litellm config (bugfinding codex)
run: |
cp example/crs-bug-finding-codex/litellm-config.yaml /tmp/ci-config/litellm-bugfinding-codex.yaml

- name: Setup mock-c repo as git
run: |
cd oss_crs/tests/integration/fixtures/mock-c-repo
git init
git config user.email "ci@test.com"
git config user.name "CI"
git add .
git commit -m "initial"

- name: Prepare CRSs
run: |
uv run oss-crs prepare \
--compose-file /tmp/ci-config/compose-bugfinding-codex.yaml \
--work-dir /tmp/oss-crs-work
Comment thread
azchin marked this conversation as resolved.
Resolved

- name: Build mock-c target
run: |
uv run oss-crs build-target \
--compose-file /tmp/ci-config/compose-bugfinding-codex.yaml \
--work-dir /tmp/oss-crs-work \
--fuzz-proj-path oss_crs/tests/integration/fixtures/mock-c-project \
--target-source-path oss_crs/tests/integration/fixtures/mock-c-repo \
--build-id smoke-c-bugfinding-codex

- name: Bugfinding (crs-bug-finding-codex)
run: |
uv run oss-crs run \
--compose-file /tmp/ci-config/compose-bugfinding-codex.yaml \
--work-dir /tmp/oss-crs-work \
--fuzz-proj-path oss_crs/tests/integration/fixtures/mock-c-project \
--target-source-path oss_crs/tests/integration/fixtures/mock-c-repo \
--target-harness fuzz_parse_buffer \
--timeout 600 \
--build-id smoke-c-bugfinding-codex \
--run-id bugfinding-c-codex \
--early-exit

- name: Verify POVs found
run: |
artifacts=$(uv run oss-crs artifacts \
--compose-file /tmp/ci-config/compose-bugfinding-codex.yaml \
--work-dir /tmp/oss-crs-work \
--fuzz-proj-path oss_crs/tests/integration/fixtures/mock-c-project \
--target-source-path oss_crs/tests/integration/fixtures/mock-c-repo \
--target-harness fuzz_parse_buffer \
--build-id smoke-c-bugfinding-codex \
--run-id bugfinding-c-codex)
echo "$artifacts" | jq .
pov_dir=$(echo "$artifacts" | jq -r '.crs | to_entries[0].value.pov')
echo "POV directory: $pov_dir"
if [ ! -d "$pov_dir" ] || [ -z "$(ls -A "$pov_dir")" ]; then
echo "ERROR: No POVs found"
exit 1
fi
pov_count=$(find "$pov_dir" -maxdepth 1 -type f | wc -l)
echo "Found $pov_count POV file(s)"

- name: Create smoke-c-bugfinding-codex workdir tarball
if: failure()
run: |
python scripts/create_workdir_tarball.py \
--output /tmp/smoke-c-bugfinding-codex-workdir.tar.gz \
--empty-message "No smoke-c-bugfinding-codex workdir artifacts were found."
tarball=/tmp/smoke-c-bugfinding-codex-workdir.tar.gz
ls -lh "$tarball"

- name: Upload smoke-c-bugfinding-codex workdir artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: smoke-c-bugfinding-codex-workdir
path: /tmp/smoke-c-bugfinding-codex-workdir.tar.gz
if-no-files-found: warn
retention-days: 2

smoke-java:
name: Smoke test (Java)
runs-on: ubuntu-latest
needs: [verify]
timeout-minutes: 30
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v7
Expand Down
8 changes: 7 additions & 1 deletion libCRS/libCRS/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,15 @@ def _submit_and_poll(
logger.error("Failed to submit job to %s: %s", endpoint, e)
return None

job_id = resp.json()["id"]
submit_result = resp.json()
job_id = submit_result["id"]
logger.info("Submitted job %s to %s", job_id, endpoint)

# Cache hits return status=done immediately; use the POST response
# directly so any rewritten fields (e.g. rebuild_id) are preserved.
if submit_result.get("status") == "done":
return submit_result

start = time.monotonic()
while time.monotonic() - start < timeout:
try:
Expand Down
32 changes: 32 additions & 0 deletions oss-crs-infra/builder-sidecar/docker_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,38 @@ def next_rebuild_id(rebuild_out_dir: Path, crs_name: str) -> int:
return max(existing, default=0) + 1


def stage_cached_rebuild(
rebuild_out_dir: Path, crs_name: str, src_rid: int, dst_rid: int
) -> None:
"""Materialize a cached rebuild tree into a caller-requested rebuild_id slot.

Files are hardlinked so the cached directory and the staged copy share
underlying inodes (near-zero disk cost), but remain independent: removing
one directory does not affect the other. Staging goes through a sibling
``.{dst_rid}.staging`` directory and is committed via an atomic rename so
concurrent readers never observe a partial tree.

Raises RuntimeError if the source rebuild directory does not exist.
"""
src_dir = rebuild_output_dir(rebuild_out_dir, crs_name, src_rid)
dst_dir = rebuild_output_dir(rebuild_out_dir, crs_name, dst_rid)
if not src_dir.is_dir():
raise RuntimeError(f"Cached rebuild artifacts missing: {src_dir}")

staging = dst_dir.parent / f".{dst_rid}.staging"
if staging.exists():
shutil.rmtree(staging)

def _hardlink(src: str, dst: str, *, follow_symlinks: bool = True) -> None:
os.link(src, dst, follow_symlinks=follow_symlinks)

shutil.copytree(src_dir, staging, copy_function=_hardlink)

if dst_dir.exists():
shutil.rmtree(dst_dir)
staging.rename(dst_dir)


def _run_ephemeral(
base_image: str,
rebuild_id: int,
Expand Down
33 changes: 31 additions & 2 deletions oss-crs-infra/builder-sidecar/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from fastapi import FastAPI, UploadFile, File, Form
from fastapi.responses import JSONResponse
from pydantic import BaseModel
import copy
import hashlib
import os
from concurrent.futures import ThreadPoolExecutor
Expand All @@ -36,6 +37,7 @@
next_rebuild_id,
run_ephemeral_build,
run_ephemeral_test,
stage_cached_rebuild,
)
import docker

Expand Down Expand Up @@ -75,6 +77,33 @@ def _make_job_id(patch_content: bytes, builder_name: str = "") -> str:
return hasher.hexdigest()[:12]


def _cached_response_for_rebuild_id(
cached: dict, crs_name: str, requested_rid: "int | None"
) -> dict:
"""Return a cache-hit response honoring a caller-supplied ``rebuild_id``.

When the caller passes an explicit ``rebuild_id`` that differs from the
cached one, hardlink-stage the cached rebuild tree into the requested
slot and return a *copy* of the cached entry with ``rebuild_id`` rewritten
to the requested value. The cached entry itself is left untouched so
subsequent callers still see the canonical (original) rebuild_id.

When the caller passes no ``rebuild_id`` (or it already matches), the
cached entry is returned as-is.
"""
result = cached.get("result") or {}
cached_rid = result.get("rebuild_id")
if requested_rid is None or cached_rid is None or requested_rid == cached_rid:
return cached

rebuild_out_dir = Path(os.environ.get("REBUILD_OUT_DIR", "/rebuild_out"))
stage_cached_rebuild(rebuild_out_dir, crs_name, cached_rid, requested_rid)

response = copy.deepcopy(cached)
response["result"]["rebuild_id"] = requested_rid
return response


# ---------------------------------------------------------------------------
# Endpoints
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -105,7 +134,7 @@ async def submit_build(
if existing["status"] == "done":
result = existing.get("result")
if result is not None and result.get("exit_code") == 0:
return existing
return _cached_response_for_rebuild_id(existing, crs_name, rebuild_id)

# Resolve rebuild_id if not provided
if rebuild_id is None:
Expand Down Expand Up @@ -161,7 +190,7 @@ async def run_test(
if existing["status"] == "done":
result = existing.get("result")
if result is not None and result.get("exit_code") == 0:
return existing
return _cached_response_for_rebuild_id(existing, crs_name, rebuild_id)

if rebuild_id is None:
rebuild_out_dir = Path(os.environ.get("REBUILD_OUT_DIR", "/rebuild_out"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,45 @@ def main() -> int:
fail(f"Rebuilt {harness_name} missing __llvm_profile symbols")
log(f"PASS: rebuilt {harness_name} contains __llvm_profile symbols")

# --- Cache-hit with different rebuild_id (build) ---
# Re-submit the same patch with an explicit rebuild_id that differs from the
# cached one. The sidecar should return quickly (cache hit), stage the
# cached artifacts at the new rebuild_id, and report the requested id.
alt_build_rid = rebuild_id + 100
log(
f"Re-submitting same patch with rebuild_id={alt_build_rid} (cached={rebuild_id})..."
)
cache_build_response = RESPONSE_DIR / "cache-build"
cache_build_rc = crs.apply_patch_build(
PATCH,
cache_build_response,
builder_name="default-build",
rebuild_id=alt_build_rid,
)
if cache_build_rc != 0:
fail(f"Cached build (alt rebuild_id) failed with exit code {cache_build_rc}")
cache_rid_file = cache_build_response / "rebuild_id"
if not cache_rid_file.exists():
fail("No rebuild_id returned from cached build")
cache_rid = int(cache_rid_file.read_text().strip())
if cache_rid != alt_build_rid:
fail(
f"Cached build returned rebuild_id={cache_rid}, expected {alt_build_rid}"
)
log(f"PASS: cached build returned requested rebuild_id={cache_rid}")

# Verify staged artifacts are accessible via download
cache_build_dir = Path("/tmp/cache-build-artifacts-py")
crs.download_build_output("build", cache_build_dir, rebuild_id=alt_build_rid)
cache_harness = cache_build_dir / harness_name
if not cache_harness.exists():
fail(
f"Staged harness {harness_name} not found at rebuild_id={alt_build_rid}"
)
log(
f"PASS: staged build artifacts downloadable at rebuild_id={alt_build_rid}"
)

# --- Apply patch + test ---
log("Running test.sh via Python API...")
test_response = RESPONSE_DIR / "test"
Expand All @@ -142,7 +181,9 @@ def main() -> int:
fail(f"Tests returned exit code {test_rc}")
log(f"Test exit code: {test_rc}")

# --- Run POV ---
# --- Run POV against unpatched base build (no rebuild_id) ---
# Without a rebuild_id the runner uses the original unpatched build, so the
# POV must trigger a sanitizer crash (non-zero exit code).
pov_dir = Path(fetch_dir) / "povs"
if not pov_dir.is_dir():
fail(f"POV directory {pov_dir} does not exist")
Expand All @@ -151,6 +192,32 @@ def main() -> int:
if not pov_files:
fail(f"No POV files found in {pov_dir}")

for pov_file in pov_files:
log(
f"Running POV {pov_file.name} against unpatched build (no rebuild_id)..."
)
unpatched_response = RESPONSE_DIR / "pov-unpatched"
unpatched_rc = crs.run_pov(pov_file, harness_name, unpatched_response)

log(f"Unpatched POV exit code: {unpatched_rc}")
stderr_file = unpatched_response / "stderr.log"
stderr_text = ""
if stderr_file.exists():
stderr_text = stderr_file.read_text()
log(f" stderr: {stderr_text.strip()[:200]}")

if unpatched_rc == 0:
fail(
f"POV {pov_file.name}: expected crash on unpatched build but got exit code 0"
)
if "Sanitizer" not in stderr_text:
fail(
f"POV {pov_file.name}: crash on unpatched build not from sanitizer — "
f"stderr: {stderr_text.strip()[:300]}"
)
log(f"PASS: POV {pov_file.name} triggers sanitizer crash on unpatched build with retcode {unpatched_rc}")

# --- Run POV against patched build (with rebuild_id) ---
for pov_file in pov_files:
log(
f"Running POV {pov_file.name} (harness={harness_name}, rebuild_id={rebuild_id})..."
Expand Down
Loading
Loading