release(v4.0.0): Shade GA — V3.x consolidation + audit prep
Some checks failed
Test / test (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled

V3.1 → V3.12 consolidated and tagged for the first GA release. Wire
format unchanged from 0.4.x — 4.0 peers interoperate with 0.4.x peers
byte-for-byte. The version bump is semantic: audit-cycle complete,
opt-in surface fully exposed, threat model refreshed for every new
surface.

Highlights:
- All 24 @shade/* packages bumped to 4.0.0 in lockstep.
- CHANGELOG 4.0.0 section is the canonical manifest of what landed.
- THREAT-MODEL extended (§10 fingerprint gates, §11 WebRTC P2P, §12
  Web-Worker boundary) + residual-risks table refreshed.
- OpenAPI now covers all 27 routes: prekey, transfer, KT, inbox,
  bridge, observer, /metrics, /healthz, /ready.
- MIGRATION 0.3.x → 4.0 documented + smoke-tested against
  shade migrate-storage on a real SQLite DB.
- docs/audit/REVIEW-BUNDLE.md + SCOPE.md ready for external reviewer.
- scripts/soak.ts harness for the GA-stable 2-week soak window.
- All V*.md plans archived under docs/archive/ with Status: Done.
- Voice/Video carved out into V5.0; 4.0 audit focuses on the frozen
  non-realtime stack.

Tests: TS 1000/1000 + Kotlin 11/11 cross-platform vectors green.
Docker: gt.zyon.no/stian/shade-prekey:4.0.0 builds and reports
  version 4.0.0 on /health.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-03 18:35:35 +02:00
parent 8b055912b7
commit e6fdf31b49
298 changed files with 37909 additions and 256 deletions

View File

@@ -19,6 +19,22 @@ import {
type StreamMetadata,
} from '@shade/streams';
import { decodeStreamChunk, inspectEnvelopeType } from '@shade/proto';
import {
ATTR_BYTES_BIN,
ATTR_DIRECTION,
ATTR_ERROR_CODE,
ATTR_LANE_COUNT,
ATTR_PARTITION,
ATTR_PEER_HASH,
ATTR_RESULT,
ATTR_RETRY_COUNT,
bytesBin,
laneCountBin,
NOOP_HOOK,
peerHash,
type ObservabilityHook,
type Span,
} from '@shade/observability';
import {
TransferAbortError,
TransferIntegrityError,
@@ -72,6 +88,12 @@ export interface TransferEngineDeps {
* random per-process key).
*/
deviceKey?: Uint8Array;
/**
* Optional observability hook. Spans are emitted for each upload and for
* each accepted incoming transfer. Defaults to a no-op when omitted.
* Use `withTracer()` from `@shade/observability` to plug in OTel.
*/
observability?: ObservabilityHook;
}
/**
@@ -90,8 +112,10 @@ export class TransferEngine {
>();
private readonly unsubscribeControl: () => void;
private readonly persister: Persister | null;
private readonly observability: ObservabilityHook;
constructor(private readonly deps: TransferEngineDeps) {
this.observability = deps.observability ?? NOOP_HOOK;
this.persister =
deps.resumeStore !== undefined
? new Persister(deps.crypto, deps.resumeStore, deps.deviceKey)
@@ -172,6 +196,13 @@ export class TransferEngine {
opts.onProgress,
opts.onEvent,
);
state.span = this.observability.startSpan('shade.transfer.upload', {
[ATTR_DIRECTION]: 'upload',
[ATTR_PEER_HASH]: peerHash(opts.to),
[ATTR_BYTES_BIN]: bytesBin(input.size ?? 0),
[ATTR_LANE_COUNT]: laneCountBin(lanes.length),
[ATTR_PARTITION]: partitionMode,
});
this.outgoing.set(streamId, state);
// Persist initial resume state BEFORE sending init, so a crash before
@@ -308,6 +339,13 @@ export class TransferEngine {
opts?.onProgress,
opts?.onEvent,
);
state.span = this.observability.startSpan('shade.transfer.upload.resume', {
[ATTR_DIRECTION]: 'upload',
[ATTR_PEER_HASH]: peerHash(peer),
[ATTR_BYTES_BIN]: bytesBin(input.size ?? metadata.sizeBytes ?? 0),
[ATTR_LANE_COUNT]: laneCountBin(lanes.length),
[ATTR_PARTITION]: partitionMode,
});
// Mark already-shipped lanes as having advanced.
for (const lane of lanes) {
const lp = (state as unknown as { laneProgress: Map<number, LaneProgress> }).laneProgress.get(
@@ -615,6 +653,13 @@ export class TransferEngine {
if (opts.onProgress !== undefined) state.onProgress = opts.onProgress;
if (opts.onEvent !== undefined) state.onEvent = opts.onEvent;
state.startedAt = nowMs();
state.span = this.observability.startSpan('shade.transfer.download', {
[ATTR_DIRECTION]: 'download',
[ATTR_PEER_HASH]: peerHash(from),
[ATTR_BYTES_BIN]: bytesBin(msg.metadata.sizeBytes ?? 0),
[ATTR_LANE_COUNT]: laneCountBin(msg.lanes.length),
[ATTR_PARTITION]: msg.lanes[0]?.partition.kind ?? 'unknown',
});
state.emit({ type: 'start', streamId: msg.streamId });
return state.handle;
},
@@ -843,6 +888,8 @@ interface ChunkJob {
class OutgoingState {
startedAt = -1;
aborted = false;
span: Span | null = null;
private retryCount = 0;
private completedAt = -1;
private resolveDone!: (result: TransferResult) => void;
private rejectDone!: (err: unknown) => void;
@@ -942,6 +989,16 @@ class OutgoingState {
this.completedAt = nowMs();
this.emit({ type: 'complete', streamId: result.streamId, sha256: result.sha256, durationMs: result.durationMs });
this.flushEventEnd();
if (this.span !== null) {
this.span.setAttributes({
[ATTR_RESULT]: 'ok',
[ATTR_BYTES_BIN]: bytesBin(result.bytesSent),
[ATTR_RETRY_COUNT]: this.retryCount,
});
this.span.setStatus('ok');
this.span.end();
this.span = null;
}
this.resolveDone(result);
void this.input.close();
this.sender.destroy();
@@ -952,6 +1009,18 @@ class OutgoingState {
this.aborted = true;
this.emit({ type: 'error', error: err });
this.flushEventEnd();
if (this.span !== null) {
const code = errorCodeOf(err);
this.span.setAttributes({
[ATTR_RESULT]: 'error',
[ATTR_ERROR_CODE]: code,
[ATTR_RETRY_COUNT]: this.retryCount,
});
this.span.recordException(err);
this.span.setStatus('error', code);
this.span.end();
this.span = null;
}
try {
await this.input.close();
} catch {
@@ -961,6 +1030,10 @@ class OutgoingState {
this.rejectDone(err);
}
recordRetry(): void {
this.retryCount++;
}
private flushEventEnd(): void {
for (const r of this.eventResolvers) r({ value: undefined as never, done: true });
this.eventResolvers = [];
@@ -990,6 +1063,7 @@ class IncomingState {
startedAt = -1;
accepted = false;
declined = false;
span: Span | null = null;
sink: OutputSink | null = null;
outputKind: 'pipe' | 'callback' | 'buffer' | 'file' | 'fileHandle' | undefined;
onProgress: ((p: TransferProgress) => void) | undefined;
@@ -1224,6 +1298,15 @@ class IncomingState {
this.completedAt = nowMs();
this.emit({ type: 'complete', streamId: result.streamId, sha256: result.sha256, durationMs: result.durationMs });
this.flushEventEnd();
if (this.span !== null) {
this.span.setAttributes({
[ATTR_RESULT]: 'ok',
[ATTR_BYTES_BIN]: bytesBin(result.bytesSent),
});
this.span.setStatus('ok');
this.span.end();
this.span = null;
}
this.resolveDone(result);
this.receiver.destroy();
}
@@ -1234,6 +1317,15 @@ class IncomingState {
if (this.sink !== null) await this.sink.abort(reason);
this.emit({ type: 'abort', reason });
this.flushEventEnd();
if (this.span !== null) {
this.span.setAttributes({
[ATTR_RESULT]: 'abort',
[ATTR_ERROR_CODE]: 'SHADE_TRANSFER_ABORT',
});
this.span.setStatus('error', reason);
this.span.end();
this.span = null;
}
this.receiver.destroy();
this.rejectDone(new TransferAbortError(reason));
}
@@ -1253,6 +1345,17 @@ class IncomingState {
this.aborted = true;
this.emit({ type: 'error', error: err });
this.flushEventEnd();
if (this.span !== null) {
const code = errorCodeOf(err);
this.span.setAttributes({
[ATTR_RESULT]: 'error',
[ATTR_ERROR_CODE]: code,
});
this.span.recordException(err);
this.span.setStatus('error', code);
this.span.end();
this.span = null;
}
if (this.sink !== null) await this.sink.abort('integrity-failure');
this.receiver.destroy();
this.rejectDone(err);
@@ -1357,6 +1460,17 @@ function nowMs(): number {
return typeof performance !== 'undefined' ? performance.now() : Date.now();
}
function errorCodeOf(err: unknown): string {
if (err === null || err === undefined) return 'SHADE_UNKNOWN';
if (typeof err === 'object') {
const code = (err as { code?: unknown }).code;
if (typeof code === 'string' && code.length > 0) return code;
const name = (err as { name?: unknown }).name;
if (typeof name === 'string' && name.startsWith('Transfer')) return `SHADE_${name}`;
}
return 'SHADE_UNKNOWN';
}
// ─── Persister ───────────────────────────────────────────────
class Persister {