@wildshard/shard-format 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -52,25 +52,26 @@ const BASE_LEVEL = 1
52
52
  // Chromium capture (04d76bcf). The calibrated increment rounds to 168 MB.
53
53
  const SHADER_COMPILE_BYTES = 168_000_000
54
54
  const MB = 1_000_000
55
- const ENGINE_PLAYING_BYTES = 696_764_000
56
- const ENGINE_LOADING_BYTES = 982_344_000
57
- /** MG6 epoch 5 (mini-em11b, 2026-11-18): the estimate is ENGINE-MEMORY EM11's phone chain (engine
58
- * `scripts/memory/phone-model.json`, refit on readings without the Web Inspector's Network retention: native WebKit [K]
59
- * of the WebContent and GPU processes through alpha or scale to an iPhone 17 Pro's WebContent, at the 2048 MiB
60
- * ActiveHard line). Each weight is phone bytes per product byte, fitted so that every pinned product's estimate is at or
61
- * over the upper bound of EM11's error bar on its cold runs (engine `037d9f15`, Mac mini, phone Low;
62
- * `memory-calibration.golden.json` holds the pairs), with each verdict kept at the 1.0 GB playing envelope and the 1.5 GB
63
- * loading line except Pine's loading (memory-calibration.test.ts says why). The fit is minimax, then least
64
- * total overshoot; the content weight is held at 0.5 settled and 0.8 loading at least, so bytes a boot downloads and
65
- * decodes always count. The terms count only the files a phone fetches (`phoneInactiveFiles`). The engine term is
66
- * Template's bound raised to cover Sunscar Dunes, whose held bitmaps outweigh its terms; refit it when the engine's own
67
- * boot gets cheaper. Epoch 4 (`6b432a2a` readings) read Pine at 1.46x its clean bound and Dunes under it. */
55
+ const ENGINE_PLAYING_BYTES = 730_889_000
56
+ const ENGINE_LOADING_BYTES = 968_046_000
57
+ /** MG6 epoch 7 (mini-em11c, 2026-11-18; epoch 6 mini-sweep): the estimate is ENGINE-MEMORY EM11's phone chain (engine
58
+ * `scripts/memory/phone-model.json`, read without the Web Inspector's Network retention: native WebKit [K] of the
59
+ * WebContent and GPU processes through alpha or scale to an iPhone 17 Pro's WebContent, at the 2048 MiB ActiveHard line).
60
+ * The terms are the product's alone; the engine term and every weight are what one engine build does with them, so the
61
+ * estimate follows the engine only through a sweep and a refit: `memory-calibration.em11.json` names the build (engine
62
+ * `50092092`, 99 cold runs, 6 per heavy zone), `memory-fit.mjs` fits this block from it and the golden pairs it. Each
63
+ * weight is phone bytes per product byte, fitted so that every pinned product's estimate is at or over the upper bound
64
+ * of EM11's error bar over its cold runs (engine `upperOverRuns`, the 90% prediction bound on one more cold boot;
65
+ * epoch 6 used the highest run's), with each verdict kept at the 1.0 GB playing envelope and the 1.5 GB loading
66
+ * line. The fit is minimax, then least total overshoot; the content weight is held at 0.5 settled and 0.8 loading at
67
+ * least, so bytes a boot downloads and decodes always count. The terms count only the files a phone fetches
68
+ * (`phoneInactiveFiles`). Refit at every engine release, and after a memory cut that should reach the gates. */
68
69
  const PHONE = {
69
70
  engine: { playing: ENGINE_PLAYING_BYTES, loading: ENGINE_LOADING_BYTES },
70
71
  content: { playing: 0.5, loading: 0.8 },
71
- textures: { playing: 1.46099, loading: 1.786 },
72
- gl: { playing: 1.771, loading: 1.349 },
73
- geometry: { playing: 0, loading: 1.977 },
72
+ textures: { playing: 0.8518, loading: 2.2277 },
73
+ gl: { playing: 2.1475, loading: 1.8758 },
74
+ geometry: { playing: 0, loading: 0.7399 },
74
75
  /** A runtime home never reads under its own Simulator reading settled, nor under it times EM11's lowest peak over
75
76
  * settled (1.257) while loading. No pinned home binds here today; it stops a heavy runtime with light files. */
76
77
  runtime: { playing: 1, loading: 1.26 },
@@ -1,12 +1,16 @@
1
+ import { staleReadingAdmitted } from './memory-ratchet.ts'
2
+
1
3
  /** MEMORY-GATES MG5 (J408, Jake 2026-11-17: "a stale runtimeCost is refused"): the memory model a runtime home's
2
4
  * `runtimeCost` reading must have been taken against. It rises when the model changes what it charges (MG6 adds shader
3
5
  * compile, load transients, far slabs and paint arrays); from then a reading from an older epoch is refused until the
4
6
  * shard re-measures. A reading with no `epoch` is epoch 1, the model before MG6. */
5
- const MEMORY_EPOCH = 5
7
+ const MEMORY_EPOCH = 7
6
8
  /** MG6 epoch 4 (mini-estcal2) changed how the estimate converts a reading (EM11's chain), not how a reading is taken:
7
9
  * epoch 3's paired Simulator WebContent + GL protocol stands, so a reading from epoch 3 on is current. Epoch 5
8
10
  * (mini-em11b) refits that conversion to EM11 read without the Web Inspector's Network retention and counts only the
9
- * files a phone fetches; readings are still taken as in epoch 3. */
11
+ * files a phone fetches; epoch 6 (mini-sweep) refits it to an every-zone sweep on engine `50092092`; epoch 7 (mini-em11c) refits
12
+ * it to the same sweep read with EM11's 90% prediction bound over runs in place of the highest run. Readings are still
13
+ * taken as in epoch 3. */
10
14
  const OLDEST_CURRENT_EPOCH = 3
11
15
  const LEGACY_EPOCH = 1
12
16
 
@@ -19,7 +23,7 @@ interface StaleRuntimeIssue {
19
23
  readonly metric: string
20
24
  readonly actual: number
21
25
  readonly limit: number
22
- readonly severity: 'refusal'
26
+ readonly severity: 'refusal' | 'warning'
23
27
  }
24
28
 
25
29
  /** Why a runtime reading is stale, older than `current` (the oldest current epoch), or empty when it is current. */
@@ -35,11 +39,14 @@ function staleRuntimeCost(
35
39
  }
36
40
 
37
41
  /** A refusal, whatever the policy, for a runtime home's reading and for its images-first reading, each stale against
38
- * `current`. Takes the shard's `runtime` (null for a data-only shard). */
42
+ * `current`. Takes the shard's `runtime` (null for a data-only shard). J412: a report instead for exactly the pinned
43
+ * revision the ratchet names (`memory-ratchet.ts` `staleRevision`), given its `identity`. */
39
44
  function staleRuntimeIssues(
40
45
  runtime: Readonly<{ cost?: EpochRow | undefined }> | null,
41
46
  current: number = OLDEST_CURRENT_EPOCH,
47
+ identity?: Readonly<{ slug: string; revision: number }>,
42
48
  ): StaleRuntimeIssue[] {
49
+ const admitted = staleReadingAdmitted(identity?.slug, identity?.revision)
43
50
  const rows: EpochRow[] = []
44
51
  const cost = runtime === null ? undefined : runtime.cost
45
52
  if (cost !== undefined) {
@@ -52,10 +59,10 @@ function staleRuntimeIssues(
52
59
  .filter((row: EpochRow): boolean => staleRuntimeCost(row, current) !== '')
53
60
  .map((row: EpochRow): StaleRuntimeIssue => ({
54
61
  code: 'perf-native-resident-unmeasured',
55
- metric: staleRuntimeCost(row, current),
62
+ metric: `${staleRuntimeCost(row, current)}${admitted ? ' (report-only, J412 ratchet: the pinned revision)' : ''}`,
56
63
  actual: row.epoch ?? LEGACY_EPOCH,
57
64
  limit: current,
58
- severity: 'refusal',
65
+ severity: admitted ? 'warning' : 'refusal',
59
66
  }))
60
67
  }
61
68
 
@@ -2,6 +2,7 @@ import { parse } from 'valibot'
2
2
 
3
3
  import { bootMemoryCosts } from './boot-memory-cost.ts'
4
4
  import { worstContentCost } from './budget.ts'
5
+ import { ratchetNote, ratchetSeverity } from './memory-ratchet.ts'
5
6
  import { runtimeAccountedBytes, RuntimeCostSchema } from './runtimeCost.ts'
6
7
 
7
8
  import type { TierIndex } from './phone-files.ts'
@@ -23,23 +24,29 @@ function overHardLine(bytes: number): string {
23
24
  return ` (over the ${(MEMORY_HARD_BYTES / GB).toFixed(DIGITS)} GB phone line, J408: a phone would close the page)`
24
25
  }
25
26
 
26
- /** J408 (MG4): the refusal for a worst-playing or loading estimate over the hard line. */
27
+ /** J408 (MG4): the issue for a worst-playing or loading estimate over the hard line. J412: a refusal only over the
28
+ * zone's ratchet baseline (`memory-ratchet.ts`); at or under it, a report. */
27
29
  function hardLineIssue(
28
30
  kind: 'playing' | 'loading',
29
31
  bytes: number,
32
+ slug?: string,
30
33
  ): {
31
34
  readonly code: 'perf-playing-memory' | 'perf-loading-memory'
32
35
  readonly metric: string
33
36
  readonly actual: number
34
37
  readonly limit: number
35
- readonly severity: 'refusal'
38
+ readonly severity: 'refusal' | 'warning'
36
39
  } {
40
+ const severity = ratchetSeverity(slug, kind, {
41
+ line: MEMORY_HARD_BYTES,
42
+ actual: bytes,
43
+ })
37
44
  return {
38
45
  code: `perf-${kind}-memory`,
39
- metric: `worst ${kind} total bytes${overHardLine(bytes)}`,
46
+ metric: `worst ${kind} total bytes${overHardLine(bytes)}${severity === 'warning' ? ratchetNote(slug, kind) : ''}`,
40
47
  actual: bytes,
41
48
  limit: MEMORY_HARD_BYTES,
42
- severity: 'refusal',
49
+ severity,
43
50
  }
44
51
  }
45
52
 
@@ -104,7 +111,7 @@ function offlineMemoryIssues(
104
111
  return (['playing', 'loading'] as const)
105
112
  .filter((kind): boolean => cost[kind] > MEMORY_HARD_BYTES)
106
113
  .map((kind): ReturnType<typeof hardLineIssue> =>
107
- hardLineIssue(kind, cost[kind]),
114
+ hardLineIssue(kind, cost[kind], source.identity.slug),
108
115
  )
109
116
  }
110
117
 
@@ -0,0 +1,105 @@
1
+ /**
2
+ * J411 / J412 (Jake, 2026-11-18): memory gates are ratchets. "With these new gates we should definitely be landing
3
+ * improvements even if they don't meet the new high standards." The J408 phone line (1.5 GB playing and loading), the
4
+ * OF10c1a runtime tier and the MG5 stale-reading check refuse a zone only when it is worse than its baseline here;
5
+ * at or under the baseline they report. A zone with no row keeps every refusing gate.
6
+ *
7
+ * Each baseline is the zone's reading on 2026-11-18 under memory epoch 7 (MEMORY-GATES MG8, mini-mg8): the largest of
8
+ * the engine-pinned product's estimates (admission and performance report) and the current source's, in decimal bytes. A cut ratchets the row down; a zone
9
+ * that passes a line loses that field, and the line refuses again. `staleRevision` is the pinned product's
10
+ * `identity.revision`: it admits that revision's pre-epoch-3 runtime reading; any later revision must carry a current one.
11
+ */
12
+ interface MemoryBaseline {
13
+ readonly playing?: number
14
+ readonly loading?: number
15
+ readonly runtime?: number
16
+ readonly staleRevision?: number
17
+ }
18
+
19
+ const MEMORY_RATCHET: Readonly<Record<string, MemoryBaseline>> = Object.freeze({
20
+ 'driftwood-isle': {
21
+ loading: 1_616_043_903,
22
+ runtime: 538_863_164,
23
+ staleRevision: 2,
24
+ },
25
+ 'nalati-grasslands': {
26
+ loading: 1_731_454_480,
27
+ runtime: 700_846_587,
28
+ staleRevision: 1,
29
+ },
30
+ 'nine-dragon-stack': {
31
+ playing: 1_530_989_917,
32
+ loading: 1_928_953_301,
33
+ runtime: 547_365_098,
34
+ staleRevision: 1,
35
+ },
36
+ 'pine-hollow': {
37
+ playing: 1_648_479_456,
38
+ loading: 1_982_254_656,
39
+ runtime: 550_909_717,
40
+ staleRevision: 1,
41
+ },
42
+ })
43
+
44
+ /** The estimate's run-to-run noise is zero (it is computed, not sampled); the allowance covers byte drift from a
45
+ * rebuild of the same source (compression, packing order). */
46
+ const RATCHET_ALLOWANCE = 0.005
47
+
48
+ type RatchetMetric = 'playing' | 'loading' | 'runtime'
49
+
50
+ /** The bytes over which `slug` refuses on `metric`: the line, or its baseline plus the allowance when that is higher. */
51
+ function ratchetLimit(
52
+ slug: string | undefined,
53
+ metric: RatchetMetric,
54
+ line: number,
55
+ ): number {
56
+ const baseline =
57
+ slug === undefined ? undefined : MEMORY_RATCHET[slug]?.[metric]
58
+ if (baseline === undefined) {
59
+ return line
60
+ }
61
+ return Math.max(line, baseline + Math.floor(baseline * RATCHET_ALLOWANCE))
62
+ }
63
+
64
+ /** 'refusal' over the ratchet, 'warning' over the line but within the zone's baseline. */
65
+ function ratchetSeverity(
66
+ slug: string | undefined,
67
+ metric: RatchetMetric,
68
+ reading: Readonly<{ line: number; actual: number }>,
69
+ ): 'refusal' | 'warning' {
70
+ return reading.actual > ratchetLimit(slug, metric, reading.line)
71
+ ? 'refusal'
72
+ : 'warning'
73
+ }
74
+
75
+ /** The words a reported (not refused) issue carries. */
76
+ function ratchetNote(slug: string | undefined, metric: RatchetMetric): string {
77
+ const baseline =
78
+ slug === undefined ? undefined : MEMORY_RATCHET[slug]?.[metric]
79
+ return baseline === undefined
80
+ ? ''
81
+ : ` (report-only, J412 ratchet: ${slug ?? ''} baseline ${String(baseline)})`
82
+ }
83
+
84
+ /** True when `revision` of `slug` is the pinned product whose stale reading the ratchet admits. */
85
+ function staleReadingAdmitted(
86
+ slug: string | undefined,
87
+ revision: number | undefined,
88
+ ): boolean {
89
+ return (
90
+ slug !== undefined &&
91
+ revision !== undefined &&
92
+ MEMORY_RATCHET[slug]?.staleRevision === revision
93
+ )
94
+ }
95
+
96
+ export {
97
+ MEMORY_RATCHET,
98
+ RATCHET_ALLOWANCE,
99
+ type MemoryBaseline,
100
+ type RatchetMetric,
101
+ ratchetLimit,
102
+ ratchetNote,
103
+ ratchetSeverity,
104
+ staleReadingAdmitted,
105
+ }
@@ -33,9 +33,10 @@ export class MemoryAdmission {
33
33
  private readonly warnings = new Map<string, MemoryAdmissionWarning>();
34
34
  private readonly listeners = new Set<() => void>();
35
35
  private readonly developer: () => boolean;
36
- private readonly hardBytes: number;
37
- /** `hardBytes` (J408): applies to playing and loading even with an override. */
38
- constructor(developer: () => boolean = () => false, hardBytes: number = Number.POSITIVE_INFINITY) { this.developer = developer; this.hardBytes = hardBytes; }
36
+ private readonly hardBytes: number | ((owner: string, kind: 'playing' | 'loading') => number);
37
+ /** `hardBytes` (J408): applies to playing and loading even with an override; a function gives each owner its own
38
+ * line (J412's ratchet, `memory-ratchet.ts`). */
39
+ constructor(developer: () => boolean = () => false, hardBytes: number | ((owner: string, kind: 'playing' | 'loading') => number) = Number.POSITIVE_INFINITY) { this.developer = developer; this.hardBytes = hardBytes; }
39
40
 
40
41
  /** True for an in-envelope request or a Developer override. False means the caller retains its original refusal path. */
41
42
  accept(request: MemoryAdmissionRequest): boolean {
@@ -44,7 +45,8 @@ export class MemoryAdmission {
44
45
  || ![playingCap, loadingCap].every(value => Number.isFinite(value) && value > 0)) throw new RangeError('Invalid memory admission report');
45
46
  const key = `${request.stage}:${request.owner}`;
46
47
  const playingOverBytes = Math.max(0, request.playingBytes - playingCap), loadingOverBytes = Math.max(0, request.loadingBytes - loadingCap);
47
- if (Math.max(request.playingBytes, request.loadingBytes) > this.hardBytes) { return false; }
48
+ const hard = this.hardBytes, line = (kind: 'playing' | 'loading'): number => typeof hard === 'number' ? hard : hard(request.owner, kind);
49
+ if (request.playingBytes > line('playing') || request.loadingBytes > line('loading')) { return false; }
48
50
  if (playingOverBytes === 0 && loadingOverBytes === 0) { if (this.warnings.delete(key)) this.notify(); return true; }
49
51
  if (!this.developer()) return false;
50
52
  const warning = Object.freeze({ ...request, playingCap, loadingCap, playingOverBytes, loadingOverBytes,
@@ -1,4 +1,5 @@
1
1
  import { budgetTierLimits } from './budget-tiers.ts'
2
+ import { ratchetNote, ratchetSeverity } from './memory-ratchet.ts'
2
3
  import { runtimeAccountedBytes } from './runtimeCost.ts'
3
4
 
4
5
  import type { BudgetTier } from './budget-tiers.ts'
@@ -10,6 +11,8 @@ const UNNAMED_TIER: BudgetTier = 'large'
10
11
  type RuntimeTierSource = Readonly<{
11
12
  runtime: Readonly<{ cost?: unknown }> | null
12
13
  budgets: Readonly<{ client?: unknown; tier?: BudgetTier }>
14
+ /** J412: the zone whose ratchet baseline applies (`memory-ratchet.ts`). */
15
+ identity?: Readonly<{ slug: string }>
13
16
  }>
14
17
 
15
18
  interface RuntimeTierIssue {
@@ -17,7 +20,7 @@ interface RuntimeTierIssue {
17
20
  readonly metric: string
18
21
  readonly actual: number
19
22
  readonly limit: number
20
- readonly severity: 'refusal'
23
+ readonly severity: 'refusal' | 'warning'
21
24
  }
22
25
 
23
26
  /**
@@ -37,13 +40,17 @@ function runtimeTierIssues(source: RuntimeTierSource): RuntimeTierIssue[] {
37
40
  if (actual <= limit) {
38
41
  return []
39
42
  }
43
+ const severity = ratchetSeverity(source.identity?.slug, 'runtime', {
44
+ line: limit,
45
+ actual,
46
+ })
40
47
  return [
41
48
  {
42
49
  code: 'runtime-tier-memory',
43
- metric: `runtime accounted bytes over the ${tier} tier's memory (OF10c1a: name a larger tier or shrink the runtime)`,
50
+ metric: `runtime accounted bytes over the ${tier} tier's memory (OF10c1a: name a larger tier or shrink the runtime)${severity === 'warning' ? ratchetNote(source.identity?.slug, 'runtime') : ''}`,
44
51
  actual,
45
52
  limit,
46
- severity: 'refusal',
53
+ severity,
47
54
  },
48
55
  ]
49
56
  }
@@ -14,6 +14,7 @@ import type { ShardTerrain } from "./terrain.ts";
14
14
  import { worstContentCost, memoryTargetWarnings, nearbyContentCost } from "./budget.ts";
15
15
  import { CONTENT_CAPS as C, MEMORY_GATES } from './contentBounds.ts';
16
16
  import { staleRuntimeIssues } from './memory-epoch.ts';
17
+ import { ratchetLimit } from './memory-ratchet.ts';
17
18
  import { MEMORY_HARD_BYTES, hardLineIssue, runtimeOfflineBytes } from './memory-line.ts';
18
19
  import { bootMemoryCosts } from './boot-memory-cost.ts';
19
20
  import type { TierIndex } from './phone-files.ts';
@@ -318,10 +319,10 @@ export function performanceReport(source: Shardfile, observations: PerformanceOb
318
319
  };
319
320
  if (native.unmeasuredViewAndDownload) check(['perf-native-view-unmeasured', 'native view/download measurement required'], 1, 0);
320
321
  if (source.runtime !== null && source.runtime.cost === undefined) check(['perf-native-resident-unmeasured', 'native resident measurement required'], 1, 0);
321
- issues.push(...staleRuntimeIssues(source.runtime));
322
+ issues.push(...staleRuntimeIssues(source.runtime, undefined, source.identity));
322
323
  // G433 keeps the soft caps report-only. J408 applies to both estimates ahead of the soft caps.
323
324
  const total = (kind: 'playing' | 'loading', actual: number, limit: number): void => {
324
- if (actual > MEMORY_HARD_BYTES) { issues.push(hardLineIssue(kind, actual)); return; }
325
+ if (actual > MEMORY_HARD_BYTES) { issues.push(hardLineIssue(kind, actual, source.identity.slug)); return; }
325
326
  const code = `perf-${kind}-memory` as const, metric = `worst ${kind} total bytes`;
326
327
  if (MEMORY_GATES.reportOnly && actual > limit) issues.push({ code, metric: `${metric} (report-only, G433)`, actual, limit, severity: 'warning' }); else check([code, metric], actual, limit);
327
328
  };
@@ -375,5 +376,6 @@ export function performanceReportLines(report: PerformanceReport): string[] {
375
376
 
376
377
  /** Offline soft-cap policy and the fixed J408 line for playing and loading. */
377
378
  export function offlineMemoryAdmission(policy: 'warn' | 'refuse'): MemoryAdmission {
378
- return new MemoryAdmission(() => policy === 'warn' || MEMORY_GATES.reportOnly, MEMORY_HARD_BYTES);
379
+ // J412: the line holds each zone at its ratchet baseline when that is higher (`memory-ratchet.ts`).
380
+ return new MemoryAdmission(() => policy === 'warn' || MEMORY_GATES.reportOnly, (owner, kind): number => ratchetLimit(owner, kind, MEMORY_HARD_BYTES));
379
381
  }
@@ -112,7 +112,8 @@ export function outputBlobExtension(kind: OutputFile['kind'], bytes: Uint8Array)
112
112
 
113
113
  /** Refuse the declared targets a policy treats as refusals, before any byte is read or executed. */
114
114
  export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse', context: MemoryContext = new Map()): void {
115
- const issues = [...staleRuntimeIssues(source.runtime), ...offlineMemoryIssues(source, context), ...runtimeTierIssues(source), ...performanceTargetIssues(source, policy).filter(issue => issue.severity === 'refusal')];
115
+ // J412: the memory gates are ratchets; an issue within a zone's baseline reports (`memory-ratchet.ts`) and is not thrown here.
116
+ const issues = [...staleRuntimeIssues(source.runtime, undefined, source.identity), ...offlineMemoryIssues(source, context), ...runtimeTierIssues(source), ...performanceTargetIssues(source, policy)].filter(issue => issue.severity === 'refusal');
116
117
  if (issues.length === 0) return;
117
118
  throw issueError('performance-targets', issues.map(issue => `REFUSAL: ${issue.metric}: ${issue.actual} > ${issue.limit}`).join('\n'));
118
119
  }