Skip to content

feat(diagnostics): add time-limited tracing and explicit exports - #590

Merged
nixuuu merged 4 commits into
feat/diagnostics-5-logsfrom
feat/diagnostics-6-tracing
Nov 13, 2026
Merged

nixuuu merged 4 commits into
feat/diagnostics-5-logsfrom
feat/diagnostics-6-tracing

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

One diagnostics session can now collect short, explicitly requested traces on one computer's gateway or one connected worker. Owners can start a 1/5/10-minute session, stop it and export its samples from web, desktop and mobile. The default is five minutes; tracing never starts through overview polling or log collection.

Stage 6 slow-reader cost occurs while explicitly requested tracing is active. In B, benchTracing() starts gateway tracing before every phase, including slow_reader, exports its samples and stops it afterward. A leaves tracing inactive; stages 1–5 are enabled on both sides. All four B slow-reader runs exported 616 samples each with zero drops. The maintainer accepts the measured cost for this opt-in mode (at most 10 minutes): +0.562 ms p95 (+15.242%), +21.322 MiB RSS / +18.900 MiB heap; without flagged pair 4, +0.581 ms, +20.668 / +19.489 MiB. These are active-session working-set observations, not the tracing-off cost. Four accepted / zero rejected pairs, zero scope swap throughout; CPU medians are at most +0.148 pp. Full results remain below.

Stop, GC and export-retention evidence — 2026-11-13

Ran only the requested focused slow-reader A/B: bash scripts/bench/diagnostics-retention.sh 6 slow_reader end, immutable head 0d058ff70d1dec3791c2c697c155de56d9bb2c5a. It reuses fresh state, seeded history, periodic detail views and the 90-second workload. B exported 615 samples with zero drops and stopped before the heap checkpoint. Both scope swap values remained zero; the focused pair passed load/swap-in gates. No full overhead recording was repeated.

After stop and two full GCs, gateway heap was A 75.267 MiB / B 76.722 MiB, B−A +1.455 MiB. Before GC it was A 94.439 / B 84.507 MiB. The earlier roughly +19 MiB endpoint difference is therefore not retained after collection in this focused workload. Persistence had zero pending minutes/bytes on both sides. The snapshot diff shows one extra Float64Array (144,048 bytes, the bounded 2,000-span ring), +0.938 MiB ArrayBuffer self bytes with unchanged object count, and +0.440 MiB function-code self bytes. These are root-reachable self-size deltas, not dominator retained sizes; snapshot graphs and sanitized retainer paths are private evidence.

Stop immediately disables recording; it deliberately preserves the 141 KiB numeric ring for up to ten minutes so the owner can still export the finished trace. Temporary export DTOs are not cached. The purge timer then clears the ring and session state; worker stop also detaches its governor observer, and close/disconnect clears everything. This is bounded post-stop export retention, not an immediate-zero-memory claim.

Added an isolated lifecycle regression: 12 consecutive saturated rings and protobuf exports, two full GCs after every stop and TTL expiry. Heap after GC: warm baseline 6.906 MiB, final stopped 6.986 MiB (+0.079 MiB), final purged 6.848 MiB (−0.058 MiB). Every sample stayed within 2 MiB of baseline; no accumulation across cycles, and the old lease becomes unexportable after expiry. The existing gRPC/WorkerLink tests also verify explicit stop, expiry, detached worker observation and restart. No production tracing/instrumentation change was needed.

Evidence: /var/tmp/canopy-diagnostics-6/retention-stop/run/end/ (post-gc.json, A/B snapshots, retention-diff.json, raw events), and /var/tmp/canopy-diagnostics-6/final-trace-memory-test.log; not committed.

  • One ephemeral lease per computer, fenced stop/export, monotonic expiry and no restoration after restart. Worker disconnect clears its ring and observer. Direct linked homes support explicit actions; onward tracing is denied. Existing owner authentication and direct-peer export permission apply.
  • Sample less than 1% of fixed RPC/DB/pool/ingest/governor operations, at most 100 samples/s and 2,000 spans. The numeric ring allocates 141 KiB on explicit start, within the separate 4 MiB tracing ceiling, and is purged within ten minutes after stop/expiry. Inactive recording uses no clocks or allocations. Export DTOs are temporary and never cached. Ordinary snapshots contain session metadata only; peer persistence omits it.
  • No payload, SQL, parameters, error objects/messages/stacks or arbitrary labels enter the ring. Names are projected from local descriptors/family definitions at export. Remote unknown protobuf fields and supplied names are discarded. Start, stop, expiry, cancellation and export have separate scalar audit events; coordinator/home actions share the lease ID.
  • Additive protobuf messages, WorkerLink frame 852 and diagnostics_trace_v1; generated contracts included. No migration, protocol bump, frozen update/v1 edit or native dependency.

