Skip to content

[#1208] Implemented LinkCreationProcessor::link_creation() - #1222

Open
andre-senna wants to merge 6 commits into
masterfrom
senna-1208-2
Open

[#1208] Implemented LinkCreationProcessor::link_creation()#1222
andre-senna wants to merge 6 commits into
masterfrom
senna-1208-2

Conversation

@andre-senna

Copy link
Copy Markdown
Contributor

WIP towards #1208

link_creation() is the method where the actual action happens. It uses several parameters to control how and for how long LCA is supposed to keep trying to create links.

I also removed the code related to remote evaluation of link creation requests. This will be returned in a future PR (actually a future issue card). For now, we'll stick with local link creators only.

We are still missing the concrete link creators we use in the evaluation evolution POC. This will be added in a follow-up PR.

@andre-senna andre-senna self-assigned this Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2defa0a6-73af-44af-aed2-ead8384ad227

📥 Commits

Reviewing files that changed from the base of the PR and between cf5a3b7 and d361157.

📒 Files selected for processing (1)
  • src/agents/link_creation_agent/LinkCreationProcessor.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/agents/link_creation_agent/LinkCreationProcessor.cc

  • Implements local link creation in LinkCreationProcessor::link_creation(). The processor applies creation, visit, unproductive-visit, and round limits. It aborts unfinished query proxies and records LinkCreationStats.
  • Removes remote link-creation processing and rejects remote creator tags. Review stale remote state such as ongoing_remote_link_creation, plus error handling for invalid proxies and aborted queries.
  • Renames processor thread tracking and adds self-reaping. Review mutex usage, thread-ID removal, concurrent cleanup, and termination correctness.
  • LinkCreationStats is a small value object and does not add reported hot-path allocation. Review repeated shared_ptr copies and query-proxy lifetime retention during multiple rounds.
  • Tests cover statistics values and rejection of remote proxy creation. They do not cover processor limits, multiple rounds, unfinished-query abortion, thread cleanup, or error paths.

Walkthrough

The PR introduces LinkCreationStats, updates LinkCreationProxy APIs and remote handling, implements processor-side link-creation rounds, and renames processor thread tracking. Tests validate statistics and reject remote proxy creation.

Changes

Link creation flow

Layer / File(s) Summary
Statistics contract and creator implementations
src/agents/link_creation_agent/link_creators/LinkCreator.h, src/agents/link_creation_agent/link_creators/UnitTestLinkCreator.h, src/tests/cpp/link_creation_agent_test.cc
LinkCreator::create now returns LinkCreationStats with visited, created, and updated fields. Test creators and assertions use the new result type.
Proxy API and remote handling
src/agents/link_creation_agent/LinkCreationProxy.h, src/agents/link_creation_agent/LinkCreationProxy.cc, src/tests/cpp/link_creation_agent_test.cc
LinkCreationProxy::link_creation returns LinkCreationStats. Link-creation limits and round counting were added. Remote APIs and command handlers were removed, and remote creator tags are rejected.
Processor query rounds and thread tracking
src/agents/link_creation_agent/LinkCreationProcessor.h, src/agents/link_creation_agent/LinkCreationProcessor.cc
The processor uses processor_threads and thread_management_mutex. It runs bounded query rounds, processes answers, aborts unfinished proxies, increments rounds, and logs created-link counts. The disabled USE_MORK macro was added.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • singnet/das#1171: Related processor-thread self-reaping and cleanup changes.
  • singnet/das#1205: Updates link-creation test interfaces in the same test file.
  • singnet/das#1217: Introduced the link-creation components and APIs updated by this PR.

Suggested reviewers: ccgsnet

Sequence Diagram(s)

sequenceDiagram
  participant LinkCreationProcessor
  participant LinkCreationProxy
  participant QueryAnswer
  participant LinkCreator
  LinkCreationProcessor->>LinkCreationProxy: Issue query round
  LinkCreationProxy->>QueryAnswer: Drain query answers
  LinkCreationProcessor->>LinkCreationProxy: Process query answer
  LinkCreationProxy->>LinkCreator: Create links
  LinkCreator-->>LinkCreationProxy: Return LinkCreationStats
  LinkCreationProcessor->>LinkCreationProxy: Increment round count
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the implementation of link creation and the removal of remote evaluation support.
Title check ✅ Passed The title clearly identifies the main change: implementing LinkCreationProcessor::link_creation().
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.
Tests For Behavior Changes ✅ Passed Production link-creation logic changed, and src/tests/cpp/link_creation_agent_test.cc was updated for LinkCreationStats and remote-proxy rejection.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch senna-1208-2

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/agents/link_creation_agent/LinkCreationProxy.h (1)

117-117: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Remove the unused LinkCreatorRegistry::REMOTE_FUNCTION dependency.

is_link_creation_function_remote() compares link_creator_function_tag to LinkCreatorRegistry::REMOTE_FUNCTION, but LinkCreatorRegistry::REMOTE_FUNCTION is not declared/included from LinkCreationProxy.h. This currently breaks the build. Since remote evaluation is rejected elsewhere, drop the comparison and use a const local string literal instead of the remote registry tag.

🤖 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/agents/link_creation_agent/LinkCreationProxy.h` at line 117, Update
is_link_creation_function_remote() to remove the
LinkCreatorRegistry::REMOTE_FUNCTION reference and compare
link_creator_function_tag against a const local string literal instead. Do not
add the missing dependency or include; preserve the existing remote-evaluation
rejection behavior.
🧹 Nitpick comments (3)
src/tests/cpp/link_creation_agent_test.cc (2)

52-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add tests for round handling and processor thread cleanup.

The remote-creator rejection and the LinkCreationStats fields are covered. Two behavior changes in this PR are not covered:

  • LinkCreationProxy::inc_round_count() and stop_criteria_met(): assert that stop_criteria_met() returns false below MAX_ROUNDS and true after MAX_ROUNDS calls to inc_round_count().
  • LinkCreationProcessor thread tracking: assert that processor_threads returns to baseline after a command finishes, and that a duplicate thread id raises an error in run_command.

I can draft these cases if you want.

As per coding guidelines: "Test updates are required when production code changes: Add or update C++ tests (*_test.cc under src/tests/cpp/) ... when production code under src/ ... changes behavior".

🤖 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/tests/cpp/link_creation_agent_test.cc` around lines 52 - 56, Extend the
existing C++ tests to cover the untested round and processor-thread behavior.
Add assertions for LinkCreationProxy::stop_criteria_met() returning false before
MAX_ROUNDS and true after MAX_ROUNDS calls to inc_round_count(), and verify
LinkCreationProcessor::processor_threads returns to its baseline after a command
completes and that run_command rejects a duplicate thread ID.

Source: Coding guidelines


42-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Capture each LinkCreationStats once per input.

Lines 42-50 call link_creation nine times to assert three fields for three inputs. Each call builds a new QueryAnswer. Store one stats object per input and assert its three fields. This removes six redundant calls and makes the expected values easier to read.

♻️ Proposed refactor
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blah", 0.0)).created, 4);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blahhh", 0.5)).created, 6);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blahh", 1.0)).created, 5);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blah", 0.0)).updated, 5);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blahhh", 0.5)).updated, 7);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blahh", 1.0)).updated, 6);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blah", 0.0)).visited, true);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blahhh", 0.5)).visited, true);
-    EXPECT_EQ(proxy1.link_creation(make_shared<QueryAnswer>("blahh", 1.0)).visited, true);
+    LinkCreationStats stats1 = proxy1.link_creation(make_shared<QueryAnswer>("blah", 0.0));
+    EXPECT_EQ(stats1.created, 4);
+    EXPECT_EQ(stats1.updated, 5);
+    EXPECT_TRUE(stats1.visited);
+    LinkCreationStats stats2 = proxy1.link_creation(make_shared<QueryAnswer>("blahhh", 0.5));
+    EXPECT_EQ(stats2.created, 6);
+    EXPECT_EQ(stats2.updated, 7);
+    EXPECT_TRUE(stats2.visited);
+    LinkCreationStats stats3 = proxy1.link_creation(make_shared<QueryAnswer>("blahh", 1.0));
+    EXPECT_EQ(stats3.created, 5);
+    EXPECT_EQ(stats3.updated, 6);
+    EXPECT_TRUE(stats3.visited);
🤖 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/tests/cpp/link_creation_agent_test.cc` around lines 42 - 50, Update the
test around proxy1.link_creation to call it once for each of the three
QueryAnswer inputs, storing each returned LinkCreationStats object in a named
local variable. Assert created, updated, and visited on the corresponding stored
result, preserving all existing expected values.
src/agents/link_creation_agent/LinkCreationProcessor.cc (1)

101-108: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove dead remove_processor_thread method.

remove_processor_thread has no callers, while the private thread_process_one_query self-reap path already erases the finished thread id directly. Delete the method and its declaration.

🤖 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/agents/link_creation_agent/LinkCreationProcessor.cc` around lines 101 -
108, Delete the unused LinkCreationProcessor::remove_processor_thread method and
its class declaration. Keep the existing thread_process_one_query self-reap
logic that erases completed thread IDs directly.
🤖 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.

