Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
117 changes: 117 additions & 0 deletions CI_AND_FUZZ_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# CI and adversarial fuzz audit — Q00/ouroboros PR #3129 and #3130

Date: 2026-11-30
Stage: `evolve-r1-security-and-boundary-audit`
Audit worktree: `/Users/san/.gemini/antigravity/scratch/night-20261130/worktrees/ouroboros-fuzz-lab`

## Live GitHub Actions

The PR heads inspected were #3129 `e8d3f17d` (`feat/cloud-sandbox-runtime-20261130`) and #3130 `060966d` (`feat/personal-agent-vm-runtime-20261130`). No PR was merged or modified.

- **PR #3129:** all listed checks passed except `Test Python 3.12`, which completed with **failure** in run [46306082223](https://github.com/Q00/ouroboros/actions/runs/46306082223), job [141481600729](https://github.com/Q00/ouroboros/actions/runs/46306082223/job/141481600729). The failed run was inspected with `gh run view --log-failed`.
- **PR #3129 failure:** `tests/unit/cloud/test_runtime.py::test_local_host_with_portable_runtime_dir_is_not_marked_limited`; aggregate result was `1 failed, 38888 passed, 319 skipped, 1 xfailed`. The test obtains `Path.home()` after the hermetic test fixture has redirected HOME to `/tmp/pytest-of-runner/...`; the cloud detector correctly labels that path ephemeral, so `home_restricted` is true and the test assertion fails.
- **PR #3130:** all listed checks passed, including `Test Python 3.12`, in run [46306049135](https://github.com/Q00/ouroboros/actions/runs/46306049135), job [141481491381](https://github.com/Q00/ouroboros/actions/runs/46306049135/job/141481491381).
- No other failed jobs were present in the inspected check lists. Advisory performance checks were skipped as expected.

The CI failure is reproducible from the log and is independent of the three runtime behaviors found below. A safe test-only repair is to construct a dedicated test HOME and make `tempfile.gettempdir()` a separate sentinel, or otherwise avoid deriving the “portable” fixture from the hermetic `Path.home()` under `/tmp`.

## Snapshot and method

A read-only snapshot of `src/ouroboros/cloud` was copied from source commit `e8d3f17d` into `snapshot/cloud-v1/`. The minimal `snapshot/ouroboros` wrapper only makes that copied package importable for this audit. The assigned `ouroboros-cloud-runtime` worktree was clean at initial inspection; by the final status check it had uncommitted changes in six files (`bundle.py`, `driver.py`, `state.py`, two cloud docs, and the cloud regression test). Those changes appeared outside this audit; they were not edited, reverted, or overwritten. Findings below are explicitly against the captured `e8d3f17d` snapshot.

The audit covered corrupted JSON state, generated malformed state objects, concurrent `CloudDriver.next()` calls, tar member traversal and absolute paths, symlink and hardlink members, duplicate members, oversized members, existing symlink targets, non-zero step exit codes, read-only HOME/XDG paths, and imported bundle behavior.

## Results

The copied upstream cloud regression file passed **26 tests**. The adversarial suite plus that regression file passed **32 tests, 3 expected failures**. The expected failures are intentional assertions of defects in the snapshot and are listed below. All other adversarial cases passed their fail-closed or detection assertions.

| Area | Result | Evidence |
| --- | --- | --- |
| Corrupted local JSON and 200 generated state shapes | Pass | Parser raises validation errors without rewriting the payload; valid parses retain list/string invariants. |
| Bundle traversal, absolute paths, symlink/hardlink members, duplicates, oversize members | Pass | Import rejects before replacing the known-good destination state. |
| Existing destination symlink target | Pass | Import rejects and leaves the outside file and prior state unchanged. |
| Non-zero step exit | Pass | Return code is recorded and `verify()` remains false even with evidence. |
| Read-only HOME and XDG_CONFIG_HOME | Pass on unprivileged audit host | Detector marks both restricted and does not create probes; root-like hosts may report mode-bit behavior differently. |
| Existing cloud regression suite | Pass | `26 passed`. |
| Replanning evidence isolation | **Finding** | A prior step-0 evidence record survives `plan()` and makes an identical new one-step plan verify without new evidence. |
| Concurrent `next()` serialization | **Finding** | Two processes both execute the one planned shell step (`counter == "xx"`) while the final JSON contains one checkpoint. |
| Imported bootstrap mode | **Finding** | Export marks `bootstrap.sh` 0755, but import writes it with `mkstemp` permissions 0600. |

