Repository navigation
feat(diagnostics): add time-limited tracing and explicit exports - #590
Merged
Merged
Conversation
nixuuu
force-pushed
the
feat/diagnostics-6-tracing
branch
3 times, most recently
from
November 12, 2026 23:45
c096031 to
f226def
Compare
nixuuu
marked this pull request as ready for review
November 12, 2026 23:59
nixuuu
force-pushed
the
feat/diagnostics-6-tracing
branch
from
November 13, 2026 00:04
f226def to
1624e9a
Compare
nixuuu
force-pushed
the
feat/diagnostics-6-tracing
branch
from
November 13, 2026 00:20
1624e9a to
e1172d2
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, includingslow_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 head0d058ff70d1dec3791c2c697c155de56d9bb2c5a. 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 MiBArrayBufferself 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.diagnostics_trace_v1; generated contracts included. No migration, protocol bump, frozenupdate/v1edit 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 --checkand shell syntax validation of the stage-6 bench script. Focusedcheck:tmpruns, 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; focusedcheck:tmpruns 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'sadditional_capabilitiesfield/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-interactivepreserves iOS6ddec9ef559ee0095ac33e94ff9418a942053b17and Android5f6eae3ab278f1cd543e9ed763f923a319b65ec9. 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.
updatedbran 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.mdand 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.
updatedbPID 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
Gateway — sensitivity excluding flagged pair 4, n=3
Worker and process totals
Total CPU sums the measured gateway, worker and PostgreSQL processes; it excludes the driver.
Host results
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.
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.