feat(analysis): add deterministic preflight planning and local run reporting - #603
feat(analysis): add deterministic preflight planning and local run reporting#603KumamuKuma wants to merge 6 commits into
Conversation
8ae0357 to
499181b
Compare
499181b to
cfe12ac
Compare
cfe12ac to
499181b
Compare
|
Hi @Lum1104, could you please review this PR? It adds deterministic preflight planning and run telemetry, and all CI checks are passing. Thanks! |
thejesh23
left a comment
There was a problem hiding this comment.
This might gets tricky if someone don't want to emit any of their data especially any software company so we need to have to flag to turn it off.
For example in strix repo , Anything is sent but only send stats like token usage (all of this is explained in telemetry.md) — but can also turn this off with STRIX_TELEMTRY 0 flag
https://github.com/usestrix/strix/blob/main/strix/telemetry/README.md
|
Thanks for raising this, @thejesh23 — I agree that the word “telemetry” commonly implies remote data collection. I checked the implementation end to end. In this PR, it is local run reporting only:
I have renamed the PR to use “local run reporting” and documented the privacy and data-transmission boundary in commit e9455c9. The existing LLM-backed analysis is governed separately by the user’s host and model-provider configuration. Since this PR introduces no remote telemetry or analytics collection, I have not added an opt-out flag. If you also mean the ability to disable creation of the local report files, we can discuss that as a separate requirement. |
|
I don't quiet get this, can you provide some detail explaination? |
|
@Lum1104 Sure — here is a concrete walkthrough of what changes during a normal Before this PRAfter scanning and batching the repository, For a large repository, the user cannot easily see in advance:
The user also does not receive a durable report showing which stages and batches succeeded, failed, or were retried. After this PRThe workflow becomes: 1. Preflight planAfter scanning and batching—but before dispatching any For example, it might report: It also records source bytes, lines, languages, file categories, batch-size distribution, risks, and possible scope-reduction suggestions. The plan includes a digest derived from the current selected source. If the source changes, the digest and 2. User decisionThe user must then explicitly choose:
A non-interactive host cancels instead of automatically accepting an unreviewed expensive run. 3. Local run reportIf the user continues, It records the status and duration of stages such as scanning, batching, analysis, merging, architecture generation, review, and saving. It also records per-batch attempts, retries, failures, and the number of files actually processed. For example, if batch 7 fails once and succeeds on retry, that history remains visible in the report. If some batches still fail, the final run can be marked This report is local only; it is not uploaded or sent to an analytics service. Important boundariesThis PR does not yet implement:
The token range covers only the known Phase 2 input. It does not claim to estimate model output, reasoning, retries, later agents, cache behavior, wall time, or total USD cost. So the main purpose of this PR is not to reduce cost automatically. It makes the selected workload reviewable before file analysis begins and provides a durable, machine-readable run report that future budget enforcement, resume support, and dashboard progress views can build on. The detailed contract is documented here: |
|
The main concern is the token estimation. Agents working on graph generation is going to read relevant codebase, current PR does not count these token (while they are the largest token machine). |
|
@KumamuKuma Thanks for clarifying my concern on telemetry I'm good as long we don't do any remote data collection. As I'm travelling couldn't review the latest code but I agree with @Lum1104 on token estimation as I myself burned Approx $138 on my first run of /ua on a monorepo. |
|
I tested the preflight token range against a real Phase 2 run on Emotion-LLaMA to see whether it gives users a reliable cost signal. The estimate topped out at 296K input tokens, but actual uncached input was 637K and cached input reached 7.47M, so the current range is counting a different thing from real usage; I don’t think we should merge this as a token consumption estimate, and I’m closing this PR for now. |
Summary
This PR adds deterministic preflight planning and persistent run telemetry to
/understand. Users can review the selected workload before LLM-backed file analysis begins, then inspect a durable report covering stage progress, batch outcomes, retries, failures, and actual processed scope.Large repositories can otherwise start unexpectedly expensive analysis runs with little visibility into the selected scope or batch workload. These contracts also provide a shared foundation for future budget enforcement, checkpointing, and dashboard progress views.
Linked issue(s)
Refs #284 and #413. Related to Discussion #118.
What changed
Deterministic preflight planning
After scanning and semantic batching, but before any
file-analyzeris dispatched,/understandnow writesanalysis-plan.jsonwith:The selected-source digest is calculated from current file contents. Same-size source edits and changes between scanning and planning therefore produce a different
inputDigestandplanId.Preflight decision gate
Interactive runs require one of three decisions before file analysis begins:
Non-interactive hosts cancel rather than implicitly accepting an unreviewed expensive run. A deterministic-only option is not exposed because the production pipeline does not currently implement a complete deterministic-only analysis mode.
Persistent run telemetry
Each run writes a versioned
run-report.jsoncovering scan, batching, analysis, merge, assembled-graph review, architecture, tour, final review, and save stages.Stage and batch records retain status, timestamps, duration, attempts, retries, and bounded failure history. The report distinguishes running, interrupted, cancelled, degraded, failed, and successful outcomes.
A new run archives its predecessor and marks an unfinished predecessor as interrupted. Report updates use an exclusive lock and temporary-file plus backup-and-restore writes to preserve the previous valid report if delivery fails.
Estimate boundaries
The preflight token range covers only known Phase 2 input derived from selected source bytes and deterministic batch context. It does not include model output, reasoning, tool protocol overhead, retries, later agents, cache behavior, or provider-specific tokenization.
Wall-time and USD estimates remain unavailable until the host provides calibration data or authoritative model telemetry. Estimated tokens are stored separately from measured usage so consumers cannot mistake an estimate for actual consumption.
Workflow and benchmark compatibility
.ua/and legacy.understand-anything/analysis artifacts.Generated artifacts
The active analysis data directory now retains:
analysis-plan.jsonrun-report.jsonBoth artifacts use versioned JSON Schema Draft 2020-12 contracts. Existing projects using
.understand-anything/keep that directory, while new projects use.ua/.How I tested this
pnpm lintpnpm --filter @understand-anything/core test— 970 passedpnpm test— 513 passed, 15 skippedAdditional validation:
Versioning
2.9.4to2.9.5in all six manifests listed inCLAUDE.mdFollow-up opportunities
The new plan and report contracts provide a foundation for future work without including those features in this PR: