Skip to content

fix(sandbox): emit one log line per installed dep, not a 16KB array - #4271

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-dep-metrics-per-line
Jul 2, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-dep-metrics-per-line

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The merged dep-install telemetry (#4269) emitted the whole dependencies array in a single sandbox.install.deps JSON log line. The log pipeline truncates lines at 16KB, so a large monorepo (e.g. a 391-dep install) gets cut mid-JSON → the line is unparseable → VictoriaLogs unpack_json extracts nothing → the top-deps aggregation collapses to name="". Confirmed live: _msg length was exactly 16384 bytes.

Fix

Emit one small line per dependency (sandbox.dep.installed with name, version, + pm/repo/branch/bootId), each well under the cap, plus a trailing sandbox.install.deps summary line with install-level totals (dependencyCount). Per-line rows are also what let VictoriaLogs stats by (name) count() aggregate directly — no nested-array unroll.

Trade-off

More lines per install (one per dep, capped at the existing MAX_DEPS=10000). Tiny lines, infrequent (per sandbox boot), well within VL capacity — and the correct shape for per-package aggregation, which is the whole point.

Testing

bun test daemon/setup/dep-metrics.test.ts passes; bun run fmt clean. Dashboard panel queries updated to the per-dep line format.

🤖 Generated with Claude Code


Summary by cubic

Switch dep-install telemetry to emit one log line per installed dependency (sandbox.dep.installed: name, version, context) plus a small summary line (sandbox.install.deps: dependencyCount). This prevents 16KB log truncation and restores accurate per-package aggregation in VictoriaLogs.

Written for commit a46b67e. Summary will update on new commits.

Review in cubic

The single sandbox.install.deps line carried the whole dependencies array,
which the log pipeline truncates at 16KB — a 391-dep monorepo's line is cut
mid-JSON and becomes unparseable, so VictoriaLogs can't aggregate it (the
top-deps panel collapsed to name="").

Emit one small sandbox.dep.installed line per package (name+version+context)
so stats by (name) count() works without unrolling a nested array, plus a
trailing sandbox.install.deps summary line with the install-level totals.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 2, 2026 21:30

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 1 file

Re-trigger cubic

@pedrofrxncx
pedrofrxncx disabled auto-merge July 2, 2026 21:31
@pedrofrxncx
pedrofrxncx merged commit adc4df4 into main Jul 2, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-dep-metrics-per-line branch July 2, 2026 21:37
decocms Bot pushed a commit that referenced this pull request Jul 2, 2026
PR: #4271 fix(sandbox): emit one log line per installed dep, not a 16KB array
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.9.0 -> 1.9.1

Deploy-Scope: both
pedrofrxncx added a commit that referenced this pull request Jul 2, 2026
…#4273)

* fix(sandbox): chunk dep-install log lines to survive the log pipeline

Third and final format for the dep-install telemetry. Both prior shapes
were destroyed by the log pipeline in prod:
- one line with the whole dependencies array → truncated at 16KB →
  unparseable JSON (VictoriaLogs extracts nothing);
- one line per dep (#4271) → ~350-line burst per install → the collector's
  rate sampler drops ~99% (survivors tagged sample_rate=100), leaving
  2-4 random transitive deps per install.

Emit chunked sandbox.deps lines of ~200 name@version strings (~7KB each,
1-3 lines per install): under the truncation cap AND under the burst
sampler. The deps field is a pre-JSON-encoded string so no pipeline stage
can flatten the array; VictoriaLogs `unroll (deps)` parses it back into
per-dep rows — verified end-to-end against the live datasource with an
inserted probe line.

* fix(sandbox): chunk dep lines by serialized bytes, not dep count

Count-based chunking (200/line) doesn't bound the serialized line size:
npm names allow up to 214 chars, so a line could reach ~40KB and hit the
same 16KB truncation this format exists to avoid. Pack name@version strings
greedily by Buffer.byteLength under a 14KB cap (leaving ~2KB for the JSON
envelope). Adds a regression test with 200 long-named deps.

* fix(sandbox): budget final line bytes incl. deps-string quote escaping

The chunker sized the raw deps array, but deps is stored as a string field
so the outer JSON.stringify escapes every element's quotes ("x" -> \"x\",
+2 bytes each). Short-dep-heavy lines undercounted by ~2 bytes/dep could
cross 16KB and truncate. Budget the FINAL line: measured envelope + per-dep
escaped cost, cap 15.5KB. Adds a 4000-short-dep regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant