Skip to content

Milestone: Configurable TTL Cascade - #283

Merged
yedidyakfir merged 45 commits into
developfrom
cascade-ttl-full-review
Jul 20, 2026
Merged

Milestone: Configurable TTL Cascade#283
yedidyakfir merged 45 commits into
developfrom
cascade-ttl-full-review

Conversation

@yedidyakfir

@yedidyakfir yedidyakfir commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

The complete Configurable TTL Cascade milestone, re-applied on top of the reverted develop (after #279) with every review comment from #277 addressed — plus the full evolution since. This is the PR to review the whole diff in and merge cascade back into develop.

Summary

Milestone: Configurable TTL Cascade — the first slice of a configurable cascade framework for rapyer. Setting a parent aggregate's TTL performs a cascading refresh across its cascade-enabled ForeignKey-referenced children — each child re-armed to its own Meta.ttl — applied atomically and server-side at set-time. Cascade is opt-in and disabled-by-default, so existing projects are byte-for-byte unaffected.

Status: All 4 phases complete and verified; full CI matrix green.

Phases (all complete)

  • Phase 1 — Cascade Config + Cycle-Safe Traversal Backbone: declare/detect CascadeTTL; FK-graph field classification feeding the cascade plan; CascadeSpec EXT-01 seam for future delete/save cascade.
  • Phase 2 — Atomic TTL Apply: the flagship server-side unit. Traverses the cascade-enabled FK graph and re-arms each reached key to its owning class's Meta.ttl in a single atomic op, with a per-class plan baked in.
  • Phase 3 — Action-Boundary Wiring + Backward-Compat: cascade rides the triggering write's transaction; the no-config path stays byte-identical.
  • Phase 4 — Integration Tests + Docs + Backbone Stubs: cross-model cascade proven on real Redis across graph shapes and the version matrix; API + extension seams documented.

Evolution since the initial milestone (quick-task refinements)

  • EVALSHA Lua → Redis Functions library. The atomic apply logic moved from an EVALSHA script to a FUNCTION LOAD/FCALL library (library.lua): the plan is baked into the library and decoded once (memoized upvalue; cjson is unavailable at load scope), so per-call cost is ~0. Library + function names carry a plan-hash for server-global isolation.
  • Real-Redis-7+ only for cascade traversal. fakeredis has no FUNCTION support, so it falls back to a root-own all_keys EXPIRE loop — preserving Meta.ttl / refresh_ttl behavior. Cascade traversal tests are gated to real Redis 7+.
  • Stateless scripts layer. Removed the module-global cascade-function name; the plan-hashed name lives on RedisConfig.cascade_function_name (init-baked, freeze-exempt).
  • Dead-code cleanup: removed unused extract_annotation and the test-only arun_fcall wrapper.
  • Cascade-function self-heal deferred to a dedicated ticket (Extend NOSCRIPT self-heal to the TTL-refresh pipeline paths (ensure_pipeline / pipeline_with_execution) #284). A production self-heal (reload a missing cascade Function + retry) was prototyped but rolled back to keep this milestone scoped — production returns to propagating the FCALL error if the Function is missing. The NOSCRIPT/EVALSHA self-heal is unrelated and remains.

Verification

  • Full suite: 2412 passed, 205 skipped, 0 failures. Unit (fakeredis): 800 passed. Cascade integration on real Redis Stack 7.4.7 (:6370): 40 passed.
  • black --check + ruff check clean; mypy (3.10–3.13) green.
  • CI matrix green across Python 3.10–3.13 × Redis 6.2–7.2 × pydantic 2.11–2.13, plus coverage, security scans, and benchmarks.

Note on the CodSpeed check

The only red check is CodSpeed Performance Analysis. develop currently has no cascade at all (reverted in #279), so any cascade feature registers as a "regression" against a cascade-free baseline — this is the feature's inherent cost, not a defect. Against the last cascade-bearing benchmark baseline, the Functions rewrite is 11–46% faster with 0 regressions.

Housekeeping

Supersedes #278 (which showed only the fixes because its branch shared the milestone commit as a merge-base with develop). #278 can be closed.

🤖 Generated with Claude Code

YedidyaHKfir and others added 8 commits July 13, 2026 13:27
…ble TTL cascade across ForeignKey graphs (milestone, phases 1-4)"

This reverts commit 48e4adc.
…): CR-01 replay EVALSHA-only on NOSCRIPT, converge recovery paths

execute_pipeline_with_noscript_recovery replayed the FULL command stack on
NOSCRIPT. In a transactional MULTI/EXEC a NOSCRIPT surfaces at EXEC time after
the non-EVALSHA commands already committed (Redis does not roll back a
transaction on a mid-execution command error), so a full replay double-applies
non-idempotent native ops (JSON.NUMINCRBY, JSON.ARRAPPEND, SF ops). This
affected every write routed through ensure_pipeline/pipeline_with_execution,
not just cascade, and only on a script-cache flush/failover.

- context.py: replay only the EVALSHA entries (matching the already-correct
  _apipeline pattern); add an ignore_redis_error param so the two write paths
  share one recovery implementation (WR-03, IN-01).
- base.py: _apipeline now delegates to the shared helper; drop the duplicated
  backup/replay block. Also document the non-positive-ttl root-delete asymmetry
  in aset_ttl(cascade=True) (IN-04) and restore valid indentation on
  contains_sf_field (stray uncommitted corruption).
- test_context.py: rewrite the full-stack-replay test to assert EVALSHA-only
  replay (it had locked in the buggy behavior).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…): make Meta.ttl/cascade_ttl freeze lifecycle robust

- init.py (WR-01): wrap the unfreeze -> configure -> bake -> refreeze sequence
  in try/finally so a failed init (e.g. validate_cascade_ttl_targets on a
  mis-configured graph) still refreezes every model instead of leaving them
  unfrozen with silently-mutable, half-baked Meta.ttl/cascade_ttl.
- init.py (WR-02): teardown_rapyer now clears _ttl_frozen so a torn-down model
  doesn't leak MetaTtlFrozenError into a later init-less path.
- config.py (WR-04): freeze cascade_ttl too, not just ttl — both are baked into
  the per-class Lua plan / _has_cascade gate, so mutating cascade_ttl post-freeze
  would silently desync the runtime cascade from the baked plan.
- cascade/conftest.py: autouse fixture resets _ttl_frozen around each cascade
  test so the process-global freeze can't make tests order-dependent (WR-02).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…): harden lua-literal escaping and correct dead-branch comment

- registry.py (IN-03): _lua_literal now also escapes newlines/CR so a stray
  control char in an injected literal yields valid Lua at SCRIPT LOAD instead
  of a silently broken script body.
- apply.lua (IN-02): correct the recurse=false comment — the branch is a
  not-yet-exercised seam (every emitted edge has recurse=true), and a
  non-recursing target can still be reached via its override edges since
  next_hop ignores budget for overrides.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…): freeze the whole Meta config after init, not just ttl