## Actionable findings

### F1 — stale evidence survives a new plan (contract risk, high)

`CloudDriver.plan()` resets `plan`, `next_step`, `checkpoints`, and receipts but does not clear `state.evidence` (`src/ouroboros/cloud/driver.py:52-62`). Reusing a step index lets old evidence satisfy a new plan. In the audit, a completed `true` plan with evidence was replaced by another `true` plan; the second `verify()` returned `True` without recording new evidence.

**Fix:** clear `state.evidence` whenever a new plan replaces the old plan, or attach a plan/run identifier to evidence and require it to match during verification. Add a regression that replanning cannot reuse prior evidence.

### F2 — concurrent `next()` duplicates host-side effects (contract/security risk, high if callers can overlap)

`CloudDriver.next()` performs load → subprocess → append → save without a cross-process lock (`src/ouroboros/cloud/driver.py:102-132`). Two processes can load the same `next_step`, execute the same command, and atomically overwrite each other’s JSON. The final checkpoint looks singular, while the external command ran twice. PR #3130 explicitly calls cross-process receipt locking a non-goal for its integration runtime; this finding applies to the cloud driver’s own “planned commands run ... once each” promise.

**Fix:** either serialize each workspace run with a cross-platform lock held across load/execute/save, or make the contract explicitly reject concurrent callers and add a durable compare-and-swap revision check before committing a checkpoint. Add a subprocess race regression that counts side effects, not only final JSON shape.

### F3 — bundle import drops the bootstrap executable bit (portability defect, medium)

`_write_deterministic_tar()` emits `bootstrap.sh` with mode 0755, but `_write_regular_file()` uses `mkstemp()` and replaces the destination without restoring executable permissions (`src/ouroboros/cloud/bundle.py:154-167, 321-331`). An imported bundle’s `bootstrap.sh` is 0600 and cannot be invoked as `./bootstrap.sh`.

**Fix:** pass an explicit mode to `_write_regular_file()` and apply `0o755` to the bootstrap destination after the atomic replace, while keeping state JSON at 0600/0644 as intended. Add an import mode regression.

## What held

Malformed state fails closed; checksum validation protects an existing checkpoint; bundle member allowlisting and target checks stop traversal and symlink replacement; non-zero commands cannot verify; and state remains workspace-local when HOME/XDG are unavailable. No source fix was applied because the task explicitly assigns this worktree as the audit lab and forbids editing `ouroboros-cloud-runtime` directly. The final dirty state of that separate worktree was preserved for its owner.

## Reproduction commands

```bash
PYTHONPATH="$PWD/snapshot" \
/Users/san/.gemini/antigravity/scratch/night-20261130/worktrees/ouroboros-cloud-runtime/.venv/bin/python \
-m pytest -q fuzz_tests/test_cloud_runtime_adversarial.py \
fuzz_tests/test_upstream_cloud_runtime_snapshot.py

PYTHONPATH="$PWD/snapshot" \
/Users/san/.gemini/antigravity/scratch/night-20261130/worktrees/ouroboros-cloud-runtime/.venv/bin/python \
-m ruff check fuzz_tests
```

Observed: `32 passed, 3 xfailed`; Ruff passed.

## Scope limits

This stage inspected live CI for both PRs and fuzzed the copied cloud runtime for the requested sandbox cases. It did not claim live paid VM/provider execution for #3130; its required CI checks were green. No merge, push, or PR update was performed.

## Round 1 follow-up — 2026-11-30

The initial three strict xfails were converted into passing regressions and fixed in both snapshot copies:

- `CloudDriver.plan()` now clears evidence and all mutating driver operations serialize on a workspace lock. The lock rejects symlink targets and uses `flock` on POSIX or `msvcrt` on Windows.
- Bundle import writes `bootstrap.sh` with mode `0755`, writes state with mode `0600`, applies a Git patch before replacing state, and rolls back patch/files after injected post-apply failures.
- New fault-injection and path-isolation tests cover patch failure before state mutation, bootstrap write failure after patch application, and a hostile lock symlink.

