Skip to content

[TENT] Add diagnostic core and version CLI - #4154

Merged
alogfans merged 10 commits into
kvcache-ai:mainfrom
0z5a:tent-diagnostic-core
Oct 21, 2026
Merged

alogfans merged 10 commits into
kvcache-ai:mainfrom
0z5a:tent-diagnostic-core

Conversation

@0z5a

@0z5a 0z5a commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Incremental review: Files changed against main.

Description

Implements the first diagnostic-core milestone proposed in #2864:

  • add the versioned DiagnosticSnapshot, check, evidence, and section model
  • provide stable text and JSON renderers with PASS/WARN/FAIL/SKIP outcomes
  • add field-aware redaction primitives, including strict per-snapshot pseudonyms and unconditional exclusion of secrets, rkeys, lkeys, and raw addresses
  • add the offline-only tent version command with build metadata and feature flags
  • add schema, renderer, redaction, exit-code, unavailable-data, and version tests

The CLI links only the diagnostic core and does not initialize transports, metadata clients, devices, or remote connections.

Part of #2864.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Test commands:

cmake --build build-tent-diagnostics-root --target tent_cli tent_diagnostic_test -j 16
ctest --test-dir build-tent-diagnostics-root -R '^tent_diagnostic_test$' --output-on-failure
./build-tent-diagnostics-root/mooncake-transfer-engine/tent/cli/tent version
./build-tent-diagnostics-root/mooncake-transfer-engine/tent/cli/tent version --json
ldd ./build-tent-diagnostics-root/mooncake-transfer-engine/tent/cli/tent

Test results:

  • Unit tests pass
  • Integration tests pass (not applicable)
  • Manual testing done: verified text and JSON output, invalid-command exit code 2, embedded commit metadata, and no transport/runtime dynamic dependencies

