Repository navigation
RED-217728 Allow pre-command hooks to abort JSON commands on error, make pre-command hook optional - #1653
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1653 +/- ##
==========================================
- Coverage 85.97% 85.84% -0.14%
==========================================
Files 15 15
Lines 5306 5278 -28
==========================================
- Hits 4562 4531 -31
- Misses 744 747 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8c00e22. Configure here.
gabsow
left a comment
There was a problem hiding this comment.
Reviewed at 3205244. Built and ran both feature configurations locally and checked the downstream RedisJsonHdt consumer.
What looks right: the hook still runs before manager selection on both the command and shared-API paths, so HDT's set_curr_ctx ordering is preserved; json_forget → json_del still fires the hook exactly once; all ~26 JSONAPI_* sites were updated consistently; and no LLAPI version/struct bump is needed since no field was added. Default-feature cargo test -p redis_json passes.
Main concerns (details inline):
- Two of the three new hook tests never run in CI.
pre_command_error_skips_commandandpre_command_success_runs_commandare gated on--features as-library, which no CI job enables. The PR's headline semantics are therefore unverified by CI, and this is a likely contributor to the failingcodecov/projectcheck. pre_command_success_runs_commandpasses for an accidental reason. It only seesOk(())because non-hygienicmacro_rulesitem resolution lets the function-localpre_commandshadow the module-level erroring one. Verified: renaming the local helper makes the test fail. Athread_local!switch would make the intent explicit and also let all three cases run under default features, fixing (1) at the same time.- Swallowing the hook error in
run_on_manager!deserves a log line and a doc entry. Keeping LLAPI behavior unchanged is defensible, but a fully discarded error in a RediSearch-driven path is hard to diagnose, and the command/LLAPI divergence should be documented inAGENTS.md's LLAPI section rather than only in a macro comment. - Making
pre_command_functionoptional weakens the contract for the consumer that needs it. HDT's hook is mandatory setup; omitting the key now compiles and fails at runtime instead of at build time. Passing an explicit no-op at the OSS site would drop the no-op function without loosening the macro. - Coordinate the downstream break. HDT's hook returns
()and won't compile after this merges — worth linking the paired PR.
Smaller items not worth inline comments:
command_without_pre_command_runsiscfg(not(as-library))while the others arecfg(as-library), so no single build exercises both branches of the new$(...)?optionality. Same root cause as (1)/(2).- Commit 2's message, "make pre command hook optionaly", has a typo and drops the
RED-217728prefix that commit 1 carries — worth squashing or rewording. - No flow-test coverage of the new behavior. Understandable now that OSS has no hook, but a smoke test on the HDT side (command rejected while the LLAPI still reads the same key) would be the real end-to-end guard for concern (3).
Nothing here is a blocking correctness bug in the production path; (1) and (2) are the ones I'd want resolved before merge, since as it stands the new behavior has no CI coverage.
Generated by Claude Code
| macro_rules! json_command { | ||
| ($cmd:ident) => { | ||
| |ctx: &Context, args: Vec<RedisString>| -> RedisResult { | ||
| $($pre_command_function_expr(ctx, &args)?;)? |
There was a problem hiding this comment.
This is a breaking change for the downstream consumer — worth linking the paired PR in the description so the two land together.
RedisJsonHdt/src/lib.rs:867 currently declares fn pre_command(ctx: &Context, _args: &Vec<RedisString>) returning (). Once ? is applied here, that crate won't compile until the signature becomes RedisResult<()>. (The &args → &Vec<RedisString> coercion is fine, so the signature return type is the only required change.)
Ordering is preserved correctly, for what it's worth: the hook still runs before manager selection, so HDT's set_curr_ctx happens before is_hdt_db() is evaluated — and json_forget → json_del still fires the hook exactly once.
Generated by Claude Code
There was a problem hiding this comment.
Leaving this one open — it's the only item from my review still outstanding, and I'd rather it stay visible than get resolved on a documentation-only fix.
The AGENTS.md migration note ("Existing hooks returning () must return Ok(()) after setup") helps, but I checked and there's no paired RedisJsonHdt PR queued. On the blast radius: HDT declares redis_json = { git = "...", branch = "master", features = ["as-library"] } but commits a Cargo.lock pinned to rev 1c74f65, so this won't break the moment it merges — it breaks on the next routine pin bump, with a fairly opaque "? cannot be applied to ()" error at the macro expansion site. Queuing the one-line HDT change now seems better than leaving that trap for whoever runs the next cargo update.
One note for whoever writes it: per the new contract, setup has to complete before any Err return, since the LLAPI path ignores the error and proceeds. set_curr_ctx is unconditional today so HDT satisfies this, but a guard added to that same hook later must not early-return ahead of it.
Generated by Claude Code
|
Re-reviewed at
I've resolved six of my seven threads. The one I left open is the downstream coordination: there's no paired Otherwise this looks good to me. Everything completed in CI is green (clippy, linter, sanitizer, coverage, memory-regression, Bugbot); only Generated by Claude Code |
gabsow
left a comment
There was a problem hiding this comment.
Approved at d5ab0a7. The CI coverage gap is addressed by running the as-library tests, hook success/error selection is explicit, and the command/LLAPI contract is documented. No remaining blocking code issue found in this review.
Please keep the HDT migration follow-up visible: its hook must return RedisResult<()> with Ok(()) after setup when updating the RedisJSON dependency. The codecov/project threshold failure also remains to be resolved or accepted through the normal maintainer process; codecov/patch and the build/test checks pass.
…ake pre-command hook optional (#1653)
…ake pre-command hook optional (#1653)
…ake pre-command hook optional (#1653)
…ake pre-command hook optional (#1653)
…ake pre-command hook optional (#1653)

Note
Medium Risk
Changes macro contracts and command dispatch for all JSON commands; LLAPI behavior intentionally differs (hook errors ignored), which downstream embedders must understand when migrating hooks from
()toOk(()).Overview
Makes the
pre_command_functionhook optional onredis_json_module_create!/redis_json_module_export_shared_api!and changes it to returnRedisResult<()>so JSON command wrappers can abort before manager dispatch when the hook errors. OSS drops its no-op hook;run_on_manager!still runs an optional hook for LLAPI setup but discards errors so shared C API reads are not blocked.Adds
as-libraryunit tests for success/error hook paths and documents the contract in AGENTS.md. CI, Makefile, and workflows now runcargo test -p redis_json --features as-libraryalongside the default test suite.Reviewed by Cursor Bugbot for commit d5ab0a7. Bugbot is set up for automated code reviews on this repo. Configure here.