updated 2026-11-26·5 min read
Lockfile Specification (stokes.lock)
Formal specification of the stokes.lock schema, deterministic AST hashing, per-language normalization rules, and poly-repo merge resolution.
stokes.lock is the machine-checked contract manifest behind stokes verify --lockfile=stokes.lock --strict. Unlike human-oriented CONFORMANCE.md receipts or editable stokes.toml manifests, it holds canonical digests that CI checks without spinning up containers or compilers.
Complete Schema Specification
Keys sort lexicographically and floats round to four decimal places so digests match across Linux, macOS, and Windows runners.
Annotated stokes.lock JSON Structure
{
"$schema": "https://stokes.dev/schema/v1.json",
"version": "1.0.0",
"workspace": "cloudflame-l7-proxy",
"root_digest": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"invariants": {
"max_features": 200,
"max_heap_bytes": 0,
"max_p99_latency_ns": 10.0,
"core_reserved_slots": 128
},
"targets": [
{
"id": "clickhouse-schema",
"path": "migrations/001_bot_signals.sql",
"digest": "sha256:4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a"
},
{
"id": "rust-proxy-buffer",
"path": "crates/cloudflame-proxy/src/engine/feature_ingest.rs",
"digest": "sha256:ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d"
}
]
}Top-Level & Nested Field Definitions
| Object / Field | Type | Unit / Format | Description |
|---|---|---|---|
$schema | String | URI | JSON Schema URI (https://stokes.dev/schema/v1.json). |
version | String | SemVer | Lockfile schema version (1.0.0). |
workspace | String | ID | Target workspace or proxy package identifier. |
root_digest | String | sha256:... | Root SHA-256 over the sorted targets array. |
invariants.max_features | Integer | Slots | Downstream buffer slot ceiling (200). |
invariants.max_heap_bytes | Integer | Bytes | Confirmed packet intake heap budget (0). |
invariants.max_p99_latency_ns | Float | Nanoseconds | Criterion hot-path p99 ceiling (10.0). |
invariants.core_reserved_slots | Integer | Slots | Zone 0 reserved slots (128, with 72 adaptive Zone 1 slots). |
targets[].id | String | ID | Logical target name (clickhouse-schema, rust-proxy-buffer). |
targets[].path | String | Path | Repository-relative source or migration path. |
targets[].digest | String | sha256:... | Normalized boundary digest for the target file. |
Deterministic AST Hashing & Language Normalization
Running rustfmt, black, or sqlfluff won’t touch stokes.lock because the normalizer strips comments (--, //, #, /* ... */) and extracts only public boundary declarations (dropping unconsumed internal columns unless SELECT * or unqualified system.columns triggers LINT-006/LINT-001; see Projection Isolation), sorts declarations lexicographically, and hashes the compact JSON to sha256:<64-hex>:
| Language | Extracted Contract Elements | Stripped / Ignored |
|---|---|---|
SQL (.sql) | Uppercased CREATE TABLE columns (sorted), SYSTEM.COLUMNS DATABASE = CURRENTDATABASE() status, SELECT projections | Comments, whitespace, casing differences |
Python (.py) | Uppercase capacity constants (MAX_CANONICAL, etc.), extractor signatures | Method bodies, docstrings, comments |
Rust (.rs) | pub const declarations, [Type; N] fixed buffers, struct fields (sorted) | impl method bodies, private functions, comments |
Protobuf (.proto) | repeated declarations, tag numbers, [(stokes.max_items) = N] options | Line and block comments |
Simplified SQL & Rust Digest Sketch (Python)
Note: this minimal reference sketch shows comment stripping and regex boundary extraction for .sql and .rs files; Python and Protobuf follow the same canonical JSON hashing flow.
import hashlib
import json
from pathlib import Path
import re
from typing import Any
def compute_normalized_schema_digest(
path: Path | str,
content: str | None = None,
consumed_projections: dict[str, list[str]] | None = None,
) -> str:
p = Path(path)
if content is None:
if not p.exists():
return "sha256:" + ("0" * 64)
content = p.read_text(encoding="utf-8", errors="replace")
ext = p.suffix.lower()
signature_items: list[Any] = []
if ext == ".sql":
clean = re.sub(r"--.*$", "", content, flags=re.MULTILINE)
clean = re.sub(r"/\*.*?\*/", "", clean, flags=re.DOTALL)
clean_text = " ".join(clean.split()).upper()
create_tables = re.findall(
r"CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?([A-Z0-9_.]+)\s*\((.*?)\)",
clean_text,
)
for tbl, cols in sorted(create_tables):
raw_col_list = [c.strip() for c in cols.split(",") if c.strip()]
tbl_short = tbl.split(".")[-1]
filter_cols = None
if consumed_projections:
for k, v in consumed_projections.items():
if k.upper() in (tbl.upper(), tbl_short.upper()):
filter_cols = v
break
col_list = []
for c in raw_col_list:
col_name = c.split()[0].upper()
if filter_cols is not None and col_name not in [fc.upper() for fc in filter_cols]:
continue
col_list.append(c)
signature_items.append({
"type": "sql_table",
"table": tbl,
"columns": sorted(col_list),
})
elif ext == ".rs":
clean = re.sub(r"//.*$", "", content, flags=re.MULTILINE)
clean = re.sub(r"/\*.*?\*/", "", clean, flags=re.DOTALL)
for btype, bcap in sorted(re.findall(r"\[\s*(\w+)\s*;\s*(\d+)\s*\]", clean)):
signature_items.append({
"type": "fixed_buffer",
"item_type": btype,
"capacity": int(bcap),
})
for sname, sbody in sorted(re.findall(r"(?:pub\s+)?struct\s+(\w+)\s*\{([^}]*)\}", clean)):
fields = []
for f in sbody.split(","):
f = f.strip()
if ":" in f:
fname, ftype = f.split(":", 1)
fields.append((fname.strip(), ftype.strip()))
signature_items.append({
"type": "struct",
"name": sname,
"fields": sorted(fields),
})
canonical_json = json.dumps(signature_items, sort_keys=True, separators=(',', ':'))
return "sha256:" + hashlib.sha256(canonical_json.encode("utf-8")).hexdigest()Resolving Merge Conflicts in Poly-Repo Development
Under the Consumer Expands First (Tolerant Reader) rule (see Poly-Repo Protocol), downstream capacity PRs ([Feature; 200] → [Feature; 512]) merge first before upstream schema expansions (200 → 280). If parallel PRs collide on stokes.lock:
- Union both entries in
targets(keeping both SQL and Rust target digests). - Keep the higher
invariants.max_featurescapacity and updated target digest. - Re-certify deterministically rather than editing
root_digestmanually:
stokes cert
stokes verify --lockfile=stokes.lock --strict
git add stokes.lock CONFORMANCE.md
git commit -m "chore(stokes): re-certify boundary lockfile after poly-repo merge"
See CLI Reference and Cryptographic Conformance & Audit Receipts for lockfile verification commands.