Round 1 verification: `38 passed`, compileall passed, relevant Ruff scope passed with the snapshot's existing `TRY004` contract warnings excluded, and `git diff --check` passed. Detailed evidence is in `docs/verification/2026-11-30-evolve-r1-security-boundary-audit.md`.

## Round 2 follow-up — 2026-11-30

The empirical scale and latency audit found and fixed four concrete issues in both snapshot copies.

- `CloudDriver.verify()` could pass after `init()` or `plan([])`, and whitespace-only evidence counted as observable. Verification now requires a non-empty executed plan and stripped non-blank evidence. Non-finite evidence values are rejected.
- Verification receipts grew without a bound. The state retains the latest 128 receipts. A 384-iteration measurement completed in 1.597 seconds with a 30,544-byte state file and a 272,202-byte `tracemalloc` peak.
- Shell output was captured without a limit. Concurrent pipe drainers now retain at most 1 MiB per stream and mark truncation. A 3,000,000-byte producer completed successfully with 1,048,616 retained stdout bytes and a 1,049,218-byte state file.
- Bundle export could race with step execution. Export now holds the workspace lock over the state snapshot and Git patch generation. An eight-process execution stress test completed with exactly one checkpoint per planned step.

Round 2 verification passed with `44 passed`, scoped Ruff passed with the snapshot's existing `TRY004` contract warnings excluded, `py_compile` passed, and `git diff --check` passed. The deterministic acceptance command passed. The live PR check observation was separate from this local verification. PR #3129 remained Draft with Windows sandbox failed and Python 3.12 pending at the final poll. PR #3130 remained Draft with all listed checks passing. No PR was merged.

## Round 3 follow-up — 2026-11-30

The crash, disconnect, restart, and import-race audit found four concrete gaps in both cloud snapshot copies.

- **Uncertain subprocess outcome could be replayed.** `next()` previously saved a checkpoint only after the shell returned. A process killed after the command's side effect and before that save would execute the same step again after restart. `active_step` is now written and directory-synced before execution. Restart refuses to run an uncertain step and reports the interrupted index. An explicit `retry_interrupted=True` is required after workspace inspection. A SIGSTOP/SIGKILL fixture proves the side effect remains a single `x` and the restart does not invoke the step again.
- **Bundle import could cross an executing step.** Import validated and applied state without taking the workspace lock used by `next()`. Import now holds the destination lock across validation, patch application, file replacement, schema re-read, and rollback. A blocked bootstrap write proves a concurrent `next()` remains blocked and observes the imported state afterward.
- **Atomic state replacement lacked parent-directory durability.** State payloads and the temporary file were fsynced, but the directory entry created by `os.replace` was not. POSIX saves now fsync the state directory after replacement. A regression observes both file and directory descriptors being synced. Windows retains its platform-specific no-op because directory fsync is unavailable through this path.
- **Malformed persisted state crossed the parser boundary.** `int()` accepted boolean and fractional versions, and loaded plans could contain blank commands. Version 1, non-empty commands, and a matching active-step marker are now required. The generated corpus and explicit malformed-state cases fail closed without rewriting the payload.

Round 3 verification passed with `49 passed in 3.45s`, scoped Ruff, `py_compile`, and byte-for-byte equality between the two cloud snapshot copies. The 384-call verification benchmark completed in 1.736 seconds with 128 receipts, a 34,495-byte state file, and a 290,783-byte `tracemalloc` peak. The deterministic acceptance command passed after the report update.

The live recheck observed PR #3129 as Draft with its new Python 3.12, Windows sandbox, and Claude SDK jobs passing. The earlier Windows failure remains explained by the public log's sandbox probe timeout in run `46311664418`. PR #3130 remains Draft with its fresh Python 3.12 and Windows jobs pending while its other listed checks pass. Draft PR #3133 initially failed the issue-link gate because it had no issue reference or exemption label. The documented `no-issue` label was applied, which reruns that check. These remote observations do not claim that the fuzz-lab branch is the production PR head.