Inline comments:
In `@src/agents/link_creation_agent/LinkCreationProcessor.cc`:
- Around line 118-160: Prevent the first-round null dereference in the
link_creation loop by guarding or disabling the unfinished
issue_link_creation_query path until it returns a valid proxy. When enabling it,
pass proxy rather than nullptr so command parameters are available, and
consistently drain and test the pattern-matching proxy that owns the
query-answer queue, including the finished/abort checks around pm_proxy.

In `@src/agents/link_creation_agent/LinkCreationProxy.cc`:
- Around line 81-95: Update LinkCreationProxy::link_creation to acquire
api_mutex before reading link_creator_function_tag or
link_creation_function_object, using the existing guarded tag-state access
mechanism. Hold the lock through validation and state retrieval, but release it
before invoking link_creation_function_object->create(answer) so LinkCreator
remains outside the lock.

---

Outside diff comments:
In `@src/agents/link_creation_agent/LinkCreationProxy.h`:
- Line 117: Update is_link_creation_function_remote() to remove the
LinkCreatorRegistry::REMOTE_FUNCTION reference and compare
link_creator_function_tag against a const local string literal instead. Do not
add the missing dependency or include; preserve the existing remote-evaluation
rejection behavior.

---

Nitpick comments:
In `@src/agents/link_creation_agent/LinkCreationProcessor.cc`:
- Around line 101-108: Delete the unused
LinkCreationProcessor::remove_processor_thread method and its class declaration.
Keep the existing thread_process_one_query self-reap logic that erases completed
thread IDs directly.

