Skip to content

fix(computers): preserve legacy capability handshakes - #574

Merged
nixuuu merged 2 commits into
devfrom
fix/computer-capability-overflow
Nov 12, 2026
Merged

nixuuu merged 2 commits into
devfrom
fix/computer-capability-overflow

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 12, 2026

Copy link
Copy Markdown
Member

The full desktop hello grew from 32 capabilities in nightly.133 to 33 in nightly.137 when #559 added remote_thread_panel_v1. Both versions reject more than 32 as Unauthenticated: Invalid computer identity, so an update reconnect can fail after TLS pin authentication succeeds. #573 prevents the false pairing warning, but does not repair this handshake failure.

Keep the original nightly.133 capabilities in field 7 (at most 32 entries) and send subsequent capabilities in additive NodeHello.additional_capabilities (field 8). Older peers ignore field 8 and keep all their existing configuration, move and update capabilities. New peers combine both fields before negotiation and accept unfixed nightly.137 hellos containing 33 entries in field 7. Bound the combined list at 128 and reject overflow with InvalidArgument. Pair requests/responses, connect, welcome and rename broadcasts all use the same encoding. TLS pins, certificate verification and owner scoping retain their existing checks.

Added gateway-to-gateway integration coverage using the actual desktop startComputerLinks constructor, which enables every production capability:

  • Complete production pairing, followed by restarting both gateways on their existing databases; compare pins and full negotiated capabilities.
  • Raw unfixed 33-entry Pair and Connect requests over pinned TLS, plus malformed overflow rejection without changing persisted trust.
  • Mixed-version pairing in both directions and rename handshakes against the nightly.133 32-entry guard and unknown-field behavior. This fixture emulates the old decoder/validator; it does not run a released desktop binary.

Validation: generated protobuf bindings with bun run gen; formatted changed source files; git diff --check is clean. No local tests, typecheck, lint, build, servers or Docker runs: the maintainer has a performance measurement running and requested CI-only execution. CI must validate the new coverage and repository gates. No UI copy changed.

Static investigation and startup/updater/keychain evidence: #573 (comment). The source establishes this release regression in the full desktop configuration; incident logs would be needed to attribute every earlier report or explain successful re-pairing under a different configuration.

Fixes: #559
Related: #573

Keep the original 32 capabilities in the legacy hello field and negotiate overflow through an additive field. Accept the unfixed 33-entry hello without weakening certificate pins or owner scoping.

Fixes: #559

Related: #573
@nixuuu
nixuuu marked this pull request as ready for review November 12, 2026 14:52
@nixuuu
nixuuu merged commit c1746a7 into dev Nov 12, 2026
9 checks passed
@nixuuu
nixuuu deleted the fix/computer-capability-overflow branch November 12, 2026 15:08
nixuuu added a commit that referenced this pull request Nov 12, 2026
An update or restart can surface an authentication failure as “Pair
again” even when the saved computer identity has not changed. Reconnect
now treats RPC authentication failures as retryable and requires
repeated, locally verified TLS pin mismatches before requesting new
trust. A successful handshake with the saved identity clears stale
pairing state.

## Investigation

