Files
alkhttp/tasks/adapters/review-002-oai11-ref-memoization.md
T
glm-5.3-flash e2c255d40c docs(tasks): decompose review-002 into 24 tasks (23 implementation + 1 bracketed follow-up)
Decomposition of docs/reviews/002-post-remediation-review.md per its
5-unit remediation plan:

- Unit 1 (security-critical): gw15-publish-body-cap,
  prj16-schema-via-call (CF-004 filed alkcall-side), fwd13-dot-segments,
  fwd16-missing-capability, oai11-ref-memoization
- Unit 2 (timeout/terminality): ws13-idle-progress,
  fwd15-stream-timeout, cli01-retry-after-budget, con17-mcp-pagination,
  con18-wss-sweep-exit
- Unit 3 (projection/docs): projection-truthfulness, mcp-batch-cap,
  gw16-status-drift
- Unit 4 (spec-import): yaml-normalization, oai13-path-item-wildcards,
  import-loudness-cluster, js01-placeholder-check,
  fwd17-19-contract-decisions
- Unit 5 (WS polish + tests): con18b-ws-polish,
  client-policy-wire-tests, cov-deployment-knobs, cov13-dead-code,
  srv11-srv12-router-ordering
- review-002-bracketed-followup: tentatively planned post-bulk pass
  (stale-check, OQA-18 enforcement decision, CON-08/09 close() lever,
  cross-crate re-checks) — deliberately not serialized against the
  bulk

Also: review-002 numbering repair (CON-14 was double-booked; MCP
pagination now CON-14, from_wss monitor renumbered CON-18, missing
CON-14 section added).

taskgraph: 66 valid, no cycles; 24 pending (all review-002);
gen-1/gen-2 parallel waves identified; workflow-cost hotspots are
prj16 (12.8) and ws13 (11.1), both carrying the reviewed slicing
guidance in their Notes.
2026-08-30 10:50:34 +00:00

70 lines
3.0 KiB
Markdown

---
id: review-002-oai11-ref-memoization
name: Memoize $ref expansion to bound resolver work (OAI-11)
status: pending
depends_on: []
scope: moderate
risk: medium
impact: component
level: implementation
tags: [adapters, review-002, from-openapi, openapi-spec]
---
## Description
Review 002 OAI-11 [major, borderline critical]. The OAI-01 fix
(cycle guard + depth budget, `openapi_spec.rs:382-437`) bounds *stack*,
not *work*: every `$ref` hop re-expands its target from a fresh clone
with no memoization. A chain of shared but acyclic refs —
```
S_i = { a: { $ref: "S_{i+1}" }, b: { $ref: "S_{i+1}" } }
```
(the doubly-linked-list `prev`/`next` shape — valid, common) expands as
a full binary tree. Empirically (verbatim harness): 20 levels → 7.3M
node visits / 3.6 s; growth ≈ 2^levels → 30 levels ≈ ~1 hour, 40 ≈ days.
Neither guard fires (`err=false`); the import just wedges — no stack
overflow, no error. The same "valid document kills the process" class
as OAI-01, one mitigation shy.
## Acceptance Criteria
- [ ] `resolve_refs_bounded` memoizes resolved, cycle-free `$ref`
targets per document (cache keyed on the ref string; clone the
resolved `Value` on hit instead of re-resolving) — or an
equivalent total-node-count budget with a clean
`SchemaParse`-family error (implementer's choice; memoization
strongly preferred — it preserves full acyclic support)
- [ ] The cycle guard and both depth checks remain (memoization must
not alter cycle detection semantics — a cycle still errors)
- [ ] Acceptance gate: a 30+ level shared-chain spec imports in
bounded time (add the test with a wall-clock or node-count
assert; a 30-level chain must import in < 1 s)
- [ ] Tests: diamond (non-cyclic shared refs) unchanged-correct;
cycle-through-shared-node still errors; memoized result equals
the old expansion for a shared-ref schema (golden compare on one
case)
- [ ] The four missing cycle-shape tests from OAI-16 (array-items,
allOf, additionalProperties, `$ref`-sibling) land here too —
same function, same risk envelope
- [ ] `cargo test`, `cargo clippy --all-targets -- -D warnings`,
`cargo fmt --check` pass
## References
- docs/reviews/002-post-remediation-review.md (Part E', OAI-11 + OAI-16)
- src/adapters/openapi_spec.rs:382-437 (the resolver), :713-805 (existing cycle tests), from_openapi.rs:736 (the requestBody-chain test)
- tasks/adapters/review-001-ref-cycle-guard.md (the OAI-01 fix this completes)
- docs/architecture/decisions/066-from-jsonschema-as-http-adapter.md
## Notes
Clone cost per hit is fine (schemas are small; the win is avoiding
exponential re-resolution, not allocation). If memoizing, note the
`resolving`-set interaction: a memo entry must only be written for
*completed* (cycle-free) expansions — a partial expansion under an
active cycle attempt must never be cached (write-on-success at the
top of the recursion return path, or post-order). This is the one
subtle part; the existing cycle tests + the four new shape tests are
the safety net.