In `@src/tests/cpp/link_creation_agent_test.cc`:
- Around line 52-56: Extend the existing C++ tests to cover the untested round
and processor-thread behavior. Add assertions for
LinkCreationProxy::stop_criteria_met() returning false before MAX_ROUNDS and
true after MAX_ROUNDS calls to inc_round_count(), and verify
LinkCreationProcessor::processor_threads returns to its baseline after a command
completes and that run_command rejects a duplicate thread ID.
- Around line 42-50: Update the test around proxy1.link_creation to call it once
for each of the three QueryAnswer inputs, storing each returned
LinkCreationStats object in a named local variable. Assert created, updated, and
visited on the corresponding stored result, preserving all existing expected
values.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: eeefc3a2-a62d-4758-bb46-bf1852990fcd

📥 Commits

Reviewing files that changed from the base of the PR and between 95aece8 and c7eb675.

📒 Files selected for processing (8)
  • src/agents/link_creation_agent/LinkCreationProcessor.cc
  • src/agents/link_creation_agent/LinkCreationProcessor.h
  • src/agents/link_creation_agent/LinkCreationProxy.cc
  • src/agents/link_creation_agent/LinkCreationProxy.h
  • src/agents/link_creation_agent/link_creators/LinkCreator.cc
  • src/agents/link_creation_agent/link_creators/LinkCreator.h
  • src/agents/link_creation_agent/link_creators/UnitTestLinkCreator.h
  • src/tests/cpp/link_creation_agent_test.cc
💤 Files with no reviewable changes (1)
  • src/agents/link_creation_agent/link_creators/LinkCreator.cc

Comment thread src/agents/link_creation_agent/LinkCreationProcessor.cc
Comment thread src/agents/link_creation_agent/LinkCreationProxy.cc
@andre-senna
andre-senna requested a review from ccgsnet August 6, 2026 19:05
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