The full pre-commit runner could not bootstrap its GitHub-hosted hook repositories because the test host's TLS connection was interrupted. Equivalent local checks passed with clang-format 20.1.8, cmake-format 0.6.13, codespell 2.2.6, git diff --check, conflict-marker checks, and added-large-file checks.

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh (equivalent clang-format 20.1.8 check passed)
  • I have run pre-commit on the files changed in this PR and all hooks pass (hook bootstrap was blocked by the network issue described above)
  • I have updated the documentation (not applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue ([RFC]: TENT Operator CLI and Sanitized Diagnostic Bundle #2864)

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used

AI assistance was used for implementation and test support. The submitter is responsible for reviewing and defending the changes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We expect diagnositics as a subfunction so that cli can be extended in the future.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Perhaps a tent binary test should be included as well.

@0z5a

0z5a commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, @alogfans. I have updated the CLI to expose diagnostics as a subcommand and added a test for the tent binary, as suggested. Please take another look.

@0z5a
0z5a requested a review from alogfans September 17, 2026 03:42

@hongzhi-gao hongzhi-gao 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.

Two focused correctness concerns on the current head.

#include <unordered_map>
#include <vector>

#include "tent/thirdparty/nlohmann/json.h"

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.

This is installed as a public header, but the install rules do not install tent/thirdparty/nlohmann/json.h. A consumer using the installed tent_diagnostics archive will fail at preprocessing when it includes tent/diagnostics/diagnostic.h. Please install the bundled JSON header (or keep JSON out of the installed API), and ideally compile a tiny consumer against the install tree.

for (const auto& check : snapshot.checks) {
nlohmann::json serialized{{"id", check.id},
{"outcome", toString(check.outcome)},
{"summary", check.summary},

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.

Only DiagnosticEvidence.observed passes through Redactor; summary and remediation here, plus source/field in evidenceToJson(), are emitted verbatim in JSON and text. A collector that puts a peer URI, path, credential-bearing error, or other dynamic detail in one of these fields will leak it even in strict mode. Since the diagnostic output is intended to be shareable, please make these fields fixed text/IDs or add a way to sanitize their dynamic content before rendering.

@0z5a
0z5a force-pushed the tent-diagnostic-core branch from 34adc93 to d34bb13 Compare September 24, 2026 01:17

@alogfans alogfans left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

} // namespace

int main(int argc, char** argv) {
if (argc == 2 && std::string_view(argv[1]) == "--help") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is mature args lib out there, if this cli app isn't a oneshot code and need to be maintained for a long time, prefer using lib like https://github.com/jarro2783/cxxopts, https://github.com/CLIUtils/CLI11

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I switched the diagnostics CLI to CLI11 and kept the existing commands and exit codes. The CLI tests pass.

@@ -0,0 +1,72 @@
# Exercise the built CLI, including dispatch, output streams and exit codes.
if(NOT DEFINED TENT_CLI OR NOT EXISTS "${TENT_CLI}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why cli test is a cmake file? Normally we use bash python or something easy to review.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I replaced the CMake test script with a Python CLI test, still run through CTest. All 11 cases pass.

Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
@0z5a
0z5a force-pushed the tent-diagnostic-core branch from 896a300 to 042b7ce Compare September 24, 2026 05:57
@Aionw

Aionw commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Please using cmake to manage CLI11 dependencies, not copy itself as a single header into codebase.

@xiaodouzi666

Copy link
Copy Markdown
Contributor

Hi @0z5a, thanks for this PR — we are building the later diagnostics commands of #2864 on top of it. To help it land, here are ready-made changes for the three review points, as five patches on top of your branch (authorship of your five commits unchanged):

  1. CLI11 through CMake (@Aionw's point): mooncake_provide_cli11() in cmake/Dependencies.cmake, following the file's existing provider pattern — it finds CLI/CLI.hpp (system package or CLI11_DIR/MOONCAKE_CLI11_INCLUDE_DIR) and exposes Mooncake::cli11; called from the top level and from the standalone TENT entry; libcli11-dev / cli11-devel added to dependencies.sh; extern/cli11/ and the extern exclusions in .typos.toml / scripts/code_format.sh removed. Built and tested against CLI11 2.1.2 (what libcli11-dev on ubuntu-22.04, i.e. CI, ships), 2.5.0 and 2.7.2 without code changes.
  2. Installed header and its JSON dependency (@hongzhi-gao's first point): include/tent/thirdparty/nlohmann/json.h is installed next to diagnostic.h, so a program that includes only the installed header compiles.
  3. Free text through the redactor (@hongzhi-gao's second point): Redactor::sanitizeText() redacts credentials in every mode and, in strict mode, replaces the values already pseudonymized in fields and any IP/GID/MAC-shaped token with the same pseudonyms; summary, remediation, source and field go through it, with tests.

Two small extras in the same series, which the later commands rely on but which stand on their own: renderText prints the evidence of checks that did not pass (otherwise the device or link that failed is only in the JSON), and diagnosticExitCode tells a collector failure (3) and an internal error (4) apart from check failures, as the RFC specifies.

Branch: https://github.com/xiaodouzi666/Mooncake/tree/pr/4154-assist — current main + your five commits (cherry-picked, authorship unchanged) + the five patches as its last five commits; just the series: xiaodouzi666/Mooncake@58745ba...202e640. git format-patch -5 202e640145 gives the patches; they apply cleanly with git am on your head (042b7ce) and on main + your head. Happy to adjust anything, or to open a PR against your branch if that is easier for you.

xiaodouzi666 added 5 commits October 14, 2026 22:56
Drop the copied single header under extern/cli11 and resolve CLI11 like
the other system dependencies: mooncake_provide_cli11() looks up
CLI/CLI.hpp and exposes it as Mooncake::cli11. Builds with TENT enabled
call the provider from the top-level and the standalone TENT entry
points, and dependencies.sh installs libcli11-dev (cli11-devel where the
distribution packages it).

The spelling and format exclusions that only existed for the vendored
header are removed again.
include/tent/CMakeLists.txt is not added by any build entry point, so
the install rule placed there never ran and diagnostic.h was not
installed. Install the header from the diagnostics library directory
instead, together with tent/thirdparty/nlohmann/json.h, which the public
header includes.
Redactor::sanitize() replaces whole field values, which does not help
for log lines and error messages copied into a report. Add
Redactor::sanitizeText():

- credential assignments (password, token, secret, ...), URL user
  information, authorization values, rkey/lkey values and raw addresses
  are replaced in every mode;
- in strict mode, deployment strings already passed to sanitize() and
  any remaining IPv4, IPv6, GID, MAC or node GUID token are replaced by
  the same pseudonyms sanitize() hands out, so a value keeps one name
  across fields and text.

Each replacement counts towards fields_redacted.
The text renderer printed check evidence only in JSON, so the node,
device or link a warning or failure refers to was not visible in the
human-readable report. Print the evidence lines of every check that did
not pass, between the check line and its remediation.
diagnosticExitCode() only returned 0 or 1. Report a failed collector
check (the collector process crashed or timed out, or could not be
found) as 3 and a failed internal check as 4, so scripts can tell an
unhealthy deployment from a diagnostic run that could not complete.
Precedence is 4 over 3 over 1 over 0; 2 stays with the argument parser.
@0z5a

0z5a commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @xiaodouzi666, this is very helpful. I applied the five patches on top of the branch with authorship kept (15389d7, 78ebffd, a41bfde, b0d3ed0, 3fb90c0), so the PR now includes them.

Checked locally on macOS with clang 21: the diagnostic unit tests pass (15/15). I haven't checked the CMake path or the CLI tests with CLI11 installed yet.

One small mismatch: the comment describes CLI11_DIR as a lookup override, but mooncake_provide_cli11() uses find_path and the cache variable MOONCAKE_CLI11_INCLUDE_DIR, and doesn't read CLI11_DIR. Would you prefer the CMake to honor CLI11_DIR, or should the note be corrected? Happy to collaborate on the next pieces for #2864.

@alogfans

Copy link
Copy Markdown
Collaborator

@xiaodouzi666 If you think this patch is mergeable, pls tell me.

@xiaodouzi666

xiaodouzi666 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

@alogfans Yes, I think it's mergeable rn.

@xiaodouzi666

xiaodouzi666 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

@0z5a sorry that was a description error, plz keep the code as it is and correct the note, thx

@alogfans
alogfans merged commit 7540f58 into kvcache-ai:main Oct 21, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants