@wildshard/shard-format 0.34.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.34.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": {
@@ -1,3 +1,5 @@
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
@@ -21,7 +23,7 @@ interface StaleRuntimeIssue {
21
23
  readonly metric: string
22
24
  readonly actual: number
23
25
  readonly limit: number
24
- readonly severity: 'refusal'
26
+ readonly severity: 'refusal' | 'warning'
25
27
  }
26
28
 
27
29
  /** Why a runtime reading is stale, older than `current` (the oldest current epoch), or empty when it is current. */
@@ -37,11 +39,14 @@ function staleRuntimeCost(
37
39
  }
38
40
 
39
41
  /** A refusal, whatever the policy, for a runtime home's reading and for its images-first reading, each stale against
40
- * `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`. */
41
44
  function staleRuntimeIssues(
42
45
  runtime: Readonly<{ cost?: EpochRow | undefined }> | null,
43
46
  current: number = OLDEST_CURRENT_EPOCH,
47
+ identity?: Readonly<{ slug: string; revision: number }>,
44
48
  ): StaleRuntimeIssue[] {
49
+ const admitted = staleReadingAdmitted(identity?.slug, identity?.revision)
45
50
  const rows: EpochRow[] = []
46
51
  const cost = runtime === null ? undefined : runtime.cost
47
52
  if (cost !== undefined) {
@@ -54,10 +59,10 @@ function staleRuntimeIssues(
54
59
  .filter((row: EpochRow): boolean => staleRuntimeCost(row, current) !== '')
55
60
  .map((row: EpochRow): StaleRuntimeIssue => ({
56
61
  code: 'perf-native-resident-unmeasured',
57
- metric: staleRuntimeCost(row, current),
62
+ metric: `${staleRuntimeCost(row, current)}${admitted ? ' (report-only, J412 ratchet: the pinned revision)' : ''}`,
58
63
  actual: row.epoch ?? LEGACY_EPOCH,
59
64
  limit: current,
60
- severity: 'refusal',
65
+ severity: admitted ? 'warning' : 'refusal',
61
66
  }))
62
67
  }
63
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
  }