Reviewing changes to Sonde

This guide is for anyone reviewing a change to the library, human or AI agent. It explains what to run, what to read, and what to look for. Reviewers should know the rules the code relies on; most serious problems break one of them.

The goal of a review

A review answers three questions:

  1. Does it work? Does the change do what it says, including in the error cases and when things happen in an unexpected order?
  2. Is it safe? Sonde is a remote control for a running process. A mistake can let a client read memory, crash the application, or reach it from a web page.
  3. Can the next person maintain it? Is it tested, documented, consistent with the rest of the code, and in the right place?

Style preferences matter much less than these. Raise them as nits, if at all.

Step 1: run the checks

Check out the change and run mise run check (formatting, build, unit tests, smoke test, clang-tidy, Doxygen and links: the same as the pre-push hook), or the commands one by one:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
cmake --build build                          # must build with no warnings
ctest --test-dir build                       # all unit tests pass
python3 tests/smoke_test.py build            # end-to-end test passes
cmake --build build --target clang-tidy      # no findings
cmake --build build --target docs            # no Doxygen warnings
python3 tools/check.py format-check          # Qt style (.clang-format)
python3 tests/check_links.py                 # documentation links

and, if the change touches library code:

cmake -S . -B build-cov -G Ninja -DSONDE_COVERAGE=ON -DSONDE_BUILD_EXAMPLES=OFF
cmake --build build-cov --target coverage    # line coverage must stay at least 80%

If the change touches the HTTP parser (httpparser.cpp), JSON-RPC dispatch, argument validation or JSON conversion, also run the fuzzers (needs Docker):

python3 tests/fuzz/run.py --seconds 300

Open build-cov/coverage/html/index.html and look at the files the change touched. New lines shown in red are untested.

Passing checks are necessary, not sufficient. They tell you the code compiles cleanly, the existing tests still pass, and everything has a doc comment. They don’t tell you the new behaviour is tested, the comments are true, or the design is right. That is what the rest of the review is for.

Step 2: understand the change

Before judging details:

Step 3: go through the checklist

Not every item applies to every change. Skip the ones that don’t.

Protocol and behaviour

Lifetime and ownership

These are the most common source of crashes in asynchronous Qt code.

Threads

Security

Qt and build compatibility

Tool design

The client of a tool is usually an AI model. It sees only the name, description, schema and results, so these are the user interface.

Tests

Code quality and documentation

Problems we have actually hit

Real bugs found in this codebase. Each is the kind of thing to look for.

