Skip to content

fix: make AlgorithmSvc usable - #39

Merged
wdconinc merged 1 commit into
mainfrom
claude/fix-algorithm-svc
Oct 29, 2026
Merged

wdconinc merged 1 commit into
mainfrom
claude/fix-algorithm-svc

Conversation

@wdconinc

Copy link
Copy Markdown
Contributor

Stacked on #38.

Summary

AlgorithmSvc did not compile once used, so it could not have any users. It:

  • lacked ALGORITHMS_DEFINE_LOGGED_SERVICE (no default constructor or kName) and init();
  • used Algo::algorithm_type as a value, and inverted available();
  • stored std::string_view keys of temporary strings;
  • called std::for_each with four arguments in ls();
  • returned raw pointers as std::unique_ptr;
  • locked a function-local static std::lock_guard, which never releases its mutex.

The rewrite keeps the design (factories indexed by algorithm signature, then by demangled type name) with:

  • owning std::string name keys with heterogeneous lookup by std::string_view;
  • a member mutex guarding the factories;
  • factories returning std::unique_ptr<AlgorithmBase>;
  • ls() returning std::vector<std::string>;
  • demangled type names in error messages.

Tests

New core/tests/algorithm_svc.cpp: registration (including duplicates), use before ServiceSvc::init(), listing by algorithm type, creating and running instances, and rejecting unknown names, unknown types and empty names.

With the whole stack (#34 to this PR), line coverage of core is 99.5% (gcov/lcov). The two uncovered lines are an unreachable demangling error branch and a gcov artifact on a closing brace.

Test plan

  • clang++ Debug/Release and g++ Debug/Release with CI warning flags in eic_xl:nightly: 85/85 tests pass
  • CI

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review surfaced no outstanding defects or unresolved concerns, leaving nothing that would block approval.

No open issues 🎉

What changed in this PR

This PR rewrites AlgorithmSvc (a factory service that creates Algorithm instances indexed by algorithm signature and demangled type name) so it actually compiles and works, and adds a dedicated test. Previously the service could not have any users because it lacked the service boilerplate/init(), misused algorithm_type as a value, inverted available(), stored dangling string_view keys, mislocked a function-local static lock_guard, and returned raw pointers as unique_ptr. The fix makes the service usable within the broader stacked effort to get core fully tested.

Changes:

  • Rewrites AlgorithmSvc with owning std::string keys + heterogeneous lookup, a member mutex, try_emplace for idempotent registration, unique_ptr<AlgorithmBase> factories, demangled type names in errors, and the ALGORITHMS_DEFINE_LOGGED_SERVICE/init() boilerplate.
  • Adds core/tests/algorithm_svc.cpp covering registration (incl. duplicates), use-before-init() rejection, listing by type, instance creation/execution, and rejection of unknown names/types and empty names.
File Description
core/​include/​algorithms/​algorithm.h Rewrites AlgorithmSvc to compile and function correctly: service boilerplate + init(), type-correct algorithm_type usage, member mutex, owning string keys with transparent lookup, and proper unique_ptr ownership transfer.
core/​tests/​algorithm_svc.cpp New Catch2 test exercising the full service lifecycle (register/list/get/process and error cases) in a single process, auto-registered via the existing test CMake GLOB.

Review effort: Balanced

@wdconinc
wdconinc force-pushed the claude/fix-geosvc-init branch from d781b8b to 35fe9e7 Compare October 28, 2026 23:59
@wdconinc
wdconinc changed the base branch from claude/fix-geosvc-init to main October 29, 2026 00:14
AlgorithmSvc did not compile once used: it lacked the logged service
boilerplate and init(), used Algo::algorithm_type as a value, inverted
available(), stored string_view keys of temporary strings, called
std::for_each with four arguments, and returned raw pointers as
unique_ptr. Its static lock_guard also never released its mutex.

Rewrite it with owning name keys (with heterogeneous lookup), a member
mutex guarding the factories, std::unique_ptr factories, and ls()
returning std::string names. Error messages use demangled type names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wdconinc
wdconinc force-pushed the claude/fix-algorithm-svc branch from 20d698e to d14c20f Compare October 29, 2026 00:15
@wdconinc
wdconinc merged commit a725d47 into main Oct 29, 2026
6 checks passed
@wdconinc
wdconinc deleted the claude/fix-algorithm-svc branch October 29, 2026 00:31
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