Files
cindy/scripts/device-link
Dash c584982c5f feat(device-link): compress pushes with a preset-dictionary deflate (push-deflate-v1)
Pushes from the controlled desktop (maker:event batches, messages:created,
status) were always plain JSON; only invoke results >= 4 KB were gzipped.

- Controllers with a synchronous inflateRawBase64 codec declare
  push-deflate-v1 in link-open. The host encodes pushes of 256 B..512 KiB
  for same-account reliable peers that declared it (link not explicitly
  closed): raw DEFLATE level 4 primed with PUSH_TRANSFER_DICTIONARY_V1
  (field names / enum values only, printable ASCII, guarded at load),
  base64, kept only when >= 10% smaller than the escaped wire form.
  channel and ownerStamp stay plain so reliable-queue drop/coalesce rules
  are unchanged. The 512 KiB cap keeps the existing oversize fallback and
  bounds synchronous inflate on the controller.
- Every push is independently decodable (no cross-message state), decoded
  synchronously at emitFrame so delivery order is preserved. An
  undecodable push is treated like a handler failure (not acknowledged),
  and the controller stops declaring the capability to that peer, so the
  existing reset/re-link/resync path recovers with plain pushes.
- Capability follows only the latest inbound link-open; a downgraded peer,
  an outbound accept showing a restarted peer, or an accept without a
  matching offer stops encoding and turns queued compressed pushes into
  transport skip placeholders (sent now when the link can send).
- Desktop/Node Host use Node zlib (separate "push deflate summary" debug
  stats, cached dictionary bytes); Mobile uses existing pako on the JS
  thread (no native change). Relays forward push frames unchanged; interop
  now asserts a compressed push crosses a real self-hosted relay with
  device signatures.

Measured with pnpm transfer:baseline over all stages (wire bytes without
ACKs), together with transport-ack-v2 and the 1 KiB invoke gzip threshold
of this series and without the other transfer changes: phone downlink
-17.4%, desktop downlink -22.1% excluding the 1 MiB running-result stage.

Test value
- Production entry / observable result: DeviceLinkClient.sendPush ->
  MemoryRelay -> controller onFrame; wire shape per peer capability,
  delivered payload/order identical; Mobile pako decodes Node output.
- Rule: protocol-compatibility/device-link-push-deflate.md (old peers unchanged,
  downgrade safety, shared dictionary bytes, no silent gaps).
- Gap: new protocol behaviour, no existing coverage.
- Minimal failing input: encoding without capability check, capability not
  reset on re-open / outbound restart, no size cap, no skip retirement, or
  re-declaring after a decode failure (each mutation verified red).
- Tier: unit (in-memory relay); interop covers the real relay.
- Time: client.test.ts push cases ~0.3 s; gzipBase64.test.ts ~0.03 s.

Assisted-by: Cindy (https://cindy.app)
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
2026-11-11 21:04:43 +13:00
..