Skip to content

Agent report error - #44

Merged
EddyTheCo merged 4 commits into
mainfrom
agent-report-error
Aug 5, 2026
Merged

Agent report error#44
EddyTheCo merged 4 commits into
mainfrom
agent-report-error

Conversation

@AndreaRicchi

@AndreaRicchi AndreaRicchi commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added support for handling ConnMan connection error reports with optional retry responses.
    • Added callback registration for connection and agent error handling.
  • Bug Fixes

    • D-Bus agent requests now consistently receive replies, including cancel and release actions.
    • Error details are safely forwarded, with retry behavior supported when requested.
  • Tests

    • Added integration coverage for error reporting, retry handling, and cancel responses.

The Cancel and Release branches of dispatch_method_call() returned
without ever calling g_dbus_method_invocation_return_value(), and were
taken only when a callback had been installed. In both cases the
D-Bus method invocation was left pending: connman gets an answer only
once its own reply timeout expires, and the GDBusMethodInvocation is
leaked.

Split the callback check from the method match so the invocation is
always completed, with or without a registered handler.

Signed-off-by: Andrea Ricchi <andrea.ricchi@amarulasolutions.com>
@AndreaRicchi
AndreaRicchi requested a review from EddyTheCo August 5, 2026 13:00
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d8f728d-dc28-4405-a85c-8f326f12db3b

📥 Commits

Reviewing files that changed from the base of the PR and between 7452cf8 and 7821b1d.

📒 Files selected for processing (6)
  • include/amarula/dbus/connman/gagent.hpp
  • include/amarula/dbus/connman/gmanager.hpp
  • src/dbus/gconnman_agent.cpp
  • src/dbus/gconnman_manager.cpp
  • tests/CMakeLists.txt
  • tests/gconnman_agent_test.cpp
🚧 Files skipped from review as they are similar to previous changes (5)
  • tests/CMakeLists.txt
  • src/dbus/gconnman_manager.cpp
  • include/amarula/dbus/connman/gagent.hpp
  • src/dbus/gconnman_agent.cpp
  • include/amarula/dbus/connman/gmanager.hpp

📝 Walkthrough

Walkthrough

ConnMan agent error reporting now supports registered callbacks that return a retry decision. Agent methods always complete their D-Bus replies. Manager wiring forwards service errors, and integration tests validate retry and response behavior.

Changes

ConnMan agent reporting

Layer / File(s) Summary
Callback contracts
include/amarula/dbus/connman/gagent.hpp, include/amarula/dbus/connman/gmanager.hpp
Agent and manager APIs define and store retry-aware error callbacks.
Agent dispatch and manager wiring
src/dbus/gconnman_manager.cpp, src/dbus/gconnman_agent.cpp
The manager forwards service errors to the registered callback. The agent returns retry errors or empty responses and completes Cancel and Release calls.
Agent integration validation
tests/gconnman_agent_test.cpp, tests/CMakeLists.txt
Tests validate callback data, retry responses, and completed agent method calls. The new test is added to the ConnMan test target.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ConnMan
  participant Agent
  participant Manager
  participant Service
  participant OnReportErrorCallback
  ConnMan->>Agent: ReportError(service, error)
  Agent->>Manager: invoke registered report-error handler
  Manager->>Service: locate service
  Manager->>OnReportErrorCallback: invoke service and error
  OnReportErrorCallback-->>Manager: return retry decision
  Manager-->>Agent: return retry decision
  Agent-->>ConnMan: retry D-Bus error or empty response
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding ConnMan agent report-error handling and retry behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 agent-report-error

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🧩 Build Artifacts

✅ The following build artifacts were produced:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/gconnman_agent_test.cpp (1)

107-112: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Validate the forwarded Service argument.

The callback discards service. Assert service->objPath() equals service_path. This test then detects a regression in the ReportError service lookup.

Proposed test update
 std::string reported_error;