Per review: the freeze should cover all config, not only ttl. Rename the
_ttl_frozen flag to _frozen, block every public Meta field in __setattr__ once
frozen (private attrs stay writable so init/teardown can toggle it), and rename
MetaTtlFrozenError -> MetaFrozenError. A global autouse test fixture unfreezes
models around each test so the process-global freeze can't leak across tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…): refresh_ttl always uses the cascade script

Per review: drop the _has_cascade branch in refresh_ttl and always run the
cascade EVALSHA. With no outgoing edges it simply re-arms the model's own keys,
so every TTL refresh goes through one path. Tests updated to assert the script
call instead of the per-key EXPIRE loop.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…scade): planner dataclasses, contains_sf_field, shorter docstrings

Per review, in rapyer/cascade/planner.py:
- _classify_edge returns an EdgeClassification dataclass instead of a tuple.
- _static_walk_special_suffixes uses contains_sf_field() instead of a manual
  hasattr(_special_field_names) check.
- multi-line docstrings start on their own line and are trimmed to short
  summaries; drop -> None return annotations.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…de): remove internal workflow notation from comments

Per review: drop the internal review/plan tags (D-0x, WR-0x, IN-0x, etc.) and
RESEARCH.md/Pitfall references from comments and docstrings across the cascade
code and tests; keep the actual explanations. Also reword multi-line docstrings
to start on their own line. Renamed a few tests that embedded those tags.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

TTL cascade support is added across configuration, cascade planning, atomic Lua execution, model TTL APIs, pipeline recovery, public exports, documentation, and unit/integration tests. Cascade traversal supports depth limits, special fields, dangling counts, cycles, shared nodes, and per-child TTLs.

Changes

TTL Cascade

