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
- Step 1: run the checks
- Step 2: understand the change
- Step 3: go through the checklist
- Problems we have actually hit
- Writing review comments
- Notes for AI reviewers
The goal of a review
A review answers three questions:
- Does it work? Does the change do what it says, including in the error cases and when things happen in an unexpected order?
- 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.
- 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:
- Read the description. What problem does it solve? Is there a test that shows the problem?
- Find the layer. Use the file map. Is
the code in the right place (where to put new code)?
In particular, nothing in
src/coremay include a QtGui, QtWidgets or QtQuick header. - Follow one request through it. For a new tool: where is it registered, what does the client send, what does the handler do, what comes back, including when the arguments are wrong. For a transport change: walk through one request and one error by hand.
- Try it. Run a demo (see developing.md) and call the changed tool. Five minutes of use often finds what reading misses.
Step 3: go through the checklist
Not every item applies to every change. Skip the ones that don’t.
Protocol and behaviour
- Every request (a message with an
id) gets exactly one response on every path: success, error, early return, and asynchronous completion. Cancelled requests get none. - Problems the model should see and correct are tool errors
(
ToolResult::error). JSON-RPC errors are for protocol problems: unknown method, unknown tool, malformed message. - HTTP status codes follow the existing pattern (400 bad request or missing session, 404 unknown session or path, 403 forbidden origin, 401 bad token, 202 for notification-only bodies).
- New MCP features are declared in the
initializecapabilities if MCP requires it, and work with every protocol version the server negotiates.
Lifetime and ownership
These are the most common source of crashes in asynchronous Qt code.
- Every lambda that runs later (timer, signal,
finishafter a wait) only uses things that are still alive by then. Look for: -thiscaptured in a connection without a context object. Preferconnect(sender, signal, contextObject, lambda), so the connection dies with the context. - Raw pointers to windows, widgets or items used after a wait. Windows can close while a tool waits. UseQPointerand check it, asinputtools.cppdoes. - References to locals captured by[&]in a lambda that outlives the function. - Asynchronous tools parent their timers to, or connect through,
call.context(), so they are cleaned up when the call ends. - Every
ToolCallis finished on every path. If a path forgets, the client gets a generic “did not produce a result” error. Correct, but unhelpful. newobjects have a clear owner: aQObjectparent, a smart pointer, orServer::addEventSource(which adopts parentless sources).- Destructors don’t emit signals or call back into half-destroyed objects
(see
~Serverand~HttpTransport).
Threads
- All server, transport, registry and GUI code runs on the server’s thread.
If a change does work on another thread, it sends results back with
QMetaObject::invokeMethodrather than touching server state directly. - No blocking calls on the server thread:
waitForReadyRead,waitForConnected(except the existing 200 ms probe inLocalTransport::listen),QThread::sleep, long loops. They freeze the application. - No nested event loops (
QEventLoop::exec,processEvents) inside handlers. They let other requests run in the middle of this one. Use an asynchronous tool and a timer instead. - Nothing new is called from inside the Qt message handler except queueing an event (rule 3 in architecture.md).
Security
- Default listening addresses stay on localhost. The Origin check and local socket permissions are not weakened.
- Client-supplied ids are resolved with
ObjectTree::find(), never cast to pointers. - Input sizes are bounded: request bodies, line lengths, counts (
limit,maxNodes,repeat), timeouts. A client must not be able to make the server allocate without limit or wait forever. New per-client state (sessions, connections, queued calls, buffers) is covered by aServerLimitsfield, and the limit has a test intest_limits.cpp. - Secrets are compared with
Http::bearerTokenMatches(constant time), not==. - A change of design (architecture, public API, threads or processes) has a design document, or updates one: its status, “Implemented in” and implementation notes, including what changed while implementing it.
- Data that crosses threads goes through
HomeLink::run()(or is an atomic or behind a mutex), and the change was run under ThreadSanitizer. Code that changes a registry callspublishCatalog(). - A change to a
GuiIntegrationhook (model,cellGeometry,layoutInfo, …) covers both Qt Widgets and Qt Quick, or says why not, and is tested with both. A hook returnsnotHandled()only for objects that aren’t its own, and afailure()that says why for its own that it can’t answer for. - New tools that change application state, or touch the file system or
network, say so in their description and annotations
(
readOnlyHint: trueonly for tools that really change nothing;destructiveHintfor tools that delete or overwrite). Tools that read or write arbitrary files, start processes or evaluate code need a strong reason and a discussion. - No secrets (tokens, user data) written to the log, because the log is
readable through
event_read. - Nothing makes the debug tools easier to enable by accident in a release
build, and release.md still matches the code. For
example, a new default must not start a listener, and a new built-in
tool must not be registered by
Coreon its own.
Qt and build compatibility
- Only Qt 6.8 APIs. Check the “since Qt 6.x” note in the Qt docs for any function you don’t recognise. Nothing here is built against 6.8 in CI, so the reviewer is the check.
- No private Qt headers (
<QtGui/private/...>). The one exception is the documented use ofqt_handleMouseEvent/qt_handleKeyEventininputtools.cpp. - C++17 only. For example, designated initializers (
{.name = ...}) are C++20 and not allowed. - New source files are listed in the target’s
CMakeLists.txt, and headers withQ_OBJECTare listed too, so moc runs on them. - Core still links only
Qt6::CoreandQt6::Network. - The build has no new warnings, and no new
-Wno-...or#pragmathat turns one off. Applications that add Sonde with FetchContent compile its sources with their own flags, often with warnings as errors (see developing.md, “Warnings”).
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.
- The name is
snake_caseand fits the existing families (object_*,mouse_*,events_*). - The description says what the tool does, what it returns, the units and coordinate system, the defaults, and the main limitations.
- The schema has a
typeand adescriptionfor every property, arequiredlist, and anenumwhere there is a fixed set of values. - Error messages help the caller recover: say what was wrong and what
would work.
findWindow()lists the visible windows, for example. - Output is bounded and says when it was truncated. See
object_tree’smaxNodesandevent_read’s “more available” note. - Results that confirm an action say what actually happened (what was clicked, what has focus now), not just “ok”.
Tests
- New behaviour has tests, including the error paths.
- A bug fix comes with a test that fails without the fix.
- Tests wait with
waitUntil, not fixed sleeps; useuniqueName()for sockets; don’t depend on the order tests run in; and reset any process-wide state they change (see developing.md, “Tips and traps”). - Assertions check the real outcome (the property changed, the slot ran), not just that a tool returned without error.
Code quality and documentation
- Each
NOLINTnames the check and gives a reason. Changes to.clang-tidyare justified in its header comment. - Doc comments are true and useful. “Returns the name” on
name()is fine; a comment that describes old behaviour is a bug. Check the comments on any function whose behaviour changed. - The code follows the surrounding style:
QStringLiteralfor literals,m_for members of classes with private data, adpointer for public classes, west const (const auto *x). - Guides in
notes/and the README are updated when behaviour they describe changes: tool tables, options, environment variables, commands.
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
- Say how serious each comment is:
- Blocking: a bug, a crash, a security problem, a broken rule from architecture.md, or a missing test for new behaviour.
- Should fix: unclear code, a misleading comment, a weak error message, a missing doc update.
- Nit: style or naming. Optional, and best kept few.
- Be concrete. Point at the line, describe the scenario (“if the window
closes during
settleMs, line 230 dereferences a null pointer”), and suggest a fix if you have one. - Verify before you claim. If you think something crashes, try it, or write the test that shows it. A comment that turns out to be wrong costs the author time.
- Separate what is wrong from what you would have done differently. Only the first needs to change.
Notes for AI reviewers
If you are an AI agent reviewing a change:
- Read architecture.md before the diff. The rules section and the “Problems we have actually hit” table above are the most useful context.
- Run the commands in Step 1 yourself and quote the actual output. Don’t assume a check passes.
- For each changed function, read the whole function and its callers, not just the changed lines. Most lifetime and threading bugs are only visible in context.
- Report only problems you can explain with a concrete scenario. Mark anything you could not verify as unverified, rather than presenting it as fact.
- Use the severity labels above, and lead with blocking issues.