bumblebee icon indicating copy to clipboard operation
bumblebee copied to clipboard

Bumblebee Cli Truncation

Open ruangraung opened this issue 2 months ago • 0 comments

scan_summary reports status=complete and exit code 0 for a scan stopped by --max-duration

Summary

bumblebee scan --max-duration <d> stops walking at the deadline, emits its trailing scan_summary, and exits 0. That summary carries timed_out: true together with status: "complete".

The value partial exists in the vocabulary and is never used for this case: status starts as complete and the switch in cmd/bumblebee/main.go moves it only for a run error or a failed HTTP sink batch. TimedOut is copied into the record and printed in the diagnostic line, but is never consulted when the status is chosen.

// cmd/bumblebee/main.go, v0.1.2
exitCode := 0
status := model.ScanStatusComplete
switch {
case runErr != nil && res.RecordsEmitted > 0:
    status = model.ScanStatusPartial
    exitCode = 1
case runErr != nil:
    status = model.ScanStatusError
    exitCode = 1
}
if sinkStats.HTTPBatchesFailed > 0 && status == model.ScanStatusComplete {
    status = model.ScanStatusPartial
    exitCode = 1
}

A run stopped by its own time limit reaches none of those arms: the walk predicate returns filepath.SkipDir when the context is done, and scanner.Run sets res.TimedOut = true for context.DeadlineExceeded and then returns a nil error, so runErr stays nil.

Status on main

Re-checked against main at d76e369a0b34d6506dc249b4d573f7859cac7a19 (2026-08-07), after the v0.1.2 release:

  • cmd/bumblebee/main.go:272-287 still chooses the status without consulting res.TimedOut. The three arms are unchanged: a run error with records emitted, a run error without them, and failed HTTP sink batches.
  • res.TimedOut is set in internal/scanner/scanner.go:508-509 for context.DeadlineExceeded, and reaches only the record at cmd/bumblebee/main.go:321 and the diagnostic string at cmd/bumblebee/main.go:341.
  • No release has been published since v0.1.2 (2026-06-18), so this describes the newest published build as well as the current main.

Environment

  • bumblebee v0.1.2, commit cc57710eeaf685e7b89924a36c8583cad0a378fe, built 2026-06-18T15:03:13Z with go1.25.11, linux/amd64, from release asset bumblebee_0.1.2_linux_amd64.tar.gz
  • Scan root: one read-only source tree of about 13,000 files
  • Consumer: a GUI front end that runs the CLI as a subprocess and parses the NDJSON stream

Minimal reproduction

$ bumblebee version
bumblebee v0.1.2
commit: cc57710eeaf685e7b89924a36c8583cad0a378fe
built:  2026-06-18T15:03:13Z
go:     go1.25.11

$ bumblebee scan --root /path/to/tree > full.ndjson 2> full.err; echo "exit=$?"
exit=0
$ bumblebee scan --root /path/to/tree --max-duration 50ms > cap50.ndjson 2> cap50.err; echo "exit=$?"
exit=0
$ bumblebee scan --root /path/to/tree --max-duration 1ms > cap1ms.ndjson 2> cap1ms.err; echo "exit=$?"
exit=0

echo "exit=$?" reports the CLI's own exit status. All three runs exit 0. Fields of the trailing scan_summary record of each run, parsed from the NDJSON:

invocation exit status timed_out files_considered package records duration_ms
no --max-duration 0 complete false 13374 780 228
--max-duration 50ms 0 complete true 5240 285 52
--max-duration 1ms 0 complete true 54 0 3

The message field of the info diagnostic written to stderr by the 50ms run, verbatim:

scan complete: profile=baseline status=complete files_considered=5240 records=285 findings=0 suppressed=0 duplicates=2 diagnostics=0 timed_out=true duration=52.387816ms

The summary states both things at once: status=complete and timed_out=true.

Why it matters to a consumer

docs/state-model.md states "Only promote records from a run after receiving a matching scan_summary with status=complete" and "A run is promotable only when status='complete'", and defines inventory_current as the latest complete run for each (endpoint_id, profile). A truncated run that arrives marked complete is promoted, so packages the walk never reached are indistinguishable from packages that are not installed there, and the truncated snapshot can replace a fuller earlier one. The same applies to findings_emitted: 0 on a truncated run. A consumer that checks only the exit code sees nothing at all.

docs/state-model.md does list "timeout" among the conditions a receiver should treat as raw evidence only, so the intent is documented. The emitted record does not express that intent through status or through the exit code: the machine-readable signal is timed_out, which carries no description in the schema and is not mentioned in the --max-duration help text ("max wall-clock duration for the whole scan (0 = unbounded)").

Note that docs/transport.md defines the value as "partial: the run emitted some records but also hit a terminal scan error", so a timed-out run does not qualify under that wording. Emitting partial for a timeout therefore wants that definition widened at the same time.

Suggested changes

  1. Set status to partial when TimedOut is true, so the value matches the meaning the schema enum and the promotion rule already give it. timed_out can stay for detail, and the exit code can stay 0. docs/schema/v0.2.0/scan-summary.schema.json carries the same enum, so the change holds for the next version too.
  2. Document the field. If exit code 0 and status=complete for a timed-out run are intended, say so where the time limit is described: in the --max-duration help text, in the status and timed_out properties of docs/schema/v0.1.0/scan-summary.schema.json (neither carries a description today), and in the promotion rule in docs/state-model.md, with the explicit instruction that receivers must check timed_out before treating a snapshot as complete.

If complete is meant to describe how the process ended rather than how much of the tree was covered, then item 1 is not wanted and this report reduces to the documentation request in item 2.

ruangraung avatar Sep 22 '26 14:09 ruangraung