+std::string reported_service_path;
 manager->onReportError(
-    [&reported_error](const auto& /*service*/, const std::string& error) {
+    [&reported_error, &reported_service_path](
+        const auto& service, const std::string& error) {
+        reported_service_path = service->objPath();
         reported_error = error;
         return true;
     });
 
 ...
 
 EXPECT_EQ(reported_error, "invalid-key");
+EXPECT_EQ(reported_service_path, service_path);
🤖 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 `@tests/gconnman_agent_test.cpp` around lines 107 - 112, Update the
onReportError callback setup in gconnman_agent_test.cpp so the lambda validates
the forwarded Service argument instead of discarding it; use the existing
service_path expectation and assert that service->objPath() matches it before
capturing the error string. Keep the reported_error assignment intact so the
test still verifies the error text while also catching regressions in the
ReportError service lookup.
🤖 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 `@tests/gconnman_agent_test.cpp`:
- Around line 107-112: Update the onReportError callback setup in
gconnman_agent_test.cpp so the lambda validates the forwarded Service argument
instead of discarding it; use the existing service_path expectation and assert
that service->objPath() matches it before capturing the error string. Keep the
reported_error assignment intact so the test still verifies the error text while
also catching regressions in the ReportError service lookup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0235d0db-a1cf-431d-bba1-813994fd8354

📥 Commits

Reviewing files that changed from the base of the PR and between 7452cf8 and eeb55b7.

📒 Files selected for processing (6)
  • include/amarula/dbus/connman/gagent.hpp
  • include/amarula/dbus/connman/gmanager.hpp
  • src/dbus/gconnman_agent.cpp
  • src/dbus/gconnman_manager.cpp
  • tests/CMakeLists.txt
  • tests/gconnman_agent_test.cpp

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🧩 Build Artifacts

✅ The following build artifacts were produced:

@EddyTheCo EddyTheCo 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.

The invocation release for other methods was missing. Thanks.
In general, I like the changes; just please double-check my comments.

Comment thread src/dbus/gconnman_agent.cpp
Comment thread tests/gconnman_agent_test.cpp Outdated
ReportError parsed its arguments, logged them and returned without ever
completing the invocation. connman holds the pending Service.Connect()
reply until the agent answers, so a failed connection attempt surfaced
to the caller only when its own D-Bus reply timeout expired.

Always complete the invocation, and let the handler ask for a retry:
returning true replies net.connman.Agent.Error.Retry, which makes
connman reconnect with the credentials it already has instead of
requesting them again. ReportErrorCallback therefore returns bool, and
gets the setter it was missing.

The GVariant strings are copied into std::string before the children are
unref'd, since the borrowed pointers do not outlive them once the
callback is invoked after the unref.

The callback runs on the D-Bus dispatch thread while connman waits, so
it must not block; exceptions escaping it are caught so the invocation
is still answered.

Signed-off-by: Andrea Ricchi <andrea.ricchi@amarulasolutions.com>
Expose the agent's ReportError to consumers of Manager, mapping the
connman object path to the matching Service and forwarding the connman
error string ("invalid-key", "connect-failed", ...). Returning true from
the callback asks connman to retry with the credentials it already has.

The service lookup and the callback copy are taken under mtx_, and the
callback is invoked with the lock released, like the other changed
callbacks: it runs on the D-Bus dispatch thread and typically wants to
call back into Manager, which locks the same non-recursive mutex.

Signed-off-by: Andrea Ricchi <andrea.ricchi@amarulasolutions.com>
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@AndreaRicchi
AndreaRicchi requested a review from EddyTheCo August 5, 2026 14:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/gconnman_agent_test.cpp (1)

112-118: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the callback false-result branch.

The tests cover no handler and a handler that returns true. They do not cover a handler that returns false. A change that retries whenever report_error_cb_ exists would pass both current tests.

Add a test that registers a callback returning false, then assert a normal ReportError reply and the callback payload.

🤖 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 `@tests/gconnman_agent_test.cpp` around lines 112 - 118, Add a test in the
existing gconnman agent test flow that registers an onReportError callback
returning false, invokes the normal ReportError request, and asserts both the
successful reply and the callback’s reported service path and error payload.
Keep the existing no-handler and true-result coverage unchanged.
🤖 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 `@tests/gconnman_agent_test.cpp`:
- Around line 112-118: Add a test in the existing gconnman agent test flow that
registers an onReportError callback returning false, invokes the normal
ReportError request, and asserts both the successful reply and the callback’s
reported service path and error payload. Keep the existing no-handler and
true-result coverage unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 85987d38-1099-426b-a1d2-d3f5ea85c398

📥 Commits

Reviewing files that changed from the base of the PR and between 7452cf8 and 7833015.

📒 Files selected for processing (6)
  • include/amarula/dbus/connman/gagent.hpp
  • include/amarula/dbus/connman/gmanager.hpp
  • src/dbus/gconnman_agent.cpp
  • src/dbus/gconnman_manager.cpp
  • tests/CMakeLists.txt
  • tests/gconnman_agent_test.cpp
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/dbus/gconnman_manager.cpp
  • include/amarula/dbus/connman/gmanager.hpp
  • tests/CMakeLists.txt
  • src/dbus/gconnman_agent.cpp
  • include/amarula/dbus/connman/gagent.hpp

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🧩 Build Artifacts

✅ The following build artifacts were produced:

Comment thread tests/gconnman_agent_test.cpp Outdated
Cover that the agent answers Cancel and ReportError, and that a handler
returning true makes the agent reply net.connman.Agent.Error.Retry.

The retry test needs a service the agent knows about, since a retry is
asked only for a path present in the Manager service list, so it waits
for the ServicesChanged callback instead of reading that list right
after construction, where the asynchronous GetServices() has not
answered yet. The wait happens on the test thread: the callback runs on
the same GLib thread that dispatches the agent method calls, so a
synchronous call issued from there would never be answered.

The calls use a short reply timeout on purpose: an agent that never
completes the invocation is otherwise indistinguishable from a slow one
until the D-Bus default 25s timeout expires. Like the other connman
tests these need a running connmand and skip when it is absent.

Signed-off-by: Andrea Ricchi <andrea.ricchi@amarulasolutions.com>
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🧩 Build Artifacts

✅ The following build artifacts were produced:

@EddyTheCo EddyTheCo 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.

Very nice. Thanks.
After these changes, there is no need to call remove when the service is in invalid-key, connman calls request input again.

@EddyTheCo
EddyTheCo merged commit ad19c3a into main Aug 5, 2026
3 checks passed
@EddyTheCo
EddyTheCo deleted the agent-report-error branch August 5, 2026 15:11
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