Parent stages 4 (#569) and 5 (#572) were accepted for CPU, p95 and memory by the maintainer on 2026-11-12. Their existing four-pair A/B results are preserved. Additional governor memory investigation/tests and A/A recordings were stopped as requested. Stack #506 will be marked ready after all seven current-head CI runs are green; the maintainer merges the entire stack together.

Verification

Focused tracing integration covers actual gRPC + WorkerLink start/stop/export, independent homes, authentication, foreign workers, stale leases, expiry and gateway restart. It verifies the sample/rate/ring caps, real failed parameterised SQL, malicious worker names/unknown fields and scalar audit records. Run one file at a time. Existing diagnostics and log integrations also protect the shared collectors, snapshots, capability negotiation and log pipeline.

Passed: bun install, bun run gen:check, bun run typecheck, bun run lint, bun run format:check, the web production build, git diff --check and shell syntax validation of the stage-6 bench script. Focused check:tmp runs, one file at a time: tracing (4 tests, 64 assertions), diagnostics (7 tests, 50 assertions) and logs (4 tests, 138 assertions); all passed with clean temporary directories.

Local evidence is under /var/tmp/canopy-diagnostics-6/ (not committed). A full local integration suite was not run; focused check:tmp runs verify cleanup, and CI runs the repository suite.

After the QA fixes and restack, repeated install, gen:check, full typecheck, lint, format:check and web build successfully. Focused files ran individually: report adapter 3 tests / 9 assertions, log export security 8 / 50, and the previously authorized gRPC log integration 4 / 138. All passed with clean temporary directories. Both pinned mobile fingerprint commands were rerun and preserved the hashes below. The final stack rebase uses dev 968757a4c, including #579's avatar-cache fix and the newly merged citation contracts. It reuses #574's additional_capabilities field/shared handshake implementation rather than duplicating field 8. Migrations remain 0129/0130/0131.

Post-rebase local checks passed: gen:check, full typecheck (including mobile and Svelte), lint, format:check, shard manifest, web production build and diff checks. Focused files passed individually through check:tmp: tracing 4 / 64, trace memory 1 / 27, logs 4 / 138, client diagnostics 8 / 66, diagnostics 7 / 50, production legacy capability compatibility 3 / 34, log-source/archive security 3 / 16, and GitHub avatar cache 9 / 39. Controlled temporary directories are clean; forensic scopes/listeners have stopped. The final current-head CI workflows are running; PRs stay draft until all seven are green, then will be marked ready together as requested.

Mobile stays JS-only. Pinned bunx [email protected] fingerprint:generate --platform <ios|android> --build-profile production --json --non-interactive preserves iOS 6ddec9ef559ee0095ac33e94ff9418a942053b17 and Android 5f6eae3ab278f1cd543e9ed763f923a319b65ec9. Trace export uses the existing iOS Share and Android directory picker. Browser QA is complete below; native device interactions were not exercised by that run.

Measurement protocol — completed

bash scripts/bench/diagnostics-stage6.sh — about 100–110 minutes, longer after rejected pairs. Four fresh AB/BA/AB/BA pairs on the same revision, with stages 1–5 enabled on both sides. A leaves tracing inactive; B explicitly starts tracing on the gateway, then on the worker in its own phase. Idle (3 min), steady, slow receiver, governor, gateway tracing with log export, and worker tracing with log export (90 s each); existing synthetic sync, journal/ACK, deterministic harness/git and RPC traffic continue. Each B phase exports and checks samples, then stops its lease.

The recording used swap-disabled user scopes for gateway, worker and bench PostgreSQL. Every sample had zero scope swap; load and sustained swap-in gates passed. Host swap-out was recorded without rejecting solely for it. Pair 4 met the joint 2×MAD/high-swap-out rule and remains in primary medians; sensitivity excludes it. updatedb ran for 40 s during A's governor phase (PID 2103822); the pair's host swap-out was 214.195 MiB, peak 111.262 MiB/s. No tests or builds ran on the measured server during recording; manual QA/checks ran on the second machine. No additional A/A controls were recorded, as instructed. Recording and all owned processes are finished; the benchmark ports are free.

Copy audit — docs/copy.md §8

Before: no tracing action or feedback. After: “Start deeper tracing”, “Stop tracing”, “Export samples”, one short privacy sentence, explicit expiry/off/unsupported states and an error with a retry action. The longer Start label is the accepted spec wording. Controls reuse the settings kit, compact density, semantic colours, reduced-motion support and minimum touch targets; no new custom animation or native control. Numbers/times and off/unsupported status are textual. Long worker names use the existing Select/SettingChoice truncation. No new metaphor or glossary synonym. Desktop/narrow/phone light/dark interactions and long-name layouts were checked without page-wide horizontal overflow.

Whole-stack browser QA

Reviewed linked overview, gateway/DB/governor, worker resources and queues, client delivery, Markdown/JSON report preview and placement selection, log collection/download and deeper tracing on a disposable seeded stack. Light/dark at 1440×1000, 768×1024 and 390×844; long names, offline/unsupported homes and empty/loading/read-error/Retry states. Gateway start/stop worked for 1/5/10 minutes; actual one-minute automatic expiry exported 91 samples. Worker start/stop/export worked through the fixture WorkerLink; that brief idle UI session had no worker samples, while integration and the acceptance bench exercise active work. Trace action failure recovered on retry. No uncaught errors in valid flows.

Fixed two findings in their owning stages: semantic DB disclosure borders and shared short RPC histogram copy (#535), plus actual startup/link log template recognition with a security regression test (#572). Interrupted final screenshots/static checks were repeated after the QA machine reboot. Browser, fixture processes and its named container were stopped; allocated ports were verified free and the disposable checkout cleaned. Evidence: /var/tmp/canopy-diagnostics-6/qa/qa-report.md and adjacent screenshots/check logs, not committed.

Limitations: synthetic linked/worker data, no native device interaction, and no real investigation thread was created because the fixture advertised no available model. Project/workspace selection and the disabled unavailable-model state were checked. Focused integration provides ownership, tracing-capability and cross-home protocol evidence.

Stage 6 measurement — 2026-11-12/13

Measured immutable head: 3182e35547152f36d42a75fc918ed40e60df0d69. Four accepted / zero rejected pairs, first attempt each, strict AB / BA / AB / BA. A=tracing inactive, B=explicit tracing; stages 1–5 enabled on both. Every member used a fresh driver, PostgreSQL cluster/database/WAL and gateway/worker state. Initial counts matched (500 threads, 1,000 turns, 7,099 items, 840 rollups).

Every scope sample had MemorySwapMax=0 and memory.swap.current=0. Load and sustained swap-in gates passed. No foreign tests/builds were observed. Host swap-out is log-only under the agreed protocol.

Pair 4 is flagged by the joint >2×MAD and >4 MiB/s host swap-out rule, and remains in the primary medians. updatedb PID 2103822 (/usr/bin/updatedb --prune-bind-mounts=no --add-prunepaths=/.snapshots) ran 00:14:56–00:15:36 CET during A's governor phase. Pair 4 peak host swap-out was 111.262 MiB/s, total 214.195 MiB. Scope swap remained zero and load peaked at 2.03 in that member. The job finished before the recording ended; no pair was retried. Kernel kswapd/zram counters were logged; kernel affinity could not be changed. Gateway/worker/PostgreSQL were pinned to CPUs 2/3/4.

CPU values are percentage points of one core. RSS/heap are endpoint MiB without forced GC. Percent deltas are paired percent changes, not a ratio of medians. These results are reported for maintainer acceptance; the repeatable slow-receiver memory increase is not attributed solely to updatedb or labelled as accepted noise.

Gateway — primary n=4

Phase CPU pp p95 ms p95 % RSS MiB Heap MiB
idle -0.006 — — 0.713 0.106
steady 0.148 0.108 3.248 0.213 0.976
slow_reader -0.07 0.562 15.242 21.322 18.9
governor -0.006 0.147 5.519 -7.998 -11.524
log_export 0.067 0.055 3.744 8.502 8.282
trace_worker -0.032 0.154 5.415 3.58 1.564

Gateway — sensitivity excluding flagged pair 4, n=3

Phase CPU pp p95 ms p95 % RSS MiB Heap MiB
idle 0 — — 0.742 0.059
steady 0.107 0.273 8.148 -0.133 0.716
slow_reader 0.011 0.581 16.144 20.668 19.489
governor 0.044 0.236 8.947 -13.77 -14.327
log_export 0.135 0.389 15.517 14.098 10.387
trace_worker 0.012 0.335 11.765 2.586 0.437

Worker and process totals

Total CPU sums the measured gateway, worker and PostgreSQL processes; it excludes the driver.

Phase Worker CPU pp n4 / n3 Worker RSS MiB n4 / n3 Worker heap MiB n4 / n3 PostgreSQL CPU pp n4 / n3 Total CPU pp n4 / n3
idle -0.004 / -0.009 0.115 / 0.113 -0.003 / -0.003 -0.004 / -0.008 -0.014 / -0.017
steady -0.002 / -0.003 0.426 / 0 0.258 / 0.204 0.052 / 0.02 0.195 / 0.119
slow_reader -0.001 / 0.003 -0.041 / 0.301 -0.405 / -0.499 0.055 / -0.008 -0.023 / -0.008
governor -0.013 / -0.009 0.064 / 0.168 -0.244 / -0.187 -0.081 / -0.066 -0.034 / 0.082
log_export -0.024 / -0.012 -0.043 / 0.066 -1.354 / -0.859 -0.064 / -0.058 0.033 / 0.111
trace_worker -0.052 / -0.032 -1.33 / -0.078 -0.858 / -0.06 -0.083 / -0.073 -0.139 / -0.056

Host results

Pair Order Result Host swap-out MiB Peak MiB/s
1 AB Accepted 0 0
2 BA Accepted 0 0
3 AB Accepted 0 0
4 BA Accepted, sensitivity flag 214.195 111.262

Per-pair deltas

Each cell lists pairs 1 / 2 / 3 / 4, including the flagged pair. Full raw deltas and every flag are in paired-report.json.

Phase Metric Pair 1 Pair 2 Pair 3 Pair 4
idle gateway.cpuPp 0 -0.044 0.016 -0.012
idle worker.cpuPp -0.009 -0.04 0.007 0.001
idle postgres.cpuPp -0.008 0.01 -0.013 0
idle total.cpuPp -0.017 -0.074 0.01 -0.012
idle gateway.rssMiB 1.742 0.742 0.453 0.684
idle gateway.heapMiB 0.059 0.433 -0.134 0.154
idle worker.rssMiB -0.246 0.117 0.113 0.391
idle worker.heapMiB -0.004 -0.003 0.001 -0.008
steady gateway.cpuPp 0.107 0.361 -0.164 0.189
steady worker.cpuPp -0.009 -0.003 -0.001 -0.002
steady postgres.cpuPp 0.02 0.015 0.085 0.084
steady total.cpuPp 0.119 0.373 -0.08 0.271
steady gateway.rssMiB -0.133 1.047 -18.813 0.559
steady gateway.heapMiB 1.411 0.443 0.716 1.236
steady worker.rssMiB -0.02 0.852 0 0.949
steady worker.heapMiB 0.204 -0.196 0.312 0.729
steady rpc.p95Ms 0.294 0.273 -0.596 -0.058
steady rpc.p95Percent 9.376 8.148 -16.475 -1.653
steady history.p95Ms 8.931 -3.046 -6.787 -3.789
slow_reader gateway.cpuPp 0.011 0.504 -0.331 -0.15
slow_reader worker.cpuPp 0.003 0.029 -0.016 -0.006
slow_reader postgres.cpuPp -0.324 -0.008 0.339 0.118
slow_reader total.cpuPp -0.31 0.525 -0.008 -0.037
slow_reader gateway.rssMiB 21.977 -13.918 20.668 22.203
slow_reader gateway.heapMiB 23.389 -13.107 19.489 18.311
slow_reader worker.rssMiB -0.625 1.395 0.301 -0.383
slow_reader worker.heapMiB 0.631 -0.603 -0.499 -0.311
slow_reader rpc.p95Ms -0.25 0.581 0.643 0.544
slow_reader rpc.p95Percent -5.625 16.144 17.859 14.341
slow_reader history.p95Ms -4.318 -3.259 -5.754 4.18
governor gateway.cpuPp 0.261 -0.056 0.044 -0.267
governor worker.cpuPp -0.017 0.003 -0.009 -0.02
governor postgres.cpuPp -0.066 -0.096 0.048 -0.107
governor total.cpuPp 0.178 -0.149 0.082 -0.394
governor gateway.rssMiB -2.227 -23.598 -13.77 27.488
governor gateway.heapMiB -8.722 -31.28 -14.327 49.258
governor worker.rssMiB 0.168 -0.777 0.84 -0.039
governor worker.heapMiB -0.3 -0.187 0.963 -4.956
governor rpc.p95Ms 0.855 0.236 0.058 -0.074
governor rpc.p95Percent 34.976 8.947 2.092 -2.188
governor history.p95Ms 1.449 2.052 -2.135 -3.485
log_export gateway.cpuPp -0.002 0.258 0.135 -0.16
log_export worker.cpuPp 0.016 -0.012 -0.035 -0.06
log_export postgres.cpuPp -0.058 -0.07 0.011 -0.204
log_export total.cpuPp -0.045 0.176 0.111 -0.423
log_export gateway.rssMiB 2.906 14.844 14.098 -6.305
log_export gateway.heapMiB 3.504 10.406 10.387 6.177
log_export worker.rssMiB -0.152 0.066 8.836 -0.156
log_export worker.heapMiB -0.859 -1.849 14.348 -2.912
log_export rpc.p95Ms 0.532 0.389 -0.278 -0.963
log_export rpc.p95Percent 20.023 15.517 -8.03 -25.016
log_export history.p95Ms -1.88 5.93 -10.343 -19.754
trace_worker gateway.cpuPp 0.012 -0.076 0.392 -0.436
trace_worker worker.cpuPp 0.025 -0.073 -0.032 -0.078
trace_worker postgres.cpuPp -0.093 -0.073 0.098 -0.221
trace_worker total.cpuPp -0.056 -0.222 0.458 -0.735
trace_worker gateway.rssMiB 4.574 2.586 1.527 6.938
trace_worker gateway.heapMiB 0.236 3.499 0.437 2.691
trace_worker worker.rssMiB -0.078 10.621 -3.441 -2.582
trace_worker worker.heapMiB -0.06 19.303 -1.657 -2.397
trace_worker rpc.p95Ms 0.346 0.335 -0.028 -1.725
trace_worker rpc.p95Percent 12.327 11.765 -0.936 -40.849
trace_worker history.p95Ms 0.708 -2.349 2.665 -140.633

Sampling, controls and postprocessing

All four B runs exported gateway trace samples in every gateway phase and worker samples in the worker phase, with zero trace drops. No new A/A controls were run, following the maintainer's instruction to stop extra A/A work. Earlier stages' steady A/A envelope (about 0.58–0.98 ms) is historical context only, not a new control or a noise adjustment for this run. Slow-receiver p95 is +0.562 ms (+15.242%) primary / +0.581 ms (+16.144%) sensitivity; its gateway RSS/heap increase persists without pair 4.

The first launcher invocation aborted before measurements because the short-phase guard omitted stage 6. That guard was fixed and committed before this immutable recording. All four completed pairs above come from the clean restart. The final postlude then exposed a report-only assumption that every stage records every known phase; it was corrected to use the recorded phase subset, with focused adapter tests covering earlier stages, complete pairs and strict order. The corrected report was regenerated from unchanged raw results; no recordings were repeated for that fix.

Subsequent QA fixes are isolated to stage-2 UI tokens/copy, stage-5 startup/link log template recognition and the report adapter. No tracing instrumentation changed after this measured head. Their final restacked heads are reported in the PRs. No collector budget or native fingerprint changed.

Evidence directory: /var/tmp/canopy-diagnostics-6/window-20261112-stage6-retry/ (not committed): head.txt, results.jsonl, paired-report.json, controller.log, controller.pid, stderr.log, maintenance.txt. Raw heap snapshots were not collected in this gate. All measured processes/scopes ended and benchmark ports were verified free.

@nixuuu
nixuuu added this pull request to stack #506 November 12, 2026 21:45
@nixuuu
nixuuu force-pushed the feat/diagnostics-6-tracing branch 3 times, most recently from c096031 to f226def Compare November 12, 2026 23:45
@nixuuu
nixuuu marked this pull request as ready for review November 12, 2026 23:59
@nixuuu
nixuuu force-pushed the feat/diagnostics-6-tracing branch from f226def to 1624e9a Compare November 13, 2026 00:04
@nixuuu
nixuuu force-pushed the feat/diagnostics-6-tracing branch from 1624e9a to e1172d2 Compare November 13, 2026 00:20
@nixuuu
nixuuu merged commit 31c7f87 into dev Nov 13, 2026
9 checks passed
@nixuuu
nixuuu deleted the feat/diagnostics-6-tracing branch November 13, 2026 00:35
nixuuu added a commit that referenced this pull request Nov 13, 2026
The user's 237-second trace filled its 2000-span ring and overwrote 112
sampled operations. Retain up to 10000 numeric samples (720000 B plus 16
B scratch) inside the unchanged separate 4 MiB opt-in trace ceiling.
Sampling remains 1/101 operations and at most 100 samples/s; no new
payload fields, timer, persistence or automatic collection.

Add an optional `DiagnosticsTraceRequest.max_samples` field and
regenerate contracts. Web/mobile request 10000; absent/zero retains the
legacy 2000 export limit through gateway, linked computer and
WorkerLink. Export truncation counts as dropped samples without
destroying the full local ring. Thus an older linked gateway's strict
validator still accepts the result.

Paired 30 s local workload after 5 s warmup: two linked desktop
gateways, 12 threads each, desktop SSE plus mobile Connect simulation,
diagnostics and tracing enabled.

| Diagnostics counter | Before A / B | After A / B |
|---|---:|---:|
| Database queries | 2901 / 2619 | 2900 / 2621 |
| Trace spans at end | 105 / 80 | 109 / 80 |
| Trace dropped samples | 0 / 0 | 0 / 0 |

This short idle workload does not fill either ring; it verifies
unchanged background work, not a drop reduction. A numeric synthetic
workload matching the reported 2112 sampled operations over 237 s
retains 2112 spans / 0 drops, versus the legacy export's 2000 spans /
112 drops. Saturated ring tests verify unique IDs, the 4 MiB encoded
limit, stop/expiry cleanup and repeated GC plateaus (27 assertions).

Validation: real owner-scoped tracing integration suite 7 passed / 79
assertions, including both export limits through local, linked and
worker routes; synthetic retention 9 assertions; memory suite passed.
Install, full typecheck, lint, format:check and web build passed. Proto
generation committed; gen:check rerun after commit. Full local check:tmp
deferred to CI because the shared host is overloaded; focused files ran
individually with clean temp directories.

Mobile iOS and Android exports passed. Native inputs unchanged: paired
local fingerprints are identical before/after (iOS
`74705db3a68907bc28379bb9b1080a227bc0755b`, Android
`7d38be8f5c9bf842d62060c75820a206f99c87e3`). Device UI verification
remains blocked by the reported device-host error. Request construction
changes only; no visible UI/copy changes.

Fixes: #590

CI follow-up: the first full run passed 666 tests in the affected shard
but failed the memory test's unchanged 2 MiB heap-delta bound. The
expanded-ring test now warms a full 12-cycle window, including
GC/expiry, before its baseline, and prints all cycle samples on failure.
The revised local run passes 27 assertions: final stopped delta 743624 B
and purged delta 23480 B. Both the 2 MiB absolute delta and 1 MiB purged
plateau bounds remain unchanged; confirmation on CI is pending.
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