Skip to content

Preserve reactive query metadata - #6711

Merged
tim-smart merged 2 commits into
Effect-TS:mainfrom
andrskr:trust-me/preserve-atom-query-metadata
Jul 28, 2026
Merged

Preserve reactive query metadata#6711
tim-smart merged 2 commits into
Effect-TS:mainfrom
andrskr:trust-me/preserve-atom-query-metadata

Conversation

@andrskr

@andrskr andrskr commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • compose AtomRpc and AtomHttpApi query reactivity before serialization and retention metadata
  • preserve serializationKey, finite timeToLive, and keepAlive behavior on the query atom returned to callers
  • extend both query regressions to cover reactivity, retention, serialization, and dehydration together

Root cause

Both query constructors attached serialization and retention metadata to the base atom and then returned a new atom from withReactivity. withReactivity is implemented as a transform, so the returned atom intentionally starts with fresh metadata. Enabling reactivityKeys therefore changed an explicitly serializable query with a one-minute TTL into a non-serializable atom with idleTTL set to 0.

The query constructors own the complete composition pipeline, so this change applies the behavioral transform first and then attaches serialization and retention to the final public atom. It does not change the generic semantics of Atom.transform, withReactivity, hydration, or the registry.

Red-before / green-after proof

With the regression changes applied to unmodified main, both focused tests failed with the same result:

actual:   { idleTTL: 0, serializable: false }
expected: { idleTTL: 60000, serializable: true }

After reordering the query composition, both tests pass and continue to verify request execution and dehydration.

Validation

  • pnpm lint-fix
  • pnpm --filter effect test --run test/reactivity/AtomRpc.test.ts test/reactivity/AtomHttpApi.test.ts
  • pnpm check
  • pnpm lint
  • pnpm --filter effect build

Summary by CodeRabbit

  • Bug Fixes
    • Reactive query atoms now preserve reactivity settings consistently, alongside serialization and retention/TTL behavior.
    • Reconstructed queries retain the same serialization and time-to-live configuration.
  • Tests
    • Strengthened assertions for reactive queries to verify serializability and TTL behavior for both “1 minute” (idleTTL) and “Infinity” (keepAlive), including reconstruction parity.
  • Chores
    • Published a patch-level update for the corrected reactive query metadata handling.

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

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d8960f2

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

This PR includes changesets to release 29 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno 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

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Jul 28, 2026
@andrskr
andrskr marked this pull request as ready for review July 28, 2026 18:36
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 30330a4f-908f-477e-866b-b025950f3346

📥 Commits

Reviewing files that changed from the base of the PR and between 73dfa60 and d8960f2.

📒 Files selected for processing (2)
  • packages/effect/test/reactivity/AtomHttpApi.test.ts
  • packages/effect/test/reactivity/AtomRpc.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/effect/test/reactivity/AtomHttpApi.test.ts
  • packages/effect/test/reactivity/AtomRpc.test.ts

📝 Walkthrough

Walkthrough

Reactive query factories in AtomRpc and AtomHttpApi now apply reactivity before serialization and retention wrappers. Tests verify serializability, TTL and keep-alive retention, and rehydrated query configuration. A patch changeset documents the fix.

Changes

Reactive query metadata

Layer / File(s) Summary
Apply reactivity before metadata wrappers
packages/effect/src/unstable/reactivity/AtomRpc.ts, packages/effect/src/unstable/reactivity/AtomHttpApi.ts
Query atoms apply reactivityKeys immediately after creation, then apply serialization and TTL transformations before returning the atom.
Verify serialized and retained queries
packages/effect/test/reactivity/AtomRpc.test.ts, packages/effect/test/reactivity/AtomHttpApi.test.ts, .changeset/fix-reactive-query-metadata.md
Tests verify serializability, a 60_000 ms idle TTL, keep-alive retention, and matching reactivity configuration during encoded query reconstruction; a patch changeset records the update.

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

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

@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.

🧹 Nitpick comments (1)
packages/effect/test/reactivity/AtomRpc.test.ts (1)

41-55: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Cover the non-finite TTL/keep-alive path in both regression tests.

Both tests currently cover only finite TTL. Add a case that verifies Atom.keepAlive preserves serialization after reactivity wrapping.

  • packages/effect/test/reactivity/AtomRpc.test.ts#L41-L55: add non-finite TTL coverage for RPC queries.
  • packages/effect/test/reactivity/AtomHttpApi.test.ts#L51-L65: add equivalent coverage for HTTP queries.
🤖 Prompt for 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.

In `@packages/effect/test/reactivity/AtomRpc.test.ts` around lines 41 - 55, The
RPC regression test around Atom.keepAlive in
packages/effect/test/reactivity/AtomRpc.test.ts lines 41-55 must also cover a
non-finite TTL and verify serialization remains true after reactivity wrapping.
Add the equivalent non-finite TTL/keep-alive case to
packages/effect/test/reactivity/AtomHttpApi.test.ts lines 51-65; preserve the
existing finite-TTL assertions in both tests.
🤖 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.

Nitpick comments:
In `@packages/effect/test/reactivity/AtomRpc.test.ts`:
- Around line 41-55: The RPC regression test around Atom.keepAlive in
packages/effect/test/reactivity/AtomRpc.test.ts lines 41-55 must also cover a
non-finite TTL and verify serialization remains true after reactivity wrapping.
Add the equivalent non-finite TTL/keep-alive case to
packages/effect/test/reactivity/AtomHttpApi.test.ts lines 51-65; preserve the
existing finite-TTL assertions in both tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 83005aba-e719-4657-8f51-57439e8873fe

📥 Commits

Reviewing files that changed from the base of the PR and between 9867b9f and 73dfa60.

📒 Files selected for processing (5)
  • .changeset/fix-reactive-query-metadata.md
  • packages/effect/src/unstable/reactivity/AtomHttpApi.ts
  • packages/effect/src/unstable/reactivity/AtomRpc.ts
  • packages/effect/test/reactivity/AtomHttpApi.test.ts
  • packages/effect/test/reactivity/AtomRpc.test.ts

@andrskr
andrskr marked this pull request as draft July 28, 2026 18:46
@andrskr
andrskr marked this pull request as ready for review July 28, 2026 18:59

andrskr commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the keep-alive coverage suggestion in d8960f2. Both AtomRpc and AtomHttpApi regression tests now exercise timeToLive: "Infinity" with reactivity enabled and verify that the returned query remains keepAlive and serializable.

Validation:

  • pnpm --filter effect test --run test/reactivity/AtomRpc.test.ts test/reactivity/AtomHttpApi.test.ts
  • pnpm lint-fix
  • pnpm check
  • pnpm lint
  • pnpm --filter effect build

@tim-smart
tim-smart enabled auto-merge (squash) July 28, 2026 20:43
@tim-smart
tim-smart merged commit 733f75b into Effect-TS:main Jul 28, 2026
14 of 15 checks passed
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants