refactor: extract apply_work inner-loop logic into helper f…#476
Conversation
…unctions Break the monolithic apply_work() loop into focused helpers: apply_init_contexts, apply_maybe_reload_config, apply_wait_events, apply_maybe_cleanup_resolutions, apply_check_readonly (ReadonlyAction enum), apply_recv_from_stream, apply_dispatch_message, apply_end_of_iteration, apply_exception_reset. No behaviour change. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe refactoring introduces a set of modularized static helper functions to decompose ChangesApply Worker Control Flow Refactoring
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/spock_apply.c (1)
3370-3383: 💤 Low valueConsider adding a defensive check for
my_exception_log_index >= 0.The code accesses
exception_log_ptr[my_exception_log_index]after checking thatexception_log_ptr != NULL, but doesn't verify thatmy_exception_log_index >= 0. While connection-class errors before the first BEGIN would be rethrown viais_connection_class_error(), a non-connection error during early startup (beforehandle_beginallocates a slot) could reach this code withmy_exception_log_index == -1.This is pre-existing behavior (the logic was moved from inline code), but adding a defensive check would make it safer.
🛡️ Suggested defensive fix
/* * Save the initial exception message and operation type so we can * include them in the exception_log if operations succeed on retry. */ - if (exception_log_ptr != NULL) + if (exception_log_ptr != NULL && my_exception_log_index >= 0) { snprintf(exception_log_ptr[my_exception_log_index].initial_error_message, sizeof(exception_log_ptr[my_exception_log_index].initial_error_message),🤖 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 `@src/spock_apply.c` around lines 3370 - 3383, Add a defensive check that my_exception_log_index is non-negative before indexing exception_log_ptr: after confirming exception_log_ptr != NULL, verify my_exception_log_index >= 0 and only then assign to exception_log_ptr[my_exception_log_index].initial_error_message and .failed_action using edata->message and xact_action_counter; if my_exception_log_index is negative, skip these assignments (or handle via the existing is_connection_class_error()/handle_begin logic) to avoid out-of-bounds access. Ensure references to exception_log_ptr, my_exception_log_index, initial_error_message, failed_action, edata, xact_action_counter, is_connection_class_error(), and handle_begin are used to locate and implement the guard.
🤖 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 `@src/spock_apply.c`:
- Around line 3370-3383: Add a defensive check that my_exception_log_index is
non-negative before indexing exception_log_ptr: after confirming
exception_log_ptr != NULL, verify my_exception_log_index >= 0 and only then
assign to exception_log_ptr[my_exception_log_index].initial_error_message and
.failed_action using edata->message and xact_action_counter; if
my_exception_log_index is negative, skip these assignments (or handle via the
existing is_connection_class_error()/handle_begin logic) to avoid out-of-bounds
access. Ensure references to exception_log_ptr, my_exception_log_index,
initial_error_message, failed_action, edata, xact_action_counter,
is_connection_class_error(), and handle_begin are used to locate and implement
the guard.
…unctions
Break the monolithic apply_work() loop into focused helpers: apply_init_contexts, apply_maybe_reload_config, apply_wait_events, apply_maybe_cleanup_resolutions, apply_check_readonly (ReadonlyAction enum), apply_recv_from_stream, apply_dispatch_message, apply_end_of_iteration, apply_exception_reset. No behaviour change.