Layer / File(s) Summary
Cascade contracts and planning
rapyer/cascade/*, rapyer/errors/*, rapyer/utils/annotation.py, rapyer/result.py
Adds CascadeTTL, cascade modes, immutable plan structures, annotation extraction, TTL validation, cascade errors, and CascadeResult.
Configuration and initialization
rapyer/config.py, rapyer/init.py, rapyer/__init__.py
Adds global cascade configuration, metadata freezing, initialization validation, model cascade flags, teardown reset, and public exports.
Cascade Lua planning and registration
rapyer/scripts/lua/cascade/apply.lua, rapyer/scripts/registry.py, rapyer/scripts/constants.py
Adds graph traversal, depth budgeting, special-key refresh, dangling counts, Lua plan injection, and script registration.
TTL refresh and pipeline integration
rapyer/base.py, rapyer/context.py
Routes automatic and explicit TTL refreshes through the cascade script and centralizes NOSCRIPT pipeline recovery.
Behavioral validation
tests/models/cascade_types.py, tests/unit/cascade/*, tests/integration/foreign_keys/*, tests/unit/test_context.py
Covers configuration, planning, Lua traversal, graph shapes, TTL behavior, concurrency, script flushing, and pipeline recovery.
Documentation and navigation
docs/documentation/special-fields/*, mkdocs.yml
Documents TTL cascade configuration, behavior, limitations, extension points, and site navigation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Model
  participant CascadeScript
  participant Redis
  Model->>CascadeScript: Refresh root TTL with cascade
  CascadeScript->>Redis: Read JSON foreign-key references
  CascadeScript->>Redis: EXPIRE root, child, and special-field keys
  Redis-->>Model: Return dangling child and special counts
Loading

Possibly related PRs

Suggested reviewers: yedidyahkfir

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.51% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding configurable TTL cascade support.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cascade-ttl-full-review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

Coverage report

Total coverage: 99%

Full report
Name                                                     Stmts   Miss  Cover
----------------------------------------------------------------------------
rapyer/__init__.py                                           5      0   100%
rapyer/actions.py                                          213      0   100%
rapyer/base.py                                             866      2    99%
rapyer/cascade/__init__.py                                   3      0   100%
rapyer/cascade/planner.py                                  144      5    97%
rapyer/cascade/spec.py                                      13      0   100%
rapyer/cascade/ttl.py                                        5      0   100%
rapyer/config.py                                            45      0   100%
rapyer/context.py                                           40      0   100%
rapyer/errors/__init__.py                                   11      0   100%
rapyer/errors/base.py                                       23      0   100%
rapyer/errors/cascade.py                                     8      0   100%
rapyer/errors/delete.py                                      3      0   100%
rapyer/errors/find.py                                       15      0   100%
rapyer/fields/__init__.py                                    4      0   100%
rapyer/fields/expression.py                                108      0   100%
rapyer/fields/index.py                                      20      0   100%
rapyer/fields/key.py                                        19      0   100%
rapyer/fields/safe_load.py                                  14      0   100%
rapyer/init.py                                              66      0   100%
rapyer/links.py                                              2      0   100%
rapyer/result.py                                            31      0   100%
rapyer/scripts/__init__.py                                   5      0   100%
rapyer/scripts/constants.py                                 17      0   100%
rapyer/scripts/loader.py                                    38      0   100%
rapyer/scripts/lua/__init__.py                               0      0   100%
rapyer/scripts/lua/atomic/__init__.py                        0      0   100%
rapyer/scripts/lua/cascade/__init__.py                       0      0   100%
rapyer/scripts/lua/datetime/__init__.py                      0      0   100%
rapyer/scripts/lua/dict/__init__.py                          0      0   100%
rapyer/scripts/lua/list/__init__.py                          0      0   100%
rapyer/scripts/lua/numeric/__init__.py                       0      0   100%
rapyer/scripts/lua/sf/__init__.py                            0      0   100%
rapyer/scripts/lua/sf/redis_priority_queue/__init__.py       0      0   100%
rapyer/scripts/lua/sf/redis_set/__init__.py                  0      0   100%
rapyer/scripts/lua/string/__init__.py                        0      0   100%
rapyer/scripts/registry.py                                  63      0   100%
rapyer/types/__init__.py                                    13      0   100%
rapyer/types/base.py                                       103      0   100%
rapyer/types/byte.py                                        33      0   100%
rapyer/types/convert.py                                     53      0   100%
rapyer/types/datetime.py                                    77      0   100%
rapyer/types/dct.py                                        116      0   100%
rapyer/types/float.py                                       65      0   100%
rapyer/types/foreign_key.py                                 68      0   100%
rapyer/types/generic.py                                     83      0   100%
rapyer/types/init.py                                        10      0   100%
rapyer/types/integer.py                                     58      0   100%
rapyer/types/lst.py                                        129      0   100%
rapyer/types/priority_queue.py                             102      0   100%
rapyer/types/redis_set.py                                  196      0   100%
rapyer/types/relational.py                                  24      0   100%
rapyer/types/special.py                                     39      0   100%
rapyer/types/string.py                                      22      0   100%
rapyer/typing_support.py                                     3      0   100%
rapyer/utils/__init__.py                                     0      0   100%
rapyer/utils/annotation.py                                  62      1    98%
rapyer/utils/fields.py                                      43      0   100%
rapyer/utils/pythonic.py                                    21      0   100%
rapyer/utils/redis.py                                       77      0   100%
----------------------------------------------------------------------------
TOTAL                                                     3178      8    99%

@codspeed-hq

codspeed-hq Bot commented Jul 13, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 11.26%

❌ 5 regressed benchmarks
✅ 163 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_benchmark_with_ttl 4.4 ms 5.1 ms -12.56%
WallTime test_benchmark_with_ttl 111.2 ms 125.7 ms -11.52%
WallTime test_benchmark_with_ttl 9.4 ms 10.6 ms -10.88%
WallTime test_benchmark_with_ttl 4.8 ms 5.4 ms -10.83%
WallTime test_benchmark_with_ttl 4.8 ms 5.4 ms -10.49%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cascade-ttl-full-review (35494d1) with develop (55d6841)

Open in CodSpeed

Comment thread rapyer/cascade/planner.py Outdated
Comment thread rapyer/cascade/planner.py Outdated
Comment thread rapyer/cascade/planner.py Outdated
Comment thread rapyer/cascade/planner.py Outdated
Comment thread rapyer/cascade/planner.py Outdated
Comment thread rapyer/base.py Outdated
Comment thread rapyer/config.py Outdated
Comment thread rapyer/context.py Outdated
Comment thread rapyer/init.py
Comment thread tests/integration/foreign_keys/test_cascade_concurrent_mutation.py Outdated
…on cascade script

- cascade unit fixtures re-establish class-declared Meta.cascade_ttl (a prior
  init_rapyer() authoritatively resets it to None); restore on teardown
- two integration tests save before clearing/flushing scripts, so the expected
  error fires inside pytest.raises rather than during asave() Arrange (asave now
  always runs the cascade Lua script via refresh_ttl)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@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: 2

🧹 Nitpick comments (5)
tests/unit/test_context.py (1)

1-104: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing coverage for the ResponseError swallow/re-raise branch.

execute_pipeline_with_noscript_recovery also swallows non-NOSCRIPT ResponseError when ignore_redis_error=True and re-raises otherwise (per its docstring in rapyer/context.py), but no test here exercises either sub-path.

♻️ Suggested additional tests
`@pytest.mark.asyncio`
async def test_execute_pipeline_with_noscript_recovery_swallows_response_error_when_ignored():
    pipe = _make_pipe(
        command_stack=[(("JSON.SET", "k", "$", "{}"), {})],
        execute_side_effect=ResponseError("boom"),
    )
    result = await execute_pipeline_with_noscript_recovery(
        pipe, MagicMock(), ignore_redis_error=True
    )
    assert result == []


`@pytest.mark.asyncio`
async def test_execute_pipeline_with_noscript_recovery_reraises_response_error_by_default():
    pipe = _make_pipe(
        command_stack=[(("JSON.SET", "k", "$", "{}"), {})],
        execute_side_effect=ResponseError("boom"),
    )
    with pytest.raises(ResponseError):
        await execute_pipeline_with_noscript_recovery(pipe, MagicMock())

As per path instructions, "Focus on test coverage completeness and edge cases" for tests/**.

🤖 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 `@tests/unit/test_context.py` around lines 1 - 104, Add coverage for the
ResponseError handling in execute_pipeline_with_noscript_recovery: import
ResponseError and add async tests verifying a non-NOSCRIPT error returns an
empty list when ignore_redis_error=True and is re-raised with the default
setting. Use _make_pipe with a JSON.SET command and ResponseError side effect,
while preserving existing tests.

Source: Path instructions

rapyer/utils/annotation.py (1)

116-123: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider reusing extract_annotation to simplify has_annotation.

To adhere to the DRY principle, you can update has_annotation (lines 104-113) to simply check if extract_annotation returns a non-None value.

♻️ Proposed refactor for `has_annotation`
def has_annotation(field: Any, annotation_type: Any) -> bool:
    return extract_annotation(field, annotation_type) is not None
🤖 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 `@rapyer/utils/annotation.py` around lines 116 - 123, Update has_annotation to
delegate to extract_annotation and return whether the result is non-None. Remove
its duplicated annotation-origin and metadata traversal while preserving the
existing boolean behavior.
rapyer/config.py (1)

80-80: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Use getattr to safely access _frozen during object initialization or deserialization.

While Pydantic usually populates __pydantic_private__ (where PrivateAttrs are stored) directly during __init__ without triggering __setattr__, certain object lifecycle states (such as unpickling or deep-copying) might invoke __setattr__ before the private attributes dictionary is fully initialized, which would cause an AttributeError.

Consider using getattr to ensure robust attribute access.

💡 Proposed fix
-        if self._frozen and not name.startswith("_"):
+        if getattr(self, "_frozen", False) and not name.startswith("_"):
🤖 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 `@rapyer/config.py` at line 80, Update the __setattr__ logic in the
configuration model around the _frozen check to access _frozen safely with
getattr and a false default. Preserve the existing name.startswith("_")
condition and assignment behavior while preventing initialization,
deserialization, or deep-copy lifecycle states from raising AttributeError.
rapyer/scripts/lua/cascade/apply.lua (1)

244-275: 🚀 Performance & Scalability | 🔵 Trivial

Operational note: unbounded cascades run as one long, blocking Lua script.

The full read-walk (all JSON.GETs) plus the EXPIRE write phase execute inside a single atomic EVALSHA, which blocks Redis's single-threaded command loop for its entire duration. With an unbounded CascadeTTL (no depth) or a deep override chain, a large/wide reachable subtree turns one aset_ttl/refresh_ttl call into a long-running script that stalls every other client on that Redis instance. This is an inherent tradeoff of the atomic-Lua design, not a defect — worth documenting as guidance to bound CascadeTTL(depth=...) on graphs that could grow large, and to monitor Lua execution time in production.

Also applies to: 287-299

🤖 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 `@rapyer/scripts/lua/cascade/apply.lua` around lines 244 - 275, Document
guidance near plan_refresh_keys and the related refresh flow that unbounded or
deeply overridden cascades execute all JSON reads and expiration writes in one
blocking atomic Lua script. Recommend bounded CascadeTTL(depth=...) for
potentially large or wide graphs and monitoring Lua execution time in
production; do not alter the traversal or atomic execution behavior.
rapyer/context.py (1)

48-99: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

NOSCRIPT recovery path silently drops non-EVALSHA results; also relies on an internal Pipeline attribute.

Two related concerns on this helper:

  1. commands_backup = list(pipe.command_stack) (line 69) reads redis-py's internal Pipeline.command_stack — not documented public API. It has changed shape/behavior across redis-py releases for other pipeline variants (e.g. redis/redis-py#3703 for ClusterPipeline), so a future redis-py upgrade could silently break this without a semver signal.
  2. On recovery, the function replays and returns only the EVALSHA entries (lines 85-92), dropping any other commands originally queued in the same pipe from the returned list. This contradicts the docstring's claim that the success path "returns pipe.execute()'s result unchanged" — the recovery path returns a different, filtered list. Today every caller that queues EVALSHA-plus-other-commands in one pipe (ensure_pipeline's/pipeline_with_execution's exits, _apipeline) discards the return value, and the one caller that inspects it (aset_ttl in base.py) only ever uses a dedicated single-EVALSHA pipe — so this isn't live today, but it's a footgun for the next caller that mixes EVALSHA with other pipe commands and trusts positional results after a NOSCRIPT event.

Please confirm the target redis-py version continues to expose command_stack in this shape, and whether any call path (e.g. via mark_actions/refresh_ttl(can_use_pipeline=True)) nests the cascade EVALSHA into a pipe alongside other writes while consuming this function's return value.

🤖 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 `@rapyer/context.py` around lines 48 - 99, Update
execute_pipeline_with_noscript_recovery to avoid depending on redis-py’s
internal command_stack shape: verify the supported redis-py version and capture
queued command metadata through a stable, explicit mechanism. Audit callers such
as mark_actions, refresh_ttl, ensure_pipeline, pipeline_with_execution,
_apipeline, and aset_ttl, then make NOSCRIPT recovery preserve the original
command-result positions instead of returning only replayed EVALSHA results.
Keep dedicated EVALSHA callers’ behavior unchanged and document or enforce the
resulting recovery contract for mixed pipelines.
🤖 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 `@rapyer/cascade/planner.py`:
- Around line 178-184: Update the field-class resolution in the loop over
model_cls._contain_sf before calling safe_issubclass: unwrap Optional/Annotated
annotations using the existing strip_optional and get_origin logic, matching
_unwrap_nested_model_cls, then perform the AtomicRedisModel check on the
unwrapped nested model class.

In `@tests/integration/foreign_keys/test_cascade_ttl_apply.py`:
- Around line 22-25: Update the TTL assertion in the test using
SCRIPT_FLUSH_ROOT_TTL_SECONDS so it verifies the resulting parent TTL is bounded
by the explicit 120-second value, rather than merely being positive. Ensure the
test setup persists parent and child as needed before invoking the script flush,
while preserving the existing distinction from CASCADE_FIXTURE_TTL_SECONDS and
the current assertion flow.

---

Nitpick comments:
In `@rapyer/config.py`:
- Line 80: Update the __setattr__ logic in the configuration model around the
_frozen check to access _frozen safely with getattr and a false default.
Preserve the existing name.startswith("_") condition and assignment behavior
while preventing initialization, deserialization, or deep-copy lifecycle states
from raising AttributeError.

In `@rapyer/context.py`:
- Around line 48-99: Update execute_pipeline_with_noscript_recovery to avoid
depending on redis-py’s internal command_stack shape: verify the supported
redis-py version and capture queued command metadata through a stable, explicit
mechanism. Audit callers such as mark_actions, refresh_ttl, ensure_pipeline,
pipeline_with_execution, _apipeline, and aset_ttl, then make NOSCRIPT recovery
preserve the original command-result positions instead of returning only
replayed EVALSHA results. Keep dedicated EVALSHA callers’ behavior unchanged and
document or enforce the resulting recovery contract for mixed pipelines.

In `@rapyer/scripts/lua/cascade/apply.lua`:
- Around line 244-275: Document guidance near plan_refresh_keys and the related
refresh flow that unbounded or deeply overridden cascades execute all JSON reads
and expiration writes in one blocking atomic Lua script. Recommend bounded
CascadeTTL(depth=...) for potentially large or wide graphs and monitoring Lua
execution time in production; do not alter the traversal or atomic execution
behavior.

In `@rapyer/utils/annotation.py`:
- Around line 116-123: Update has_annotation to delegate to extract_annotation
and return whether the result is non-None. Remove its duplicated
annotation-origin and metadata traversal while preserving the existing boolean
behavior.

In `@tests/unit/test_context.py`:
- Around line 1-104: Add coverage for the ResponseError handling in
execute_pipeline_with_noscript_recovery: import ResponseError and add async
tests verifying a non-NOSCRIPT error returns an empty list when
ignore_redis_error=True and is re-raised with the default setting. Use
_make_pipe with a JSON.SET command and ResponseError side effect, while
preserving existing tests.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8b870c71-cf05-45da-9f3c-905ff49267ba

📥 Commits

Reviewing files that changed from the base of the PR and between 55d6841 and e10ad4e.

📒 Files selected for processing (47)
  • docs/documentation/special-fields/foreign-keys.md
  • docs/documentation/special-fields/ttl-cascade.md
  • mkdocs.yml
  • rapyer/__init__.py
  • rapyer/base.py
  • rapyer/cascade/__init__.py
  • rapyer/cascade/planner.py
  • rapyer/cascade/spec.py
  • rapyer/cascade/ttl.py
  • rapyer/config.py
  • rapyer/context.py
  • rapyer/errors/__init__.py
  • rapyer/errors/cascade.py
  • rapyer/init.py
  • rapyer/result.py
  • rapyer/scripts/constants.py
  • rapyer/scripts/lua/cascade/__init__.py
  • rapyer/scripts/lua/cascade/apply.lua
  • rapyer/scripts/registry.py
  • rapyer/utils/annotation.py
  • tests/conftest.py
  • tests/integration/foreign_keys/conftest.py
  • tests/integration/foreign_keys/test_cascade_action_boundary.py
  • tests/integration/foreign_keys/test_cascade_concurrent_mutation.py
  • tests/integration/foreign_keys/test_cascade_graph_shapes.py
  • tests/integration/foreign_keys/test_cascade_ttl_apply.py
  • tests/integration/lst/test_redis_list_remove_range.py
  • tests/integration/pipeline/test_pipeline_noscript_recovery.py
  • tests/models/cascade_types.py
  • tests/unit/cascade/__init__.py
  • tests/unit/cascade/conftest.py
  • tests/unit/cascade/test_aset_ttl_cascade_flag.py
  • tests/unit/cascade/test_cascade_action_boundary.py
  • tests/unit/cascade/test_cascade_apply_lua.py
  • tests/unit/cascade/test_cascade_apply_lua_syntax.py
  • tests/unit/cascade/test_cascade_classification.py
  • tests/unit/cascade/test_cascade_plan_injection.py
  • tests/unit/cascade/test_cascade_plan_table.py
  • tests/unit/cascade/test_cascade_ttl_config.py
  • tests/unit/cascade/test_cascade_ttl_required_validation.py
  • tests/unit/cascade/test_extract_annotation.py
  • tests/unit/cascade/test_init_rapyer_cascade_ttl.py
  • tests/unit/cascade/test_meta_ttl_freeze.py
  • tests/unit/cascade/test_refresh_ttl_cascade_branch.py
  • tests/unit/test_context.py
  • tests/unit/test_init_rapyer.py
  • tests/unit/test_refresh_ttl_if_needed.py

Comment thread rapyer/cascade/planner.py
Comment thread tests/integration/foreign_keys/test_cascade_ttl_apply.py Outdated
YedidyaHKfir and others added 3 commits July 14, 2026 16:33
…est comments (PR #283 review)

- Rename CascadeEdge fields (collection/recurse/ttl/special/override ->
  is_collection/recurse_into_target/refresh_target_ttl/
  refresh_target_special_keys/resets_depth_budget) across planner.py,
  apply.lua, and every test that inspects them; document the always-True
  flags as forward-looking per-edge hooks.
- Rename RedisConfig._frozen -> _meta_locked across config.py, init.py,
  and tests.
- Fix multi-line docstrings that started text on the opening `"""` line.
- Unwrap Optional/generic annotations before the subclass check in
  _static_walk_special_suffixes (CodeRabbit #14).
- Tighten the SCRIPT_FLUSH_ROOT_TTL_SECONDS assertion in
  test_cascade_ttl_apply.py to prove the explicit root ttl was applied,
  not just that some positive ttl survived (CodeRabbit #15).
- Reformat inline Arrange/Act/Assert comment markers onto their own
  header line across the new cascade tests (CodeRabbit #12/#13).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…cascade flag (PR #283 #8)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… TTL feature (PR #283 #10)

- context.py: remove execute_pipeline_with_noscript_recovery and its
  now-unused imports; ensure_pipeline/pipeline_with_execution revert to a
  bare pipe.execute() (develop's behavior).
- base.py: restore develop's self-contained inline NOSCRIPT recovery inside
  _apipeline (EVALSHA-only replay + PersistentNoScriptError on second
  failure); aset_ttl's standalone execute is now bare, matching the
  TTL-refresh paths' new (documented) lack of self-heal.
- Update/remove tests that asserted the now-removed generic recovery seam;
  test_pipeline_noscript_recovery.py's two script-flush tests now flush
  after the establishing asave() so only the explicit apipeline() block
  (backed by _apipeline) needs to recover.
- Track extending self-heal to the TTL-refresh paths as a follow-up (see
  .planning/quick/260714-l0p-fix-9-failing-tests-on-pr-283-cascade-tt/NOSCRIPT-ISSUE.md).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread rapyer/base.py Outdated
Comment thread rapyer/base.py Outdated
Comment thread rapyer/base.py Outdated
Comment thread rapyer/base.py
YedidyaHKfir and others added 2 commits July 14, 2026 21:26
- Remove the _has_cascade ClassVar from AtomicRedisModel and the
  marking loop in init_rapyer -- it was written but never read since
  aset_ttl/refresh_ttl unified onto the cascade Lua script, which is
  the sole source of cascade-traversal truth via the plan table baked
  in at register_scripts time.
- build_cascade_plan/validate_cascade_ttl_targets still run in
  init_rapyer for fail-fast config validation.
- Strip the matching _has_cascade stash/restore scaffolding from six
  test files; pure pass-through wrapper fixtures are removed in favor
  of the base fixture they wrapped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…iew)

Condense refresh_ttl's and aset_ttl's over-long cascade-ARGV comment
blocks down to their essential why -- comment text only, zero logic
change (should_execute=False / manual pipe.execute() pattern, ARGV
order, and CascadeResult construction are untouched).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread tests/integration/pipeline/test_pipeline_noscript_recovery.py
YedidyaHKfir and others added 7 commits July 16, 2026 17:49
…ry.lua

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…disConfig

- Add cascade_function_name field, init-baked (None on fakeredis)
- Exempt it from the _meta_locked freeze guard so arun_fcall self-heal can rewrite it

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Delete _CASCADE_FUNCTION_NAME module global and get_cascade_function_name
- register_cascade_function returns the plan-hashed name instead of writing a global
- run_fcall takes function_name explicitly; arun_fcall reads/refreshes it from redis_config
- handle_missing_function assigns the refreshed name onto redis_config
- Drop get_cascade_function_name from scripts package exports

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ad it to FCALL

- init_rapyer assigns register_cascade_function's return onto every Meta post-freeze
- Both base.py run_fcall sites (refresh_ttl, aset_ttl) pass self.Meta.cascade_function_name

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…sertions and conftests

- Unit assertions insert Meta.cascade_function_name as run_fcall's new second positional arg
- Integration conftests capture register_cascade_function's return onto Meta and restore in teardown

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
YedidyaHKfir and others added 10 commits July 20, 2026 15:29
- Delete unused extract_annotation from rapyer/utils/annotation.py
- Delete its sole test file tests/unit/cascade/test_extract_annotation.py
- field_with_flag (production superseder) and has_annotation untouched

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ecute sites

- Add shared aexecute_pipeline_with_cascade_self_heal + aretry_fcall_after_missing_function to registry.py
- ensure_pipeline/pipeline_with_execution route execute through the self-heal wrapper (lazy import, documented cycle)
- aset_ttl routes bare execute through the self-heal wrapper
- _apipeline replays FCALL on function-not-found, reusing aretry_fcall_after_missing_function
- Rewrite config.py freeze-exempt comment; drop resolved issue #284 notes
- Retry rewrites only the function-name slot; single retry then PersistentCascadeFunctionError
- fakeredis EXPIRE branch and single-FCALL atomicity preserved

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…call in test helpers

- Delete arun_fcall from registry.py (import + __all__ in scripts/__init__.py)
- handle_missing_function and PersistentCascadeFunctionError retained (used by self-heal)
- 3 integration _apply_cascade helpers call real_redis_client.fcall directly
- Production self-heal now covers what arun_fcall did (Task 2)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…284, RED)

- After FUNCTION FLUSH, aset_ttl(cascade=True) and refresh_ttl must reload the
  cascade function and still refresh the reachable subtree
- Currently fails: redis-py's async pipeline masks the function-not-found
  message, so the helper's string match never fires inside a pipeline

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…not error text (GREEN)

- redis-py's async pipeline annotate_exception (client.py:1585) overwrites
  exception.args with a non-f-string literal, destroying the "Function not found"
  message; every production FCALL runs inside a pipeline, so string-matching
  never fired there (only the deleted direct-client arun_fcall saw the real text)
- Add acascade_function_missing (FUNCTION LIST scan) + _pipeline_has_fcall guard
- Self-heal only fires on real Redis when the pipeline enqueued an FCALL and the
  cascade function is genuinely absent; other ResponseErrors re-raise unchanged
- Wire the registry-based detection into both the shared wrapper and _apipeline

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…drop cascade self-heal helpers

- context.py: ensure_pipeline + pipeline_with_execution use bare pipe.execute(), remove lazy registry imports
- base.py: aset_ttl uses pipe.execute(); _apipeline reverts to NOSCRIPT-only path (no FCALL-missing detection/replay)
- registry.py: delete six self-heal helpers; imports drop ResponseError, PersistentCascadeFunctionError, cascade.planner

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…te self-heal test, fix stale comments

- errors/cascade.py + __init__.py: remove PersistentCascadeFunctionError and its __all__ entry
- delete tests/integration/foreign_keys/test_cascade_self_heal.py
- config.py: cascade_function_name freeze-exemption comment now references init_rapyer(), not the removed self-heal path

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@yedidyakfir yedidyakfir changed the title TTL Cascade milestone — full diff + review fixes Milestone: Configurable TTL Cascade Jul 20, 2026
@yedidyakfir
yedidyakfir merged commit fff2a38 into develop Jul 20, 2026
56 of 57 checks passed
@yedidyakfir
yedidyakfir deleted the cascade-ttl-full-review branch July 20, 2026 15:23
yedidyakfir pushed a commit that referenced this pull request Aug 13, 2026
…eased entry since v1.3.4

Only #288 had an entry; five merged items were missing.

- [1.3.6] new: SF-held reference cascade (#289, Added) and multi-class
  union / polymorphic-base FK reach (#290, Fixed)
- [1.3.5] backfilled: the configurable TTL cascade feature itself (#283),
  the init_rapyer client-rebind fix (#276), runtime CPU optimizations (#263)

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants