Skip to content

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

Merged
pedrofrxncx merged 3 commits into
mainfrom
fix/sandbox-dep-metrics-chunked
Jul 2, 2026
Merged

pedrofrxncx merged 3 commits into
mainfrom
fix/sandbox-dep-metrics-chunked

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem — both prior formats are destroyed by the log pipeline (observed in prod)

  1. feat(sandbox): telemetry on installed deps per sandbox install #4269 (one array line): truncated at exactly 16KB → unparseable JSON → VictoriaLogs extracts nothing. A 391-dep install's line was cut mid-array.
  2. fix(sandbox): emit one log line per installed dep, not a 16KB array #4271 (one line per dep): ~350 lines burst per install → the collector's rate sampler drops ~99% (survivors arrive tagged sample_rate=100). Real installs surfaced as 2-4 random transitive deps — noise, not a ranking.

Fix — chunked lines that dodge both walls

Emit msg: "sandbox.deps" lines of ~200 name@version strings each (~7KB → under truncation; 1-3 lines/install → under the burst sampler), each carrying chunk/chunks/dependencyCount + install context. The deps field is a pre-JSON-encoded string, not a real array, so no pipeline stage can flatten or re-shape it.

Verified against live infra, not theory

Inserted a probe line in this exact format into the VictoriaLogs datasource and ran the panel query:

_msg:~"sandbox.deps" | unpack_json | unroll (deps) | deps:!"" | stats by (deps) count() installs | sort by (installs desc)

→ returns one row per package ([email protected], [email protected], [email protected]). The Grafana panel is wired to this query and will populate as sandboxes install after this rolls (image release + deco-apps-cd bump are automatic since #4272).

Testing

  • New pure unit tests for the chunking (buildDepLines): 391 deps → 2 lines, each <16KB, all deps present exactly once, parseable; zero-dep install still emits 1 countable line.
  • bun test daemon/setup/dep-metrics.test.ts: 4 pass. bun run fmt clean; no new type errors.

🤖 Generated with Claude Code


Summary by cubic

Chunk dependency-install telemetry into byte-bounded JSON log lines and cap the final serialized line at 15.5KB (including deps-string escaping) to survive the log pipeline and restore reliable dependency metrics in VictoriaLogs/Grafana. Replaces the broken single-array and per-dep formats.

  • Bug Fixes
    • Emit chunked sandbox.deps lines with final bytes ≤15.5KB to avoid 16KB truncation and burst sampling; greedily pack name@version entries by Buffer.byteLength.
    • Encode the deps array as a JSON string so the pipeline can’t reshape it; VictoriaLogs can unroll it back into per-dep rows.
    • Added buildDepLines and tests for long-name deps, thousands of short deps (quote-escaping accounted), large installs, and zero-dep installs.

Written for commit 6d7d0f6. Summary will update on new commits.

Review in cubic

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.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 2, 2026 22:00

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/sandbox/daemon/setup/dep-metrics.ts">

<violation number="1" location="packages/sandbox/daemon/setup/dep-metrics.ts:88">
P2: Large installs can still emit truncation-prone lines because chunking is based on dependency count, not serialized byte length. Consider building chunks by `Buffer.byteLength(JSON.stringify(chunk))` (with a safety margin under 16KB) so every emitted line stays parseable.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@pedrofrxncx
pedrofrxncx disabled auto-merge July 2, 2026 22:03
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.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 2, 2026 22:07

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

1 issue found across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@pedrofrxncx
pedrofrxncx disabled auto-merge July 2, 2026 22:09
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.
@pedrofrxncx
pedrofrxncx merged commit 963fe3b into main Jul 2, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-dep-metrics-chunked branch July 2, 2026 22:18
decocms Bot pushed a commit that referenced this pull request Jul 2, 2026
PR: #4273 fix(sandbox): chunk dep-install log lines to survive the log pipeline
Bump type: patch

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

Deploy-Scope: both
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