- The dial catch classified **every**
`ConnectError(Code.Unauthenticated)` as a pin mismatch. That includes
invalid certificate validity, a peer rejecting the client pin, and hello
validation; on a manual route it persisted `pairing_required`, and on
LAN it deleted the route. This behavior exists in the original linking
implementation (#13), before the reported release range.
- Reviewed `v0.2.0-nightly.120..v0.2.0-nightly.137` and the `.133` →
`.137` diff, including #547, #548, #559, #562, #565, #566 and #546. The
full desktop hello grew from 32 capabilities to 33 in #559; both
releases reject more than 32 as `Unauthenticated: Invalid computer
identity` after pinned TLS succeeds. Merged #574 fixes this capability
overflow, including compatibility with the older validator. This branch
is rebased onto that fix in `dev`. Full source evidence:
#573 (comment).
- Identity and the 20-year certificate are persisted in
`computer_identity`; the private key uses the existing encrypted secrets
key. Desktop keeps the same Canopy data directory, database,
app/keychain name and `secrets.enc` across versions and channel changes.
Keychain/decryption failure stops startup rather than replacing the
identity. Reinstalling while preserving that data preserves trust;
deleting it creates a new identity.
- Production starts computer links, including loading identity and
peers, before opening Network access. There is no demonstrated
listener-before-store race in that path. The new readiness guard also
makes an early or stopping link service explicitly return `Unavailable`.
- `manual` means entered by the user, including a LAN/Tailscale address;
it is separate from the network's address type. A bad manual path must
not override another route or an incoming connection proving the saved
pin. The capability-count rejection is source-proven for the reported
version pair's full desktop configuration; incident logs would still be
needed to attribute every earlier report or explain successful
re-pairing.

## Changes

- Use a local `CertificatePinMismatch` signal emitted only after TLS
proof of possession and validation of a different self-signed
certificate. Override ConnectError's inherited structural
`Symbol.hasInstance` check so ordinary RPC errors cannot impersonate
this local class. Without this override the new LAN test correctly
caught a real route-deletion bug, not test timing. Invalid/expired
certificates remain rejected without declaring an identity change.
- Exhaust routes first. Require the same different certificate at the
same manual route in two consecutive failed rounds. A matching pinned
TLS connection or ready incoming link outweighs stale addresses. Only a
verified pin mismatch removes a discovered LAN route. Saved pins are
never replaced automatically.
- Clear confirmation evidence after pinned TLS verification, a
successful handshake, explicit pairing, route edits and unlink. Existing
successful handshake recovery also clears a persisted `pairing_required`
after restart.
- Use the shared reason “{name}'s identity changed. Pair again to trust
it.” for linked computer availability and app updates, including the
relay's name when its identity changed. Remove the contradictory
automatic-retry explanation for that state. Add stable auth-failure
classifications to diagnostics without logging certificates, keys,
addresses or RPC payloads.
- Document persistence and recovery. No proto changes, protocol bump or
migration.

## Regression coverage

Added gateway↔gateway integration scenarios using independent databases
and real TLS listeners:

1. Repeated startup `Unauthenticated` on manual and LAN routes preserves
trust and resumes; verify the LAN route remains after each attempt. RPC
error text cannot impersonate a local pin mismatch, and failed TLS
connections cannot confirm a manual route's identity change.
2. An early listener returns `Unavailable` for both `Pair` and `Connect`
until ready.
3. Both gateway/core restarts reuse persisted identities/certificates
and reconnect; a protocol-1 `.133` hello without new capabilities links
with a `.137` hello and resumes after upgrading.
4. A real new key requires confirmed pairing, receives no RPC, never
replaces the pin, and has consistent availability/update explanations.
5. A persisted stale pairing state heals after restart; a valid
alternate route outweighs a stale manual address with another key.

The older-version scenario exercises the compatible wire
hello/capability set, not archived app binaries. Installer and OS
keychain behavior was inspected in source, not exercised on
macOS/Windows.

## Validation

- After maintainer clearance, ran only the two authorized test files,
sequentially, at `nice -n 19`, using `TMPDIR=/var/tmp` and `bun run
check:tmp`: `linked-pairing-recovery.test.ts` **10 pass**,
`linked-capability-compatibility.test.ts` **3 pass**. Both
temp-directory checks passed. The original LAN failure reproduced before
the fix (8 pass / 1 fail); the strengthened assertion confirmed deletion
immediately after the first auth failure.
- Changed-file formatting and lint passed; `git diff --check` is clean.
Earlier dependency install and repository formatting/lint checks passed
before the original push.
- CI validates generation, full typechecking, all test shards and builds
for the rebased head. Browser verification remains pending; the UI
change reuses existing components and only changes status explanations.

## Copy audit (§8)

“{name} must be paired again” / “Link it again…” / “unavailable, trying
again automatically” → “{name}'s identity changed. Pair again to trust
it.” The text states the verified problem and the explicit trust action,
uses two short sentences and avoids TLS jargon. The compact action badge
remains “Pair again”. Names are interpolated as whole values and
existing wrapping/layout remains in place; short/long-name checks at
desktop/phone widths have not been run yet.

Related: #13
nixuuu added a commit that referenced this pull request Nov 13, 2026
…#505)

**Draft — Stage 1 gate accepted by the maintainer; the six-stage stack
remains draft.** The accepted decision uses CPU median deltas ≤0.33 pp,
RPC p95 within ±0.5 ms and startup readiness +0.39 MiB. Remaining
approximately +12 MiB RSS medians in pool-contention/post-restore were
accepted within measured RSS noise (pair range −240…+18 MiB). Stage 2
must not increase those budgets. Historical runs/exclusions below remain
evidence, not a newly repeated Stage 1 gate.

## Stage 1

Current stack base: dev `968757a4c`. Migrations 0124–0128 are already
merged, so Stage 1 is **0129_diagnostics** (registry, schema and
sync-upgrade references updated). Stages 2–3 add no migration; Stage 4
follows with 0130 and Stage 5 with 0131. Contracts stay additive and
`update/v1` remains untouched. The stack reuses #574's shared
`additional_capabilities` field and handshake implementation, replacing
its independently implemented extension field; production legacy-peer
integration passes. Stages 2–3 overhead gates are also accepted; their
focused governor/series GC test is recorded in #535. All six stages are
implemented; the entire stack stays draft while final current-head CI
runs, then will be marked ready together as requested by the maintainer.

Settings → General → Diagnostics shows this computer and every linked
computer on web/desktop and mobile: freshness, offline saved data,
unsupported/denied states, link and RPC findings, sortable/paged RPC
rows and drill-down, and 1 min / 15 min / 1 h / 24 h windows.

- Descriptor-allowlisted RPC lifecycle metrics use 128 fixed duration
buckets, counts/rates, final codes, current/peak in-flight, stream
lifetime/first-message/message classes, and existing encoded payload
sizes where available. Public RPC payload sizes remain **Not measured**:
no existing-byte hook exists, and messages are never re-encoded to count
bytes.
- Worker/computer heartbeat echoes measure monotonic RTT/jitter
separately from heartbeat age/interval. Older versions remain usable and
visibly unsupported.
- Reads are owner-scoped. Direct and one-relay reads use
capability/onward grants, revoke/cache invalidation, shared background
gathering and bounded traffic/memory. Metrics never contain prompts,
paths, payloads, free-form errors or request-derived method labels.
- Lightweight aggregates, findings, session checkpoints and last-known
peer overviews persist off the request path, with atomic retry/dedupe,
restart gaps and existing retention leases.

Stack: [#495](#495) →
[#505](#505), [stack
#506](Stack #506). No merge is
performed by this handoff.

## Rebase and migration

The full diagnostics stack was rebased onto `origin/dev`
**`3d44197868b9c42eec317dcc3bf5903841e6e582`**, including incremental
sync #538/#539/#541/#543. Documentation head:
`7ef043e411b13d310111a90362b63de55175d2b7`; Stage 1 head:
**`ed0dc6509914499ec3812df7a1f1341266809fcb`**. Branches were
force-pushed with leases through `gh stack`. Bases remain #495 → `dev`,
#505 → `docs/diagnostics`; #535 and #542 continue above this PR.
Current-head full CI is green. Historical Stage 1 measurements below
retain their original revisions.

Dev includes migrations 0120–0124; concurrent PRs reserve 0125–0128.
Diagnostics uses **`0129_diagnostics.sql`**, with index/schema
expectations and the sync→diagnostics upgrade test updated. Stages 2–3
add no migration; Stage 4 follows with 0130. Draft numbers may still
need renumbering if dev advances. Additive GitHub/sync/diagnostics
contracts were regenerated; frozen `update/v1` is unchanged. The
allowlist/page-offset ceiling remains **512** and fixed collector
budgets remain unchanged.

## Memory and restore redesign

The original dense design had a real regression: approximately +140–160
MiB startup VmHWM, 1.3–6 s wall restoration, and +50–100 MiB
reconnect/write-failure RSS. Earlier CPU/p95 deltas changed sign under
heavy host swapping and cannot establish acceptance. The previous
resource-only run also had idle RSS +17.50 MiB and one post-restore peak
+13.83 MiB; those findings motivated the current controlled rerun and
are not erased.

- Histograms contain sorted nonzero bucket indices/counts in memory and
packed-varint protobuf fields on disk. Aggregate merges reuse buffers
without protobuf copies per merge.
- Keep the short live ring, current minute plus the last 60 minutes, and
incremental 15 m / 1 h closed-minute aggregates. Restored/live rings
remain separate for session dedupe. Cache admission failure uses direct
merging.
- The listener becomes ready before background restore; RPCs never await
it. Only the last hour of minute rows is restored in eight-row pages.
Incoming reports queue within a bound until persisted dedupe watermarks
load.
- The owner-scoped 24 h query uses hourly rows, a shared 5 s cache, and
the current hour from memory. At most one completed hour falls back to
at most 60 minute rows after a crash. View allocation is capped at 1
MiB.
- Hourly downsampling/replacement shares the atomic minute/state batch,
including retries and late minutes. Minute retention is **2 h** (quota
180 including maintenance grace); hourly retention **30 days** (quota
720). Collection has a 6 MiB method budget and 2 MiB link budget, 16
measured partners and 32 cached peer overviews. Dropped/limited coverage
is explicit.

`docs/diagnostics.md` and `docs/database-retention.md` document the
final retention, limits and size estimates, replacing 72 h of dense
in-memory minute history. No UI copy changed in this follow-up.

## Verification after rebase

Passed: `bun install`, `bun run gen`, `bun run gen:check`, full `bun run
typecheck`, root lint, format check and the web build. Ignored stale
Expo route types were regenerated with an isolated local Metro process,
then that process was stopped; no mobile source workaround was added.

Focused files ran serially:

| File | Tests | Assertions |
| --- | ---: | ---: |
| `packages/db/test/schema.test.ts` | 23 | 85 |
| `tests/integration/diagnostics-hourly.test.ts` | 4 | 23 |
| `tests/integration/diagnostics.test.ts` | 6 | 45 |
| `tests/integration/diagnostics-history.test.ts` | 11 | 76 |

Coverage includes bounded last-hour restore, owner-scoped hourly reads,
atomic replacement/dedupe, rolling expiry, responsive RPCs during locked
historical storage and reports arriving during restore. The integration
suite also covers three real gateways/workers with a relay, owner
denial/revoke, offline/older versions, no recursive gather, stream
cleanup, histogram/count dedupe, RTT versus heartbeat, limits, restart
continuity/gaps, failed-write retry, retention/downsampling and
concurrent pruning.

The requested **one fresh full `check:tmp` after all measurement/profile
processes stopped passed on this exact head**: **2383 pass, 165 skip, 0
fail**, **29,261 assertions**, **2548 tests across 443 files**,
**1372.23 s**. Command:
`TMPDIR=/var/tmp/canopy-diagnostics-1/sparse/checktmp-4b86ae4d bun run
check:tmp --max-concurrency 1`. Exit 0; `check:tmp: nothing left in the
temp dir`. The runner noted tool-owned caches excluded by its policy,
then removed its private tree; the parent scratch directory is empty.
The checkout remains clean at the measured SHA. Log:
`/var/tmp/canopy-diagnostics-1/sparse/checktmp-4b86ae4d.log`. No
production/test source was changed during this run, and the full suite
was not repeated.

Historical GitHub snapshot (2026-11-11): **CI green on both layers**,
including static checks/commitlint and the aggregate
typecheck/tests/builds job. #505 passed all four test shards and
web/Linux builds; docs-only #495 correctly skipped those matrix jobs. No
submitted reviews or review decision. Both PRs remain draft until the
complete stack is verified. Runs: [#495
CI](https://github.com/itsoltech/canopy/actions/runs/42943020455), [#505
CI](https://github.com/itsoltech/canopy/actions/runs/42943019335).

## Controlled overhead measurement

**Historical recording: 3 of the requested 5 pairs completed. Stage 1's
gate was subsequently accepted by the maintainer as stated at the top.**
The unchanged runner stopped with exit 1 after all three attempts at
pair 4 crossed the requested swap-out gates. Pair 5 never started.
Results below preserve medians/ranges of only those three eligible whole
pairs, rather than implying a five-pair run. Both PRs remain draft as
part of the unfinished stack.

Memory also remains open: steady RSS reached **+13.05 MiB** in accepted
pair 2, despite a three-pair median of +7.08 MiB; post-restore restart
VmHWM uplift reached **+14.26 MiB**. Pool-contention RSS median was
+12.48 MiB. These observations are retained; favorable CPU/p95
observations do not override memory or the missing pairs.

Protocol: five alternating off/on, on/off, off/on, on/off, off/on pairs
(ABBA blocks), each process warmed with 300 reads plus 5 s. Every member
has 10 min idle and 140 s each steady, reconnect, slow reader, write
failure and pool contention. Four lanes offer 20 GetThread/s; the
slow-reader fixture adds four update lanes and eight paused watches.
Overview reads use 15 min; detail reads use 24 h every 10 s, exceeding
the 5 s cache TTL. Each member starts with equivalent fresh private
databases: 120 minute + 720 hourly sparse rows, 24 methods, four nonzero
duration buckets and actual coverage timestamps; seeded payload
**1,115,520 bytes**.

Gateway, worker, PostgreSQL and driver are pinned to separate physical
cores (2/3/4/1). `nice -n -5` is denied, so affinity-only fallback is
used. Own ports 18191/18192; no existing stack or global caches were
changed. No builds/tests or forced GC ran alongside accepted
measurements. New processes reset their own runtime caches and warm
their own data.

Before every attempt: loadavg and 30 s preflight. Continuous `vmstat -w
-S K 1` ignores the first since-boot row; `/proc/vmstat` and actual
4096-byte pages enforce cumulative output. Reject swap-out ≥128 KiB/s in
any sample or ≥1 MiB cumulative; swap-in ≥1024 KiB/s or ≥128 KiB/s for
three consecutive seconds; load above 12 logical CPUs. Small old-page
reads are allowed and logged. Rejected whole attempts are excluded, with
at most three attempts per pair; no thresholds were relaxed.

Acceptance: paired CPU median delta <1 percentage point of one core; RPC
p95 median delta <max(1 ms, 10% baseline); startup/steady RSS uplift ≤10
MiB. Also report synchronous startup diagnostics CPU (<100 ms),
background restore separately, and full-history p95 (<50 ms).

### Host eligibility and exclusions

| Pair / attempt | Accepted | Max load | Swap-in peak KiB/s | Swap-in
bytes | Swap-out peak KiB/s / bytes | Reason |
| --- | --- | ---: | ---: | ---: | ---: | --- |
| 1 / 1 | No | 1.45 | 2476 | 3,760,128 | 0 / 0 | Input rate |
| 1 / 2 | No | 0.20 | 4544 | 4,784,128 | 0 / 0 | Input rate |
| 1 / 3 | **Yes** | 1.23 | 792 | 1,863,680 | 0 / 0 | Allowed old-page
reads; longest ≥128 KiB/s streak 1 s |
| 2 / 1 | No | 0.92 | 5668 | 6,828,032 | 0 / 0 | Input rate |
| 2 / 2 | **Yes** | 0.80 | 160 | 655,360 | 0 / 0 | Allowed reads; streak
1 s |
| 3 / 1 | **Yes** | 0.79 | 48 | 663,552 | 0 / 0 | Allowed reads; streak
0 s |
| 4 / 1 | No | 0.68 | 244 | 385,024 | 792 / 811,008 | Output rate |
| 4 / 2 | No | 0.66 | 60 | 262,144 | 2200 / 2,580,480 | Output rate and
total |
| 4 / 3 | No | 0.87 | 676 | 937,984 | 2172 / 2,682,880 | Output rate and
total; retry limit reached |

Each accepted pair contains both members and all six phases (18 verified
complete phase/pair groups). Each has 2672 one-second host samples.
Accepted keys are **1/3, 2/2, 3/1**; all rows from other attempts are
excluded, including their completed on phases. No pair 4 data are
spliced into pair 5 or the medians.

Pair 4's output bursts occurred around the transition into the disabled
member. The host counters do not identify which process owned those
pages; this report does **not** attribute them to other agents or prove
an external cause.

### Preliminary paired deltas, median [min, max], n=3

CPU is percentage points of one core; all differences are on minus off.
RPC baselines were below 10 ms, so the requested p95 threshold is 1 ms
in every measured phase. Idle issues no application reads. History p95
is the enabled 24 h view including database/transport, with 14 reads per
loaded phase/member.

| Phase | Gateway CPU pp | RPC p95 ms | RSS MiB | Enabled 24 h p95 ms |
| --- | ---: | ---: | ---: | ---: |
| Idle | +0.0127 [0.0077, 0.0170] | — | +5.74 [3.07, 8.78] | — |
| Steady | +0.2676 [0.1319, 0.3261] | −0.030 [−0.467, 0.435] | +7.08
[−2.13, **13.05**] | 25.334 [22.614, 27.338] |
| Reconnect | +0.2345 [0.2009, 0.3327] | +0.208 [−0.175, 0.301] | +6.35
[2.68, **11.68**] | 12.550 [11.853, 14.823] |
| Slow reader | +0.1275 [0.1225, 0.1868] | +0.120 [−0.736, 0.184] |
+3.82 [−25.05, 7.33] | 19.789 [12.405, 22.396] |
| Write failure | +0.0471 [−0.1152, 0.0951] | +0.135 [−0.030, 0.331] |
+9.21 [−240.37, **12.96**] | 11.319 [9.789, 12.455] |
| Pool contention | +0.0545 [−0.1950, 0.0695] | +0.263 [−0.034, 0.287] |
**+12.48** [4.25, **17.86**] | 18.999 [18.103, 23.030] |

Large negative RSS deltas are preserved: in pair 1 the disabled process
still held 422.67 MiB after the slow-reader phase at the write-failure
sample, versus 182.30 MiB enabled. These are raw RSS endpoints with
normal GC, not retained heap or proof of memory savings. No forced GC,
trimming, outlier removal or favorable-pair selection enters this table.
Offered GetThread traffic completed 2804 calls/member/loaded phase,
except 2805 disabled slow-reader calls in pair 1; reconnect completed 27
reconnects/member/phase. Eight paused watches and about 2800 updates ran
in each slow-reader phase.

| Pair | Phase | Δ CPU pp | Δ RPC p95 ms | Δ RSS MiB |
| --- | --- | ---: | ---: | ---: |
| 1 | Idle | +0.0127 | — | +5.74 |
| 2 | Idle | +0.0170 | — | +8.78 |
| 3 | Idle | +0.0077 | — | +3.07 |
| 1 | Steady | +0.2676 | −0.030 | +7.08 |
| 2 | Steady | +0.1319 | +0.435 | **+13.05** |
| 3 | Steady | +0.3261 | −0.467 | −2.13 |
| 1 | Reconnect | +0.3327 | +0.208 | +2.68 |
| 2 | Reconnect | +0.2009 | −0.175 | **+11.68** |
| 3 | Reconnect | +0.2345 | +0.301 | +6.35 |
| 1 | Slow reader | +0.1868 | +0.120 | −25.05 |
| 2 | Slow reader | +0.1275 | +0.184 | +7.33 |
| 3 | Slow reader | +0.1225 | −0.736 | +3.82 |
| 1 | Write failure | +0.0471 | −0.030 | −240.37 |
| 2 | Write failure | −0.1152 | +0.331 | **+12.96** |
| 3 | Write failure | +0.0951 | +0.135 | +9.21 |
| 1 | Pool contention | −0.1950 | +0.287 | +4.25 |
| 2 | Pool contention | +0.0545 | −0.034 | **+12.48** |
| 3 | Pool contention | +0.0695 | +0.263 | **+17.86** |

Steady raw baselines (CPU %, RPC p95 ms, RSS MiB), off → on: pair 1
**2.4037 → 2.6713; 2.939 → 2.909; 163.68 → 170.77**; pair 2 **2.4275 →
2.5594; 2.973 → 3.407; 161.37 → 174.42**; pair 3 **2.2916 → 2.6177;
3.481 → 3.015; 164.35 → 162.23**.

### Startup and restart continuity

VmHWM is the Linux process-image high-water mark. Startup is sampled at
readiness; background restore is reported separately. Restart peaks
compare to that pair's disabled startup baseline, not to an unrelated
process. Each enabled member has three fresh-process restarts.

| Pair | Startup VmHWM off / on MiB | Δ startup MiB | Initial
post-restore Δ MiB | Max restart ready Δ MiB | Max restart post-restore
Δ MiB | Sync startup CPU on ms | Restart background CPU ms (three) |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| 1 | 143.41 / 143.80 | +0.39 | +6.58 | +3.80 | **+14.26** | 0.929 |
86.451, 75.190, 76.820 |
| 2 | 143.42 / 141.99 | −1.43 | +5.48 | +3.04 | **+11.73** | 1.547 |
50.276, 51.827, 72.785 |
| 3 | 142.74 / 144.63 | +1.89 | +7.75 | +1.50 | **+12.75** | 0.938 |
58.646, 71.747, 82.577 |

Initial readiness VmHWM paired delta median **+0.39 MiB [−1.43,
+1.89]**; initial post-restore delta median **+6.58 MiB [+5.48,
+7.75]**. Max restart post-restore paired uplift median **+12.75 MiB
[+11.73, +14.26]**. Initial synchronous CPU median **0.938 ms [0.929,
1.547]**; maximum across initial starts and all nine restarts **2.439
ms**. Initial background inclusive CPU is **44.902 / 58.202 / 45.679
ms**; restart intervals are **50.276–86.451 ms**. These include
concurrent work in the process and are not isolated restore-function
CPU. Initial background wall intervals are **46.641 / 59.691 / 47.304
ms**; no 72 h startup scan occurs.

Raw startup heap off/on MiB: **22.24/23.30**, **56.79/16.26**,
**16.33/23.35**. Different GC phases make these unsuitable as
retained-memory deltas. Ring/link accounting immediately after restore
is **2,578,368 bytes** in each enabled member and **0** disabled; after
steady it is **2,280,512–2,322,048 bytes**. This counter excludes
rolling-window budgets, hourly-view/snapshot caches and runtime
overhead; it is not total retained memory or RSS.

### Worker, PostgreSQL and event loop

| Phase | Worker Δ CPU pp median [min,max] | PostgreSQL Δ CPU pp median
[min,max] | Gateway Δ loop p99 ms median [min,max] |
| --- | ---: | ---: | ---: |
| Idle | +0.0091 [0.0038,0.0107] | +0.0073 [−0.0020,0.0118] | +0.0013
[−0.0018,0.0090] |
| Steady | +0.0034 [0.0002,0.0101] | +0.0311 [−0.0446,0.0351] | +0.0041
[−0.0031,0.4337] |
| Reconnect | +0.0038 [−0.0030,0.0118] | +0.0412 [0.0017,0.0663] |
+0.0379 [−0.1326,0.4869] |
| Slow reader | +0.0031 [−0.0000,0.0093] | +0.0012 [−0.1739,0.1358] |
+0.1085 [0.0655,0.1884] |
| Write failure | +0.0024 [0.0017,0.0141] | +0.0380 [0.0047,0.1191] |
−0.0701 [−0.2673,0.1623] |
| Pool contention | +0.0054 [0.0038,0.0083] | +0.0276 [−0.1164,0.0292] |
−0.2550 [−0.2785,−0.0896] |

Enabled gateway event-loop p99 ranges from 0.460 to 1.816 ms across
measured phases. Worker RSS samples are 73.80–77.13 MiB. Write-failure
fixtures held the diagnostics table for 70 s: enabled persistence
changed `unavailable` → `saved` with zero pending minutes afterward in
every accepted pair. Pool contention showed nine blocked gateway
connections; recovered persistence remained `saved`, with zero pending
minutes.

### Persisted writes and bytes/hour

One mutation batch/minute means **60 scheduled batches/hour per
process**, with more tuple changes inside the batch. Counts below are
diagnostics table inserts/updates, **not batches**. Hour
replacement/compacted flags, seeded compaction and retry recovery create
bursts, so extrapolating a 140 s phase is not a normal long-run write
count. Disabled timed tuple-change rates were zero. Bytes are paired
deltas of **whole private PostgreSQL WAL/NVMe cgroup I/O**, including
maintenance/checkpoints and application interactions; they are not
isolated payload bytes. Negative deltas are preserved. Device 259:0 is
NVMe; zram device 253:0 is excluded from disk-write columns.

| Phase | On tuple changes/h median [min,max] | Δ WAL KiB/h median
[min,max] | Δ NVMe KiB/h median [min,max] |
| --- | ---: | ---: | ---: |
| Idle | 120.0 [120.0,485.9] | +573.8 [314.3,895.1] | +5062.6
[4823.2,5087.1] |
| Steady | 154.1 [102.7,385.1] | +896.1 [160.7,4472.4] | +5853.0
[5440.6,11500.4] |
| Reconnect | 102.7 [102.7,462.1] | +883.4 [874.5,1250.8] | +6336.3
[5454.6,7889.4] |
| Slow reader | 102.7 [102.7,153.9] | +1268.5 [−178.2,2817.8] |
+379849.8 [177096.6,439206.6] |
| Write failure | 77.0 [76.9,1665.4] | +1214.0 [−1048.8,2399.2] |
−4087.3 [−5537.0,11009.2] |
| Pool contention | 102.6 [102.5,153.8] | +1502.8 [−459.6,3442.3] |
+13391.0 [10689.2,13893.7] |

| Pair | Phase | On tuple changes/h | Δ WAL KiB/h | Δ NVMe KiB/h |
| --- | --- | ---: | ---: | ---: |
| 1 | Idle | 120.0 | +314.3 | +5062.6 |
| 2 | Idle | 485.9 | +895.1 | +4823.2 |
| 3 | Idle | 120.0 | +573.8 | +5087.1 |
| 1 | Steady | 102.7 | +160.7 | +5440.6 |
| 2 | Steady | 154.1 | +896.1 | +5853.0 |
| 3 | Steady | 385.1 | +4472.4 | +11500.4 |
| 1 | Reconnect | 462.1 | +1250.8 | +7889.4 |
| 2 | Reconnect | 102.7 | +874.5 | +5454.6 |
| 3 | Reconnect | 102.7 | +883.4 | +6336.3 |
| 1 | Slow reader | 153.9 | +2817.8 | +379849.8 |
| 2 | Slow reader | 102.7 | −178.2 | +177096.6 |
| 3 | Slow reader | 102.7 | +1268.5 | +439206.6 |
| 1 | Write failure | 77.0 | +2399.2 | −5537.0 |
| 2 | Write failure | 1665.4 | +1214.0 | −4087.3 |
| 3 | Write failure | 76.9 | −1048.8 | +11009.2 |
| 1 | Pool contention | 102.5 | −459.6 | +10689.2 |
| 2 | Pool contention | 102.6 | +3442.3 | +13391.0 |
| 3 | Pool contention | 153.8 | +1502.8 | +13893.7 |

`persistedBytesPerHour` in raw data is **net retained rollup payload
growth**, sometimes negative under retention. It is not bytes written
and is not substituted for WAL/I/O above. Seeded diagnostics table bytes
at startup are 1,490,944–1,499,136 plus 139,264 index bytes; measured
enabled phases reach 1,581,056 table bytes and 147,456 index bytes.
Logical payload after loaded phases is about 1.10 MB (1.05 MiB; see raw
counters), despite restoring only the last hour.

### Profile-backed remaining memory cost

A separate **nonacceptance** off/on control used the same production
revision with CPU/heap profiling enabled, 120 s idle +140 s steady,
realistic history and uncached 24 h reads. Only the benchmark
launcher/entry received temporary profiling hooks. They were restored
exactly to HEAD before the fresh full test. Profiles add their own
substantial memory overhead; their RSS/timing is not substituted into
the accepted-pair table. GC was forced only at shutdown in this control,
outside all accepted measurements.

The complete enabled heap profile has **1509 `Aggregate` objects, 6039
`Histogram` objects, 3018 `BigUint64Array` counter arrays**, and
**32,071 ordinary arrays versus 19,658 disabled**. `Aggregate` allocates
two fixed counter arrays and four histogram objects; each histogram owns
two sparse arrays. The 12,413 additional ordinary arrays and object
fan-out remain a concrete retained cost of the last-hour ring and its
views, even though dense histogram bins and 72 h restore are gone.
Enabled `FunctionCodeBlock` count is **1931 versus 1707** disabled;
their displayed self sizes are about 5.3 versus 4.7 MiB. These type
retained sizes overlap, so they are not summed.

| Qualitative profile control | Off | On | Difference |
| --- | ---: | ---: | ---: |
| Heap used after explicit full GC before shutdown, MiB | 79.21 | 84.61
| +5.40 |
| RSS after that GC, MiB | 193.25 | 199.58 | +6.33 |
| JSC reserved heap capacity after GC, MiB | 101.91 | 104.30 | +2.39 |
| Complete heap at exit after cleanup, bytes | 53,031,380 | 55,844,643 |
+2,813,263 |
| Ring/link budget accounting, bytes | 0 | 2,584,816 | +2,584,816 |
| Additional rolling-window accounting, bytes | 0 | 165,024 | +165,024 |
| Historical view series / pending payload bytes | 0 / 0 | 24 / 0 |
Bounded; no pending-write accumulation in this control |

The CPU profile identifies rolling-window refresh (`windows.ts`), sparse
count updates/aggregate merges and worker catalog work among added
diagnostics frames. Profile percentages/wall-weighted times are
qualitative; process CPU counters above determine the gate. The profiles
support focusing further memory work on the aggregate/histogram/counter
object layout and runtime/GC capacity. They **do not prove the cause of
the entire +13.05 MiB steady or +14.26 MiB restart RSS uplift**, nor
establish a leak or a memory pass. No further production change or
favorable remeasurement is hidden in this report.

Private profile evidence:
`/var/tmp/canopy-diagnostics-1/sparse/profile-4b86ae4d/`, including
`Heap.20261111.072510.2706275.0.003.md` (off),
`Heap.20261111.072944.2709361.0.003.md` (on), corresponding CPU
profiles, and `memory-2706275-7.json` / `memory-2709361-7.json`.
`instrumentation.patch` records the temporary hooks; no profile artifact
is committed.

### Row sizes and exact payload-write accounting

A separate resource-only exercise (`acceptance:false`, no timed
workload) records current-head row sizes and uses audit triggers only
after sampled processes stop. Fixture minute payload/tuple sizes are
**1184 /1253 bytes**; an uncompressed hourly fixture is **1352 /1421
bytes**. After compaction, hourly payloads range **1352–2100 bytes**
while physical tuple sizes range **368–1421 bytes** due to compression;
logical and physical sizes are separate measures. After the enabled
close, retained rows were 121 minute rows /141,496 payload bytes and 719
hour rows /972,836 bytes. Table/index sizes above come from actual timed
processes, not this audit.

Sixty synthetic minute calls through the real store issue **60 actual
mutation batches**. This deliberately exercises late minutes in one
already-completed hour, replacing that hourly row 60 times; it is **not
normal elapsed-hour timing or a 24-method production write-rate
estimate**.

| Mutation class | Tuple changes | Sum of NEW payload bytes written |
| --- | ---: | ---: |
| Minute rollups | 60 | 5700 |
| Hourly replacements | 60 | 6480 |
| State checkpoints | 60 | 2400 |
| **Total** | **180** | **14,580** |

This sum includes overwritten hourly payloads. The final retained
payload is only **5700 minute +108 hourly bytes**; it is explicitly not
reported as total bytes written. The byte sum excludes tuple/index/WAL
overhead; whole-database WAL/I/O measurements are reported separately
above. Evidence:
`/var/tmp/canopy-diagnostics-1/sparse/resources-4b86ae4d.{jsonl,log}`
and `profile-4b86ae4d/storage-instrumentation.patch`. The temporary
row/trigger instrumentation was restored before the full test; private
containers were removed.

Evidence:
`/var/tmp/canopy-diagnostics-1/sparse/measure-20261111T020059Z/`
(`results.jsonl`, `stderr.log`, recorded head/runtime/topology).
Repeatable wrapper:
`/var/tmp/canopy-diagnostics-1/sparse/run-five-pairs.sh`; instructions:
`/var/tmp/canopy-diagnostics-1/sparse/README.md`. Artifacts are not
committed.

## Browser, mobile and copy audit

Historical real-browser checks used three seeded computers (offline
saved metrics and older/unsupported included), long computer/method
names, many methods, sorting/pagination, unary/stream drill-down and
quiet/empty states. Light/dark, desktop/narrow/390 px phone were
inspected. No UI source changed in this follow-up; no new browser pass
is claimed after this rebase.

Screenshots remain uncommitted under `/var/tmp/canopy-diagnostics-1/`:
`desktop-{light,dark}.png`, `narrow-{light,dark}.png`,
`phone-{light,dark}.png`, `rpc-table-light.png`,
`rpc-details-{desktop,phone}.png`, `rpc-stream-details-phone.png`,
`quiet-desktop-light.png`, `quiet-phone-dark.png`,
`empty-desktop-light.png`, `empty-phone-dark.png`,
`rebased-desktop-{light,dark}.png`, `rebased-phone-{light,dark}.png`,
**`final-desktop-{light,dark}.png` and `final-phone-{light,dark}.png`**.
The last overview checks were 1440×1000 and 390×844 with no horizontal
overflow; full drill-down was not repeated after those rebases.

Copy audit (`docs/copy.md` §8): General → Diagnostics matches settings;
actions View calls / Show details / Retry / Allow. Short text
distinguishes loading, offline saved data, unsupported, denied,
insufficient coverage and no calls. **Not permitted** and **Not
measured** describe limits honestly; mobile gap text uses
singular/plural forms. Details disclose histogram quantization, exact
max and small p99 samples. Long names wrap/truncate without moving
controls; statuses use text and color. No UI tests/copy artifacts added.
The redesign leaves this copy unchanged.

Original EAS CLI 27.4.1 production fingerprints were unchanged: iOS
`6ddec9ef559ee0095ac33e94ff9418a942053b17`, Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. Stage mobile changes are JS
only; this follow-up adds no native source changes. Native visuals
remain unverified because device support failed twice, including the
advised refresh. No native diagnostics screenshot/parity pass is
claimed.

Earlier mobile verification: Expo Doctor 20/20, diagnostics modules'
scoped ESLint, and Android/iOS JS/Hermes exports passed. App-wide Expo
ESLint had 42 errors/5 warnings outside diagnostics. Disposable CNG
prebuild failed during Android image generation (`Could not find MIME
for Buffer <null>`); no native config/assets changed. No APK/IPA build
or publication attempted. Logs remain at
`/var/tmp/canopy-diagnostics-1/mobile-export-{android,ios-retry}.log`
and `mobile-export-{android,ios}/`.

## Remaining scope

**Keep #495 and #505 draft.** The maintainer accepted Stage 1's gate as
stated at the top. Historical run limitations and memory findings above
remain evidence; they are not pending gate failures. No `gh pr ready` or
merge was performed. The remaining stages must be completed and verified
before the stack can be made ready.

Later stages cover process resources/event loop/SQL/pool/governor,
broader worker/sync diagnostics, client aggregates/reports, log export
and tracing. Multi-instance live merging is future work; persisted
process/session identity is retained. Client FCP/TTI, independent
wire-byte accounting and operation-isolated maintenance cost remain
unmeasured. Public RPC payload sizes require an existing-byte hook.
Native visual parity still needs working device support.
nixuuu added a commit that referenced this pull request Nov 13, 2026
Collect logs now creates a bounded, redacted ZIP from the selected
computers and their workers. Web and desktop download it through an
authenticated, no-store route; mobile exports it using the existing
native modules. This is diagnostics stage 5, stacked on #569. Keep the
entire stack draft.

### Behavior and bounds

- Shared `@canopy/logs` writer replaces the desktop-only writer and
supports standalone gateway/worker/BFF logs. Fixed source aliases, 16
KiB lines, strict 5 MiB × 4 rotation and seven-day retention; periodic
pruning during continuous writes. External PostgreSQL logs require an
explicitly configured local adapter; no SQL logging is enabled.
- Redaction runs at each source before 32 KiB sequenced/checksummed
chunks. The export uses closed event templates: arbitrary messages,
unknown JSON, SQL/parameters, paths, hosts, names, stacks and causes are
omitted, with coverage counts. The coordinator verifies the closed
format again. This intentionally exports less context than raw logs.
- One owner job, two home readers, one exporter/home, sixteen selected
computers and sixteen workers/home. Post-redaction caps: 2 MiB/source,
12 MiB/home, 96 MiB/action and 100 MiB ZIP. Sources are pull-driven,
rate-limited and CPU-throttled; ZIP uses store mode and streams to
private disk. No raw spool, whole-ZIP heap buffer, durable worker
commands or retry queues. Per-chunk authorization checks do not clone
the job/coverage tree.
- Linked requests are source-only and nonrecursive. Onward log access
has a separate owner-scoped grant (migration 0131); read grants do not
imply log access. Revoke/cancel/expiry disconnect transfers and delete
spools. Private source registration rejects paired phones, desktop
renderers and linked callers. Partial sources remain explicit in a valid
partial ZIP; retry creates a new action. Optional attachment uses
ordinary owner-scoped placement, permissions and attachment limits, with
a coverage-manifest note and no automatic unpacking.
- Stack rebased onto dev `968757a4c`; diagnostics migrations remain 0129
(stage 1), 0130 (stage 4), 0131 (stage 5). It now reuses #574's shared
`additional_capabilities` field and handshake implementation instead of
the stack's duplicate extension field. Production legacy-peer
integration passes (3 tests / 34 assertions); log security and gRPC
export pass (3 / 16 and 4 / 138), with clean temporary directories.
Generated contracts are committed; update/v1 is untouched. Final
current-head CI is running; the maintainer authorized marking all seven
PRs ready together once green.

### Mobile: JS-only

No native dependency was added. **iOS uses Share logs; Android uses Save
logs and the existing Storage Access Framework directory picker.** The
successful Android save names the file and destination directory, and
offers Open folder when the OS reports it can open the URI. Otherwise
the destination confirmation remains visible. Share cancellation does
not report a successful share. Private cache files are bounded,
streamed, checksummed and removed after export, TTL or unpair.

**A native Android share sheet is a possible follow-up when we next ship
a native build anyway.** It is outside this stack.

Pinned `bunx [email protected] fingerprint:generate --platform
<ios|android> --build-profile production --json --non-interactive`
matches stage 4 exactly:

- iOS: `6ddec9ef559ee0095ac33e94ff9418a942053b17`
- Android: `5f6eae3ab278f1cd543e9ed763f923a319b65ec9`

### Verification and remaining work

Passed locally, one test file at a time:

- `packages/logs/test/export.test.ts`: 8 tests, 46 assertions. Split
secrets/UTF-8, oversized records, SQL/host/path/unknown payload
omission, range/tail/legacy budgets, rotation/TTL, symlink refusal, pull
checksums/cancel cleanup, coordinator verification and partial ZIP
integrity/traversal.
- `apps/gateway/test/diagnostics-logs-security.test.ts`: 3 tests, 18
assertions. Private source channel denial, bounded old-peer capability
compatibility, verified-byte accounting, partial-source cleanup and
absence of raw error/parameter bytes in ZIP.
- `bun install`, `bun run gen:check`, full typecheck (Svelte zero
errors/warnings), lint, format:check and `bash -n
scripts/bench/diagnostics-stage5.sh` passed. The final transfer-only
change also passed the focused gateway typecheck/security tests, lint
and format check.

After explicit permission, `tests/integration/diagnostics-logs.test.ts`
passed: **4 tests, 138 assertions**, using three real gateways, relay
read/log grant separation/revoke, worker source, auth, cancel and
partial ZIP. `packages/db/test/schema.test.ts` passed: **23 tests, 85
assertions**; `thread-sync-upgrade.test.ts`: **1 test, 19 assertions**.
Its rebase ordering error was corrected in stage 1 and cascaded through
the stack; 0126 is now applied after the upgrade fixture is seeded.
Files were run separately. Full gen:check/typecheck/lint/format checks
passed again before measurement. Full `check:tmp` and a fresh web build
are not claimed.

Native manual QA is **blocked**: device discovery returned `Device list
failed: Could not communicate with device support. Try refreshing
devices.` twice, including the requested refresh. Android SAF/iOS share
behavior is implemented but not confirmed on a device. No new
browser/screenshots or native QA pass is claimed for stage 5.

### Copy audit — docs/copy.md §8

1. No log export → **Collect logs**, **Time range**, computer selection
and concise secondary privacy/omission notes. English sentence case;
each description has one idea, no new glossary terms or humor. Redaction
is stated once, with missing/truncated coverage explained separately.
2. No export actions → **Download logs** on web/desktop, **Share logs**
on iOS, **Save logs** on Android. The common collection/error text is
shared in meaning. Android destination confirmation and conditional
**Open folder** complete the save flow; user-requested platform
terminology is preserved.
3. Generic failure → “Could not collect logs. Check the selection and
retry.” Refresh/export/cancel errors each have a concrete retry or
recollection action; no SQL, driver errors or implementation jargon
appears on the surface. Retry also works when initial collection failed
before a job existed.
4. No partial outcome → explicit per-computer progress, **Retry
failed**, downloadable partial archive and a 15-minute availability
note. Meaning does not depend on color; progress/status use live
announcements. Optional agent attachment is unchecked and explicit.
5. Layout uses the existing kit Dialog/Sheet, controls and density.
Short/typical/long-name desktop/phone visual verification remains open;
it is not represented as a completed audit item.

Run `bash scripts/bench/diagnostics-stage5.sh` only in a
maintainer-confirmed quiet window. The launcher is reusable (about 140
minutes before retries). Its default is four pairs; the completed
recording below is the current evidence.

### Measurement results — 2026-11-12

Measured head: `711b2b29b29ad8998c1d95b2e3d063a882a6cb8a`. Four accepted
pairs, all attempt 1; no host-gate rejections. Strict **AB / BA / AB /
BA**, fresh driver VM, PG cluster/database/WAL and gateway/worker state
per member; idle 180 s, other phases 90 s. Stages 1–4 stay enabled on
both sides. No tests or builds ran during recording.

Every sampled scope had `MemorySwapMax=0` and `memory.swap.current=0`
(stage 5: 7,649 samples, maximum load 2.74). Load and sustained swap-in
gates passed. Host swap-out remains log-only. Pinning kernel kswapd away
from the measured CPUs failed with **Operation not permitted**; kernel
ticks/CPU and zram IO were recorded instead.

**Each cell is all four pairs / sensitivity without flagged pair 4
(n=3).** Pair 4 is flagged by the agreed joint rule: a delta beyond
2×MAD coinciding with host swap-out >4 MiB/s. It stays accepted and
included in the primary median. CPU is summed gateway + worker +
PostgreSQL + driver/BFF, in percentage points of one core. RSS/heap here
are gateway phase-end values, without forced GC; other processes are
below. No fresh A/A control was run in this window, and no new A/A noise
floor is claimed.

| Phase | CPU pp | RPC p95 ms | RPC p95 % | Gateway RSS MiB | Gateway
heap MiB |
|---|---:|---:|---:|---:|---:|
| idle | +0.019 / -0.025 | — | — | +0.848 / +0.223 | +0.148 / +0.133 |
| steady | -0.116 / -0.221 | -0.146 / -0.293 | -4.021 / -8.070 | +0.285
/ -0.629 | -0.208 / -0.144 |
| reconnect | +0.074 / +0.103 | +0.232 / -0.052 | +9.225 / -1.948 |
+0.607 / +1.383 | +0.597 / +0.336 |
| slow_reader | +0.232 / +0.141 | -0.625 / -0.895 | -13.750 / -19.343 |
+1.619 / +4.973 | +6.898 / +3.316 |
| write_failure | +0.311 / +0.322 | +0.164 / +0.153 | +5.765 / +5.466 |
-0.729 / +2.094 | +0.777 / +0.905 |
| pool_contention | +0.044 / +0.187 | -0.253 / -0.202 | -7.108 / -5.232
| -0.154 / +0.297 | -2.999 / -4.728 |
| governor | -0.092 / -0.220 | +0.231 / +0.301 | +7.768 / +11.164 |
+9.666 / +12.328 | +6.104 / +8.395 |
| report | +0.078 / +0.103 | -0.058 / +0.019 | -2.008 / +0.729 | +5.633
/ +6.633 | +2.795 / +4.687 |
| log_export | +0.860 / +0.906 | -0.233 / -0.080 | -8.666 / -3.156 |
+3.059 / +1.934 | +2.150 / +2.073 |

| Pair | Order | Accepted / attempt | Host swap-out MiB total | Peak
MiB/s | Joint MAD flag |
|---|---|---|---:|---:|---|
| 1 | AB | yes / 1 | 0.000 | 0.000 | no |
| 2 | BA | yes / 1 | 0.000 | 0.000 | no |
| 3 | AB | yes / 1 | 0.000 | 0.000 | no |
| 4 | BA | yes / 1 | 26.492 | 24.172 | yes |

<details><summary>Worker and driver/BFF resource medians (all /
sensitivity)</summary>

| Phase | Worker CPU pp | Worker RSS MiB | Worker heap MiB | Driver/BFF
CPU pp | Driver/BFF RSS MiB | Driver/BFF heap MiB |
|---|---:|---:|---:|---:|---:|---:|
| idle | -0.006 / -0.019 | -0.066 / -0.047 | +0.001 / +0.003 | +0.001 /
-0.003 | +0.182 / -0.441 | -0.256 / -0.246 |
| steady | +0.024 / +0.023 | +0.609 / +0.152 | +0.199 / +0.160 | -0.036
/ -0.064 | -0.193 / -0.234 | -0.122 / -0.153 |
| reconnect | +0.028 / +0.042 | -0.008 / -1.789 | +0.867 / +0.362 |
+0.065 / +0.035 | +2.547 / +1.898 | +0.102 / -0.421 |
| slow_reader | +0.033 / +0.054 | -0.543 / -1.629 | -2.135 / -2.589 |
+0.176 / +0.115 | -1.117 / -0.738 | -0.330 / -0.324 |
| write_failure | -0.012 / +0.002 | +1.699 / +0.465 | +4.755 / +4.209 |
+0.149 / +0.052 | -2.094 / -0.227 | -1.003 / -0.220 |
| pool_contention | +0.007 / +0.003 | +2.262 / +4.164 | +2.194 / +5.397
| +0.006 / +0.035 | +0.160 / -0.027 | +0.131 / -0.203 |
| governor | -0.015 / -0.018 | +2.377 / +4.508 | +2.590 / +5.567 |
+0.022 / +0.055 | +0.727 / +0.465 | +0.134 / -0.238 |
| report | -0.011 / -0.016 | -0.070 / -0.219 | +0.333 / +1.286 | -0.035
/ -0.019 | -0.668 / -0.133 | +0.445 / +0.760 |
| log_export | +0.013 / +0.006 | +0.059 / +0.004 | +1.252 / +1.547 |
+0.108 / +0.107 | +4.568 / +3.586 | +4.106 / +4.007 |

</details>

<details><summary>Per-pair deltas, every reported process and
metric</summary>

| Phase | Metric | Pair 1 AB | Pair 2 BA | Pair 3 AB | Pair 4 BA
(flagged) |
|---|---|---:|---:|---:|---:|
| idle | gateway.cpuPp | +0.041 | -0.003 | -0.029 | +0.054 |
| idle | worker.cpuPp | +0.007 | -0.019 | -0.035 | +0.016 |
| idle | postgres.cpuPp | +0.004 | +0.002 | +0.002 | -0.001 |
| idle | driverBff.cpuPp | +0.012 | -0.005 | -0.003 | +0.004 |
| idle | driverBff.rssMiB | -0.914 | +0.805 | -0.441 | +0.848 |
| idle | driverBff.heapMiB | -0.266 | -0.149 | -0.246 | -0.357 |
| idle | total.cpuPp | +0.063 | -0.025 | -0.064 | +0.073 |
| idle | gateway.rssMiB | +0.078 | +0.223 | +1.473 | +1.820 |
| idle | worker.rssMiB | -0.039 | -0.047 | -0.086 | -0.207 |
| idle | gateway.heapMiB | -0.107 | +0.162 | +0.133 | +0.408 |
| idle | worker.heapMiB | +0.003 | +0.003 | -0.002 | -0.000 |
| steady | gateway.cpuPp | +0.153 | -0.188 | +0.016 | +0.103 |
| steady | worker.cpuPp | +0.023 | +0.068 | -0.035 | +0.025 |
| steady | postgres.cpuPp | -0.051 | -0.012 | -0.170 | -0.133 |
| steady | driverBff.cpuPp | +0.278 | -0.089 | -0.064 | -0.007 |
| steady | driverBff.rssMiB | -1.316 | -0.152 | -0.234 | +0.883 |
| steady | driverBff.heapMiB | -0.348 | -0.077 | -0.153 | -0.092 |
| steady | total.cpuPp | +0.404 | -0.221 | -0.252 | -0.012 |
| steady | gateway.rssMiB | -12.125 | -0.629 | +1.688 | +1.199 |
| steady | worker.rssMiB | +0.152 | -1.660 | +1.066 | +1.398 |
| steady | gateway.heapMiB | -0.865 | +0.662 | -0.144 | -0.271 |
| steady | worker.heapMiB | +0.160 | -0.305 | +0.914 | +0.238 |
| steady | rpc.p95Ms | -0.438 | -0.293 | +0.001 | +0.674 |
| steady | rpc.p95Percent | -13.310 | -8.070 | +0.029 | +24.274 |
| steady | history.p95Ms | -2.277 | -0.472 | +4.313 | +3.000 |
| reconnect | gateway.cpuPp | -0.027 | -0.242 | +0.073 | -0.022 |
| reconnect | worker.cpuPp | +0.053 | +0.042 | +0.013 | -0.137 |
| reconnect | postgres.cpuPp | +0.125 | +0.059 | -0.018 | +0.108 |
| reconnect | driverBff.cpuPp | +0.142 | -0.020 | +0.035 | +0.095 |
| reconnect | driverBff.rssMiB | -0.508 | +1.898 | +3.195 | +3.352 |
| reconnect | driverBff.heapMiB | -0.421 | +0.625 | -1.013 | +0.769 |
| reconnect | total.cpuPp | +0.293 | -0.161 | +0.103 | +0.045 |
| reconnect | gateway.rssMiB | -0.168 | +2.512 | +1.383 | -9.902 |
| reconnect | worker.rssMiB | +1.773 | -7.203 | -1.789 | +8.039 |
| reconnect | gateway.heapMiB | +0.336 | +0.857 | -0.217 | +0.992 |
| reconnect | worker.heapMiB | +1.373 | -9.732 | +0.362 | +10.010 |
| reconnect | rpc.p95Ms | -0.291 | -0.052 | +0.516 | +0.671 |
| reconnect | rpc.p95Percent | -10.784 | -1.948 | +20.398 | +24.062 |
| reconnect | history.p95Ms | +3.040 | +0.200 | -2.134 | -2.085 |
| slow_reader | gateway.cpuPp | +0.183 | +0.118 | -0.025 | +0.217 |
| slow_reader | worker.cpuPp | +0.086 | +0.001 | +0.054 | +0.012 |
| slow_reader | postgres.cpuPp | -0.033 | -0.083 | -0.409 | -0.144 |
| slow_reader | driverBff.cpuPp | +0.242 | +0.106 | +0.115 | +0.237 |
| slow_reader | driverBff.rssMiB | -0.738 | +0.707 | -3.344 | -1.496 |
| slow_reader | driverBff.heapMiB | -0.445 | -0.018 | -0.324 | -0.336 |
| slow_reader | total.cpuPp | +0.478 | +0.141 | -0.265 | +0.322 |
| slow_reader | gateway.rssMiB | +4.973 | +21.238 | -11.492 | -1.734 |
| slow_reader | worker.rssMiB | -1.629 | +0.543 | -3.004 | +1.605 |
| slow_reader | gateway.heapMiB | +3.316 | +11.428 | -9.515 | +10.479 |
| slow_reader | worker.heapMiB | -2.589 | +4.198 | -6.769 | -1.681 |
| slow_reader | rpc.p95Ms | -1.766 | -0.355 | -0.895 | +0.385 |
| slow_reader | rpc.p95Percent | -42.127 | -8.158 | -19.343 | +9.860 |
| slow_reader | history.p95Ms | -2.356 | -8.044 | +0.413 | -5.779 |
| write_failure | gateway.cpuPp | +0.115 | +0.235 | -0.088 | +0.133 |
| write_failure | worker.cpuPp | +0.095 | +0.002 | -0.026 | -0.069 |
| write_failure | postgres.cpuPp | +0.061 | +0.059 | -0.046 | -0.011 |
| write_failure | driverBff.cpuPp | +0.052 | +0.029 | +0.343 | +0.247 |
| write_failure | driverBff.rssMiB | -0.227 | -0.223 | -5.363 | -3.961 |
| write_failure | driverBff.heapMiB | -0.220 | -0.127 | -1.786 | -1.906
|
| write_failure | total.cpuPp | +0.322 | +0.325 | +0.183 | +0.300 |
| write_failure | gateway.rssMiB | -3.551 | +14.039 | +2.094 | -6.078 |
| write_failure | worker.rssMiB | -2.848 | +0.465 | +8.070 | +2.934 |
| write_failure | gateway.heapMiB | +0.905 | +4.019 | +0.649 | -0.768 |
| write_failure | worker.heapMiB | -8.781 | +4.209 | +10.713 | +5.301 |
| write_failure | rpc.p95Ms | +0.153 | -0.076 | +0.175 | +0.275 |
| write_failure | rpc.p95Percent | +6.064 | -2.411 | +5.466 | +9.490 |
| write_failure | history.p95Ms | +2.001 | +5.788 | -4.282 | +2.557 |
| pool_contention | gateway.cpuPp | -0.095 | +0.364 | +0.061 | +0.009 |
| pool_contention | worker.cpuPp | -0.035 | +0.010 | +0.003 | +0.013 |
| pool_contention | postgres.cpuPp | -0.188 | +0.025 | +0.026 | -0.097 |
| pool_contention | driverBff.cpuPp | +0.035 | -0.071 | +0.096 | -0.024
|
| pool_contention | driverBff.rssMiB | +0.492 | -0.027 | -0.398 | +0.348
|
| pool_contention | driverBff.heapMiB | -0.294 | -0.203 | +0.585 |
+0.466 |
| pool_contention | total.cpuPp | -0.283 | +0.328 | +0.187 | -0.099 |
| pool_contention | gateway.rssMiB | +2.266 | -12.020 | +0.297 | -0.605
|
| pool_contention | worker.rssMiB | +4.578 | +4.164 | -3.941 | +0.359 |
| pool_contention | gateway.heapMiB | -4.728 | -15.253 | -1.269 | +1.475
|
| pool_contention | worker.heapMiB | +14.064 | +5.397 | -6.205 | -1.009
|
| pool_contention | rpc.p95Ms | -0.202 | -0.304 | +0.072 | -1.128 |
| pool_contention | rpc.p95Percent | -5.232 | -8.985 | +1.890 | -30.891
|
| pool_contention | history.p95Ms | -6.037 | +6.568 | +1.054 | -14.428 |
| governor | gateway.cpuPp | -0.322 | -0.041 | -0.023 | +0.011 |
| governor | worker.cpuPp | -0.023 | +0.000 | -0.018 | -0.012 |
| governor | postgres.cpuPp | -0.010 | +0.021 | -0.094 | +0.087 |
| governor | driverBff.cpuPp | +0.055 | +0.056 | -0.084 | -0.011 |
| governor | driverBff.rssMiB | +0.465 | +1.035 | -1.727 | +0.988 |
| governor | driverBff.heapMiB | -0.481 | -0.238 | +0.572 | +0.506 |
| governor | total.cpuPp | -0.300 | +0.036 | -0.220 | +0.074 |
| governor | gateway.rssMiB | +31.313 | +7.004 | +12.328 | -12.113 |
| governor | worker.rssMiB | +0.246 | +4.508 | +8.816 | -1.438 |
| governor | gateway.heapMiB | +31.634 | +8.395 | +3.813 | -8.002 |
| governor | worker.heapMiB | -3.118 | +5.567 | +13.482 | -0.387 |
| governor | rpc.p95Ms | +0.641 | +0.048 | +0.301 | +0.160 |
| governor | rpc.p95Percent | +27.310 | +1.755 | +11.164 | +4.372 |
| governor | history.p95Ms | -7.450 | -18.052 | +0.713 | -0.204 |
| report | gateway.cpuPp | +0.248 | +0.040 | +0.105 | -0.456 |
| report | worker.cpuPp | -0.016 | -0.006 | -0.018 | +0.015 |
| report | postgres.cpuPp | +0.018 | +0.087 | +0.068 | +0.115 |
| report | driverBff.cpuPp | +0.159 | -0.019 | -0.102 | -0.052 |
| report | driverBff.rssMiB | -0.133 | +3.406 | -1.203 | -1.742 |
| report | driverBff.heapMiB | +0.129 | +1.506 | +0.760 | -1.316 |
| report | total.cpuPp | +0.409 | +0.103 | +0.054 | -0.378 |
| report | gateway.rssMiB | +6.633 | +10.074 | +4.633 | -9.980 |
| report | worker.rssMiB | +8.137 | -7.145 | -0.219 | +0.078 |
| report | gateway.heapMiB | +4.687 | +10.820 | +0.903 | -7.223 |
| report | worker.heapMiB | +12.229 | -13.792 | +1.286 | -0.620 |
| report | rpc.p95Ms | +0.206 | -0.741 | +0.019 | -0.136 |
| report | rpc.p95Percent | +7.681 | -26.205 | +0.729 | -4.746 |
| report | history.p95Ms | -1.606 | -0.153 | +2.184 | +0.344 |
| log_export | gateway.cpuPp | +0.843 | +0.786 | +0.971 | +0.491 |
| log_export | worker.cpuPp | +0.006 | -0.023 | +0.020 | +0.046 |
| log_export | postgres.cpuPp | +0.053 | -0.057 | -0.083 | -0.016 |
| log_export | driverBff.cpuPp | +0.004 | +0.107 | +0.109 | +0.110 |
| log_export | driverBff.rssMiB | +3.586 | +5.551 | +1.031 | +6.266 |
| log_export | driverBff.heapMiB | +4.205 | +4.007 | +2.770 | +5.354 |
| log_export | total.cpuPp | +0.906 | +0.814 | +1.016 | +0.631 |
| log_export | gateway.rssMiB | +1.934 | +1.234 | +7.273 | +4.184 |
| log_export | worker.rssMiB | -2.262 | +0.113 | +0.004 | +3.574 |
| log_export | gateway.heapMiB | +2.228 | -1.995 | +2.073 | +7.766 |
| log_export | worker.heapMiB | -3.744 | +1.547 | +2.134 | +0.957 |
| log_export | rpc.p95Ms | -0.080 | -0.424 | +0.262 | -0.386 |
| log_export | rpc.p95Percent | -3.156 | -14.177 | +10.368 | -14.516 |
| log_export | history.p95Ms | -0.290 | -3.568 | +1.943 | -3.835 |

</details>

Four B log actions downloaded checksum-verified **partial** archives,
3,961,767–3,961,926 bytes each, in 14.822–15.410 s; median duration
**14.925 s**. All A actions returned disabled. The explicit export phase
averages CPU across 90 s; it is separate from ordinary background
collection. A short export-only A/B smoke passed before the full run.

Preserved excluded recordings: the first attempt aborted because the
driver read a child-only diagnostics flag when validating B; the harness
now reads its own member flag. The next attempt completed two accepted
pairs, then received SIGTERM during pair 3 (no scope-swap or host-gate
violations). After confirmation that nobody intentionally stopped it,
the entire stage was rerun through **setsid + nohup**, PID file and
controller log, because the launcher has no resume mode. Only the four
complete pairs from that detached recording enter the medians above; the
earlier two are kept as additional evidence, not pooled.

Evidence (uncommitted):
`/var/tmp/canopy-diagnostics-5/window-20261112-detached/{head.txt,results.jsonl,paired-report.json,stderr.log,controller.log,controller.pid}`.
Raw deltas and every joint-rule flag remain in paired-report.json.
Measurements are complete; **CPU, p95 and memory accepted by the
maintainer on 2026-11-12**, as recorded above. All PRs remain drafts.

The driver-flag harness fix passed scripts typecheck, repository lint
and format checks; the export-only A/B smoke then verified disabled A
and checksum-verified partial B before the detached full recording.
Product code and native fingerprints did not change.


## Whole-stack QA correction — 2026-11-12

The live log collector emitted versioned gateway and UUID-shaped worker
startup/link lines which the template allowlist omitted. Recognize those
closed runtime templates, then emit only primitive
timestamp/source/event/legacy fields. The original line, version, worker
ID, address, path, SQL and parameters still never enter the exported
records. The existing security test now includes actual runtime-shaped
startup/link messages: **8 tests / 50 assertions passed**, with a clean
temporary directory. Downloading through the browser then produced a
valid partial ZIP containing five sanitized gateway events and explicit
unavailable/omitted source coverage.

Manual QA covered collection progress, partial/offline/unsupported
sources, retry and ZIP download at desktop/narrow/phone widths in
light/dark, including long names. Install, gen:check, full typecheck,
lint, format:check and web build passed. Copy audit: no new UI copy; the
existing privacy and missing-source notices remain accurate. Evidence is
in `/var/tmp/canopy-diagnostics-6/qa/` (uncommitted). Native mobile
Share/SAF interactions were not exercised by this browser run.

## Maintainer acceptance — 2026-11-12

Stages 4 (#569) and 5 (#572) are accepted for CPU, RPC p95 and memory.
The maintainer accepted the measured cumulative stages 2–5 memory
difference: about **+5 MiB idle**, **+5–12 MiB under typical load**, and
about **+15 MiB worst case during governor load**. Existing A/B results
are preserved. No further memory investigation, bounded-memory re-tests,
A/A controls or full A/B runs are required for this acceptance. The
entire diagnostics stack remains draft and will merge together after
stage 6 is accepted.
nixuuu added a commit that referenced this pull request Nov 13, 2026
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.
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