Problem Why it slipped through What to check
An automatic clang-tidy fix moved m_active = true into a constructor’s initializer list, so an inactive second LogEventSource believed it was active, and its destructor would have removed the first one’s message handler. The fix was mechanical and the code still compiled. Read tool-generated diffs as carefully as hand-written ones.
A second server could take over a live server’s local socket name, because QLocalServer with socket options renames its socket into place instead of failing. Qt’s documented behaviour differs once socket options are set. Test the failure modes of system resources (ports, socket names), not just the success.
sonde-bridge --wait myapp treated myapp as the value of --wait, and the documented command didn’t work. The option was declared as taking a value, and no test ran the bridge with --wait. Run documented commands exactly as written.
The bridge returned exit status 0 on a connection failure: the error came out of connectToServer() before exec() started, so QCoreApplication::exit(1) was ignored. It looked right when read. Check what happens when a failure is reported synchronously, before the event loop runs.
A message with an id but no method got no reply at all. The “is this a request” helper also required method. Every message that needs an answer gets one, including invalid ones.
A window closing during the settle delay crashed the reply code, which dereferenced the window afterwards. The normal path never closes windows. Ask “what if the object is gone by now?” for every delayed lambda.
Keys sent to an inactive Qt Quick window were silently lost. Qt Widgets delivers keys to inactive windows; Qt Quick does not. Test GUI features with both Widgets and Quick.
SONDE_HTTP with an invalid host bound to nothing, because QHostAddress::setAddress() clears the address on failure. The fallback was set before parsing, and parsing overwrote it. Read the documentation of functions that “fail” for side effects.
One malicious HTTP request crashed the application: the chunk-size check out->size() + size > max overflowed for a size near LLONG_MAX, the check passed, and the allocation aborted with std::bad_alloc. The check looked like a bounds check. Never add an untrusted size to something before comparing it; compare size > max - used. Test with the largest values the format allows.
Numbers from clients (1e20, 1e300) were cast to int, qint64 or quint64 unchecked, which is undefined behaviour. In different places it silently saturated, hit a Qt debug assertion, or produced garbage. On Apple silicon the cast happens to saturate, so the tests passed. Range-check every conversion of a client-supplied double. Run the UB sanitizer.
~Server emitted sessionEnded while being destroyed: the QSignalBlocker was created one line after the transport teardown that ends sessions. A slot on a half-destroyed parent window would have run. The comment said “no signals”, and the code was nearly right. In destructors, check the order of every statement against what it promises.
listenHttp() on a busy port destroyed the working listener before finding out that the new one couldn’t start. The success path was the only one tested. Build the replacement first and swap it in only when it works.
A message with an id, a method and a result killed the application: the transports treated it as a response and passed no reply function, but handleMessage treated it as a request and called the empty std::function. Two places classified messages with two different rules, and nobody writes that message by hand. The fuzzer found it within a minute. When two pieces of code must agree on a decision, make them call the same function. Fuzz the code that reads client input.
Agents never found an application’s menu commands: object_tree skipped closed menus (hidden widgets) and said only “5 hidden subtrees omitted”, and even a className: "QAction" search skipped them. A sensible default for one purpose (hide what isn’t on screen) defeated another (find the commands). When output leaves something out, say what. A search shouldn’t apply a display filter.
model_locate couldn’t scroll a Qt Quick TableView to a row: the “Contain” value 4 is right for ListView, but TableView’s mode is a Qt::Alignment-style flag where 4 is AlignHCenter (its Contain is 0x2000). Even with the right value, the view only moved at its next polish. The test only used rows that were already visible. Look up each enum’s values per type, even when the names match. Test the case the code exists for: here, an off-screen row.
sonde start would have stopped whatever process had the old pid after a reboot, and with killpg, its whole process group. The pid file was trusted. A pid is only an identity together with the process’s start time. Never signal a process you can’t prove you started.
state_diff against “now” took “now” with a higher object limit than the snapshot, so in a big application thousands of objects looked new. Small test trees never reach the limit. When two things are compared, take both the same way. Test with data past every limit.
A review reported that long calls lost their keep-alive connection. A test showed they didn’t: a queued onReadyRead restarts the idle timer. The reviewer (an AI) reasoned from one function and missed a side effect elsewhere. Write the failing test before the fix. If it passes without the fix, the finding is wrong.
signal_watch on clicked reported every click twice: moc adds a clicked() clone for the default argument of clicked(bool), and emits both. The unit test’s signal had no default arguments; the smoke test’s real QPushButton did. Test meta-object code against real Qt classes, not only test objects. Know moc’s clones (QMetaMethod::Cloned).
sonde said “ready” when the application had failed to listen: another copy held the socket name, and the readiness probe connected to that copy. “Something answers” was taken to mean “our process answers”. When checking that a service is up, make sure it is yours: check before starting that nothing else answers, and read the service’s own errors.
A test helper wrote to a local after its scope ended: a QTcpSocket was declared before the variable its disconnected lambda set, so the socket’s destructor (which emits disconnected) ran after that variable was gone. Only the address sanitizer can see it. Declare objects whose destructors emit signals after everything their connections touch. Run the address sanitizer.
object_at in Qt Quick returned a Pane’s background instead of the button on it, and itemsAbove listed the background as above the content: both took childItems() order as paint order, but a control’s background has z -1 and is often its last child. The tests used plain Rectangles, which have no backgrounds, not QtQuick.Controls. Test Qt Quick code against Controls too. Paint order is z first, then childItems() order.
An application that builds with -Woverloaded-virtual as an error couldn’t add Sonde with FetchContent: the QML event bridge’s event signal hid QObject::event(QEvent *). Sonde was built with the compiler’s default warnings, and the application’s flags also apply to Sonde’s sources. Builds use a strict warning set as errors now. Don’t name a signal or function after a virtual of the base class.
An agent’s clicks after input_scroll did nothing: a Qt Quick Flickable keeps moving for about 500 ms after a wheel scroll, and a press on a moving Flickable only stops it. settleMs was 100 ms. The tests scrolled, then read contentY, but never pressed right after. Test input in the order an agent uses it: scroll, then click. Know which Qt views take a press for themselves.
object_tree with className found nothing in a QML window: the default depth of 8 also limited the levels walked between matches, and QML items are deeper than that. The tests’ object trees were shallow. When a filter changes what is printed, check that the limits still mean what the description says.
The QML debug client found top-level objects but no delegates on Qt 6.8, while every test passed on 6.12: Qt’s engine debug service only began listing objects from child contexts in 6.12. The tests ran only against the newest Qt on the development machine. Run the tests with the oldest supported Qt too (the Docker image has 6.8), especially for code that relies on Qt’s behaviour rather than its API.
A test that put back the original message handler at its end cut Sonde’s handler out of Qt’s chain, and the next test’s LogEventSource believed it was still installed. Each test passed alone; only the order exposed it. Restore a chain by removing what you installed, in reverse order, never by installing what was there before over it. Run tests alone and in sequence.

Writing review comments

Notes for AI reviewers

If you are an AI agent reviewing a change: