--- id: review-001-ref-cycle-guard name: Bounded, cycle-safe $ref resolution (OAI-01, OAI-08) status: pending depends_on: [] scope: narrow risk: high impact: component level: implementation tags: [adapters, review-001, from-openapi] --- ## Description Review 001 finding OAI-01 — the single highest-severity finding in the review (borderline critical, empirically verified): `resolve_refs_recursive` (`src/adapters/openapi_spec.rs:199-221`) recurses with no cycle detection and no depth budget. A self-referential component (`{"$ref":"#/components/schemas/Node"}` inside Node — trees, linked lists, cursor pagination: common and *valid* OpenAPI) recurses until the stack is exhausted: `thread has overflowed its stack; fatal runtime error` → **process abort**. Not a catchable panic; `import()` kills the whole process — startup crash-loop, or remote DoS if specs are ever runtime-refreshed/peer-supplied. Fix: depth budget + visited set keyed on the JSON-pointer path, returning a clean `CallError`/import error on cycles and over-deep specs. **Do not** try to preserve full recursive expansion of recursive schemas — the goal is a clean, loud error (or a depth-limited expansion where the adapter can safely represent it), not unbounded expansion. Ride-along: **OAI-08** — guarded `expect`s in `openapi_spec.rs:144,170` (the "no `expect` outside tests" convention; `if let` costs nothing). ## Acceptance Criteria - [ ] Import of a self-referential spec returns an error — the process does not abort (the review's named acceptance gate: a test importing a self-referential spec would have caught the abort immediately) - [ ] Deeply-nested non-circular spec beyond the budget errors cleanly at import (test) - [ ] A non-recursive spec with `$ref` sharing (refs to a common schema) still imports identically — no false cycle positives (existing suite green) - [ ] OAI-08 `expect`s replaced - [ ] `cargo test` and `cargo clippy --all-targets -- -D warnings` pass ## References - docs/reviews/001-initial-implementation-review.md (Part E, OAI-01, OAI-08) ## Notes > Agent fills during implementation. Do before anything > deployment-facing. Deliberately split from the parameter/requestBody > work (review-001-openapi-import-integrity) so the delicate > cycle-detection change lands alone. ## Summary > Filled on completion.