The power-loss path was tested at the fsync contract level. A physical power cut and paid provider execution were not exercised. Draft PR #3133 initially failed its issue-link gate because the no-issue exemption label was absent. The label was added and the check rerun. No PR was merged and no secret or token was written.
14 changes: 14 additions & 0 deletions STATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Fuzz lab state

- 목표: Q00/ouroboros PR #3129/#3130의 라이브 CI와 cloud runtime adversarial behavior를 독립 검증하고 Round 3 crash/disconnect/restart findings를 수정·기록한다.
- 금지선: 모든 편집·테스트·git 작업은 fuzz-lab worktree에서 수행; PR merge 금지; 비밀값 저장 금지; 기존 PR head force-push 금지.
- 확인된 사실: `origin/main`은 `35ce8911`로 fetch됐고 fuzz-lab HEAD와 공통 merge-base가 없다. 기존 PR #3129 head는 `58797a93`이다.
- 확인된 사실: Round 2 baseline은 `1d71e308`과 44 passed였다. Round 3 수정 후 cloud adversarial+upstream suite는 49 passed다.
- 확인된 사실: subprocess 실행 전 durable `active_step` marker와 POSIX directory fsync를 추가했다. restart는 불확실한 step을 기본 거부하며 `retry_interrupted=True`만 재시도를 허용한다.
- 확인된 사실: import가 destination workspace lock을 validation부터 rollback까지 공유하도록 수정했다. malformed version, blank plan, mismatched active marker는 fail closed한다.
- 확인된 사실: 384회 verify는 1.736초, receipts 128개, state 34,495 bytes, tracemalloc peak 290,783 bytes였다.
- 확인된 사실: `CI_AND_FUZZ_REPORT.md`와 dated Round 3 evidence, required live-feedback log가 존재한다. 결정론적 acceptance gate, py_compile, scoped Ruff, duplicate snapshot comparison, diff check가 통과했다.
- 확인된 사실: PR #3129는 Draft이며 최신 Python 3.12, Windows sandbox, Claude SDK가 통과했다. 이전 Windows failure는 run `46311664418`의 sandbox probe timeout이다. PR #3130은 Draft이며 fresh Python 3.12·Windows가 pending이고 나머지 listed checks는 통과했다.
- 확인된 사실: fuzz artifacts만 production `main` 위에 올린 `feat/ouroboros-fuzz-lab-r3-20261130`을 commit `9141668d`로 push했고 Draft PR #3133을 만들었다. README와 production source deletion, generated pyc는 publish commit에 없다.
- 확인된 사실: Draft PR #3133의 첫 Issue link check는 no-issue exemption label 부재로 실패했다. 저장소의 `no-issue` label을 적용해 check 재실행을 시작했다.
- 다음 행동: local gate와 Draft PR #3133 check 상태를 최종 확인한다.
19 changes: 19 additions & 0 deletions STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Ouroboros CI & Fuzz Lab

## 🗺️ 단계 / 로드맵
- [x] 1단계: 저장소·실행 경로·라이브 PR 체크 확인
- [x] 2단계: CloudDriver/VM runtime 범위의 snapshot과 adversarial fuzz audit 수행
- [x] 3단계: CI failure 원인과 actionable Task 2 피드백 정리
- [x] 4단계: 산출물·결정론적 게이트 검증
- [x] 5단계: Round 1 보안·경계 수정 및 독립 재검증
- [x] 6단계: Round 2 empirical concurrency, memory growth, output pressure, and export-race audit
- [x] 7단계: Round 3 crash/disconnect/restart idempotency and import-race audit
- [x] 8단계: 안전한 원격 반영 및 Draft PR 보관

## 🛑 블로커
- 블로커: 없음

## 🤖 AI 실행 맥락
- 마지막 커밋: `9141668d` Draft PR #3133 fuzz lab artifact branch
- 지금 손댄 파일: `snapshot/ouroboros/cloud/`, `snapshot/cloud-v1/`, `fuzz_tests/test_cloud_runtime_adversarial.py`, `CI_AND_FUZZ_REPORT.md`, `docs/verification/`, `STATE.md`, `STATUS.md`
- 다음 할 일: local gate와 Draft PR #3133 check 상태를 최종 확인한다.
Loading