Skip to content

fix(openapi): return fresh cached specs - #6550

Open
xianjianlf2 wants to merge 2 commits into
Effect-TS:mainfrom
xianjianlf2:fix/openapi-from-api-copy-6330
Open

fix(openapi): return fresh cached specs#6550
xianjianlf2 wants to merge 2 commits into
Effect-TS:mainfrom
xianjianlf2:fix/openapi-from-api-copy-6330

Conversation

@xianjianlf2

@xianjianlf2 xianjianlf2 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #6330

Summary

  • keep the internal OpenApi.fromApi cache but return fresh deep copies to callers
  • preserve special OpenAPI keys like proto as own enumerable properties while cloning
  • add regression coverage for external mutation not affecting later cached calls

Tests

  • pnpm test packages/effect/test/unstable/httpapi/OpenApi.test.ts
  • pnpm lint-fix
  • pnpm check

Summary by CodeRabbit

  • Bug Fixes
    • OpenAPI specifications are now returned as fresh copies, preventing changes made to one result from affecting later results.
    • Cached OpenAPI data no longer leaks mutations across requests or calls.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 23, 2026
@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7a0d740

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@xianjianlf2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d9150b35-3d91-4c2c-b491-81f3c58b3623

📥 Commits

Reviewing files that changed from the base of the PR and between 2fd3fee and 7a0d740.

📒 Files selected for processing (1)
  • packages/effect/test/unstable/httpapi/OpenApi.test.ts
📝 Walkthrough

Walkthrough

OpenApi.fromApiWith now deep-clones cached and newly generated OpenAPI specifications. Tests verify that mutations to one returned specification do not affect subsequent calls, and a patch changeset documents the behavior.

Changes

OpenAPI cache isolation

Layer / File(s) Summary
Clone returned OpenAPI specifications
packages/effect/src/unstable/httpapi/OpenApi.ts
Adds recursive cloning for OpenAPI objects and returns clones for both cached and newly generated specifications.
Validate fresh specification instances
packages/effect/test/unstable/httpapi/OpenApi.test.ts, .changeset/fix-openapi-from-api-cache-copy.md
Tests isolation of nested specification mutations and documents the patch-level behavior change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: gcanti, imax153

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The patch directly fixes the shared mutable OpenAPISpec cache by cloning on every return, matching the linked issue's goal.
Out of Scope Changes check ✅ Passed The changes stay focused on OpenApi cache isolation, regression tests, and the related changeset; no unrelated code paths were added.

Comment @coderabbitai help to get the list of available commands.

@tim-smart tim-smart added the bug Something isn't working label Jul 23, 2026 — with ChatGPT Codex Connector
@xianjianlf2
xianjianlf2 force-pushed the fix/openapi-from-api-copy-6330 branch from c33e7f3 to 2fd3fee Compare July 27, 2026 03:38

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/effect/test/unstable/httpapi/OpenApi.test.ts`:
- Around line 73-91: The regression test should mutate a cache-hit result rather
than only the initially generated result. In the “returns fresh spec instances
when using the cache” test, obtain `second` via `OpenApi.fromApi(Api)`, mutate
its `info.title` and resource GET summary, then call `OpenApi.fromApi(Api)`
again and assert the third result retains the original title and has no summary,
while preserving the existing instance-isolation assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 70c904a4-09b4-41cd-82ef-314083381c13

📥 Commits

Reviewing files that changed from the base of the PR and between cc27b19 and 2fd3fee.

📒 Files selected for processing (3)
  • .changeset/fix-openapi-from-api-cache-copy.md
  • packages/effect/src/unstable/httpapi/OpenApi.ts
  • packages/effect/test/unstable/httpapi/OpenApi.test.ts

Comment thread packages/effect/test/unstable/httpapi/OpenApi.test.ts
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

OpenApi.fromApi exposes shared mutable state

2 participants