Skip to content

Refactor duplicated code in resiliency examples and channel classes - #1

Draft
ArivoliR with Copilot wants to merge 3 commits into
masterfrom
copilot/refactor-duplicated-code
Draft

ArivoliR with Copilot wants to merge 3 commits into
masterfrom
copilot/refactor-duplicated-code

Conversation

Copilot AI commented Nov 10, 2025 •

Copy link
Copy Markdown

Identified and eliminated ~134 lines of duplicated code across resiliency examples and channel classes.

Changes

Resiliency Examples

  • Extracted common test helpers (universal_ans, validate, mark_faulty_nodes) to libs/full/resiliency_distributed/examples/common.hpp
  • Both async_replicate_distributed.cpp and async_replay_distributed.cpp now use shared implementations
  • Removed ~90 lines of duplicated code

Channel Classes

  • Introduced channel_close_mixin<Derived, T> CRTP base class for shared close() implementations
  • Applied to channel<T> and send_channel<T> classes
  • Removed 44 lines of duplicated code while maintaining binary compatibility
namespace detail {
    template <typename Derived, typename T>
    class channel_close_mixin {
        // Four close() overloads for different launch policies
        void close(launch::apply_policy, bool force_delete_entries = false);
        hpx::future<std::size_t> close(launch::async_policy, bool force_delete_entries = false);
        std::size_t close(launch::sync_policy, bool force_delete_entries = false);
        std::size_t close(bool force_delete_entries = false);
    };
}

template <typename T>
class channel : public client_base<...>, public detail::channel_close_mixin<channel<T>, T> {
    // close() methods now inherited from mixin
};

All public APIs remain unchanged.

Original prompt

Find and refactor duplicated code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 10, 2025 13:27
Co-authored-by: ArivoliR <53344634+ArivoliR@users.noreply.github.com>
Co-authored-by: ArivoliR <53344634+ArivoliR@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor duplicated code in resiliency examples and channel classes Nov 10, 2025
Copilot AI requested a review from ArivoliR November 10, 2025 13:34
ArivoliR pushed a commit that referenced this pull request Aug 13, 2026
Two bugs in hpx::serialization::detail::load() for std::exception_ptr:

1. Double-read of archive fields (Bug #1 - data corruption):
   In the load() function, for hpx_exception and std_system_error types,
   the err_value and err_message fields were read from the archive twice:
   once via 'ar & ...' and again via 'ar >> ...'. Since save() writes each
   field only once, this caused the read cursor to advance by 2x, silently
   producing garbled error codes and messages in any distributed HPX
   application that propagates these exception types across localities.

   Fix: Remove the redundant 'ar & ...' reads; keep only 'ar >> ...'
   which matches the 'ar << ...' used in save().

2. Type mismatch for throw_line_ (Bug TheHPXProject#3 - platform-specific corruption):
   save() declares throw_line_ as 'long' (8 bytes on 64-bit Linux), but
   load() declared it as 'int' (4 bytes). This caused the serializer to
   write 8 bytes and the deserializer to read only 4, shifting all
   subsequent field reads by 4 bytes on affected platforms.

   Fix: Change 'int throw_line_ = 0' to 'long throw_line_ = 0' in load()
   to match the type used in save().

Additionally, added a regression test to verify that serialization of
hpx::exception, std::system_error, std::runtime_error, and sequential
round-tripping behaves correctly.

Signed-off-by: arpittkhandelwal <arpitkhandelwal810@gmail.com>
ArivoliR pushed a commit that referenced this pull request Aug 13, 2026
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