Skip to content

fix: reload Lua scripts after Redis NOSCRIPT#17

Open
julianjear wants to merge 1 commit into
Openpanel-dev:mainfrom
julianjear:fix-noscript-reload
Open

fix: reload Lua scripts after Redis NOSCRIPT#17
julianjear wants to merge 1 commit into
Openpanel-dev:mainfrom
julianjear:fix-noscript-reload

Conversation

@julianjear
Copy link
Copy Markdown

@julianjear julianjear commented May 18, 2026

Summary\n- retry GroupMQ Lua evals once when Redis returns NOSCRIPT\n- clear the stale client-side SHA cache before reloading the script\n- add unit coverage for retry and non-NOSCRIPT error behavior\n- add an integration regression for SCRIPT FLUSH with a real Redis connection\n\n## Context\nRedis Lua script cache is volatile across restarts, failovers, and SCRIPT FLUSH. GroupMQ caches SCRIPT LOAD SHA values client-side, so a stale SHA can make every queue operation fail until the process restarts.\n\n## Verification\n- npx pnpm@10.18.3 exec vitest run test/lua-loader.test.ts\n- npx pnpm@10.18.3 run build\n\nNote: full typecheck currently fails on existing queue.corrupted-jobs.test.ts typing errors unrelated to this change.

Summary by CodeRabbit

  • Bug Fixes

    • Lua script execution is now resilient to script cache misses with automatic reload and retry functionality.
  • Tests

    • Added comprehensive test coverage for script cache miss scenarios and error handling validation.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6c0b0730-17f7-4116-a52b-c5175a7ffff0

📥 Commits

Reviewing files that changed from the base of the PR and between 6439d4e and 573c3e5.

📒 Files selected for processing (3)
  • src/lua/loader.ts
  • test/lua-loader.test.ts
  • test/queue.redis-disconnect.test.ts

📝 Walkthrough

Walkthrough

The PR adds resilience to Redis Lua script execution. evalScript now retries after NOSCRIPT errors by evicting the cached script SHA and reloading; unit tests validate the retry behavior for both NOSCRIPT and non-retryable errors, and an integration test confirms the queue survives script cache flushes.

Changes

Redis Lua Script NOSCRIPT Resilience

Layer / File(s) Summary
Script loader resilience implementation and unit tests
src/lua/loader.ts, test/lua-loader.test.ts
evalScript wraps execution via a helper that loads the script SHA, attempts evalsha, and on NOSCRIPT deletes the cached SHA and retries once. Unit tests verify the retry succeeds and that non-NOSCRIPT errors are not retried.
Queue integration test for script cache flush
test/queue.redis-disconnect.test.ts
Test flushes the Redis Lua script cache and verifies queue can enqueue jobs and correctly track waiting count after the flush.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant evalScript
  participant Cache
  participant Redis as Redis Client
  Caller->>evalScript: evalScript(client, scriptName, args)
  evalScript->>Cache: lookup SHA for script
  evalScript->>Redis: evalsha(sha, args)
  Redis-->>evalScript: NOSCRIPT error
  evalScript->>Cache: delete SHA
  evalScript->>Redis: script('load', scriptCode)
  Redis-->>evalScript: new SHA
  evalScript->>Redis: evalsha(newSha, args)
  Redis-->>evalScript: result
  evalScript-->>Caller: result
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A script that vanished from the cache one day,
Now reloads itself in every Redis way,
No more NOSCRIPT errors make it fail,
Just retry once and tell the tale! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: reload Lua scripts after Redis NOSCRIPT' directly and clearly summarizes the main change: making the Lua script loader resilient to Redis NOSCRIPT errors by reloading scripts.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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 and usage tips.

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.

1 participant