[PR #572] [MERGED] Pixelforge: the seal holds after storage — a read-side fold that cannot sever an honest save #1032

Closed
opened 2026-10-20 17:33:24 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Agents/pull/572
Author: @kolacheee
Created: 8/25/2026
Status: ✅ Merged
Merged: 8/25/2026
Merged by: @kolacheee

Base: staging ← Head: fix/566-brief-revalidate


📝 Commits (6)

  • 73f68c6 fix(pixelforge): a seal that stopped holding the moment the brief was stored
  • 9043cea docs(pixelforge): the sealed spec was still promising a guarantee that ended at the seal
  • 4d2d4d3 docs(pixelforge): two comments corrected to what measurement showed
  • 2359de6 test(pixelforge): the tag fold gets the case the review asked for
  • 09c5b90 fix(pixelforge): the theme fold kept its own copy of a vocabulary it does not own
  • b16bd40 test(pixelforge): the proto map case hands its stubs back

📊 Changes

7 files changed (+722 additions, -9 deletions)

View changed files

📝 artifacts/pixelforge-0.12.0.zip (+0 -0)
📝 packages/pixelforge/client.js (+147 -3)
📝 packages/pixelforge/docs/brief-schema.md (+21 -0)
📝 packages/pixelforge/manifest.json (+2 -2)
📝 packages/pixelforge/src/18-brief.js (+112 -1)
📝 packages/pixelforge/src/20-world.js (+35 -2)
📝 packages/pixelforge/test-brief.mjs (+405 -1)

📄 Description

Pull request

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #566

Why this change

  • #566 documented that the sealed brief's validation is a seal-time guarantee that does not survive the round-trip through chat metadata: the load path returns the stored brief raw, and ~14 compiler reads trust arbitrary stored strings. Probe-verified: a hostile prosperity silently compiled 10 zones where the brief asks 41 with zero warnings; hostile scale/place.kind silently degraded the whole generated world to the 3-zone legacy layout. The forward-compat angle makes this legitimately reachable — a newer build's new enum value downgrades an older build's world the same way.
  • This PR deliberately does NOT implement the issue's proposed fix, and the reasons are measured, not stylistic. Re-validating in _configBrief would (a) sever an honest save on its first load — validate() is not byte-idempotent (a brief that took repairs at seal time re-validates with an empty _repairs, and cast key-order differs between seal paths; either alone re-hashes the brief and trips the S5 severance machinery, which keys on brief identity) — and (b) re-run the seal-time capacity policy, recreating the exact silent content loss the issue exists to close (two existing harness fixtures deliberately shrink scale post-seal and would lose places on every load). Both hazards were driven red against the rejected design before the shipped one was written.

What changed

  • Affected package ID: pixelforge (catalog-excluded; the uncatalogued-manifest sweep validates it).
  • src/18-brief.js: PF.brief.foldStored(stored, seed) — a read-side fold under the contract seal time may DROP; read time may only FOLD. It deep-copies (mandatory: validate() reorders the caller's cast in place on the leader-hoist path), folds ONLY table-key values (theme, scale, surround, prosperity, places[].kind, features[].tag, cast[].kind/tint/standing) to the same defaults seal time would have chosen, never touches lengths/names/ids/prose, never re-runs capacity policy, and records its work in _folds on the private copy — surfaced as world.briefFolds only when non-empty, never serialized, never written back to metadata.
  • src/20-world.js: build() calls the fold between the existing shape gate and compile(). _configBrief is byte-untouched — the load path still returns the stored object by reference, so brief identity (the severance hash) structurally cannot move: nothing anywhere hashes the folded copy.
  • Harness: six new fail-first cases including the two that matter most — the severance case (an honest brief loads twice through the new seam with an identical hash and nothing severed, while a genuinely changed brief still severs exactly as before) and the rejected-design red (the fold applied at _configBrief demonstrably severs an honest save on first load).
  • docs/brief-schema.md: the seal-scope guarantee language updated to describe the fold.
  • Generated outputs rebuilt in-commit (client.js, manifest, zip); rebuild-after-commit produces zero delta.

Package and security impact

  • Affected package IDs: pixelforge only
  • Engine compatibility impact: none — read-side only; no save shape changes, no metadata writes
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: none. Every existing brief fixture compiles byte-identically (verified across 1,449 builds by the implementer and independently re-derived across 398 builds covering every enum value by a second agent — zero mismatches). Only briefs carrying values this build's tables don't know change behavior: they now fold to seal-time defaults with a console warn and a debugger-visible trace, instead of silently losing zones or degrading to the legacy world. Fold cost ≈ 18–29 µs against a ~2.5 ms world build, once per build.

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Manual verification notes

Boxes are the human contributor's list. Agent-verified, independently replayed by a second adversarial agent:

  • The severance-impossibility argument verified structurally (every consumer of brief identity traced to the stored reference; foldStored has exactly one call site and its output never escapes except as the unserialized briefFolds) and empirically (the rejected design replayed: honest save severs on first load, briefHash 2081522237 → 73619670; the shipped design: identical hash, nothing severed; a genuinely changed brief still severs — the machinery is not deadened).
  • Both fold-contract halves have live reds: replacing the fold with a second validate() breaks an existing fixture (capacity policy re-run strips content); deleting the deep copy severs immediately (the in-place cast reorder reaching the stored bytes).
  • Hostile prosperity/scale/place.kind now compile the folded default's full world (e.g. 41 zones, tile-identical to the honest equivalent) instead of 10-zone silent loss or legacy-3-zone degrade.
  • One correction to the issue while implementing: its _ids.zones value-claim does not reproduce (that path is prototype-safe via Map(Object.entries(…))); the residual hole there is a null shape passing the type gate, with identical pre/post behavior — one boolean if ever wanted, deliberately out of scope.
  • Merge-order note: this branch and #569 both rebuild the generated artifacts, so whichever merges second needs a rebase + rebuild (verified mechanically: everything auto-merges clean except the two generated files, and the rebuilt bundle comes out byte-identical to the auto-merge). I'll handle it as soon as the first one merges.
  • Optional in-app check: a chat whose stored brief was hand-edited to carry an unknown enum value should now load its full world with a console warn, instead of a shrunken or legacy one.

Documentation impact

  • No documentation changes needed
  • Updated this README catalog and package guidance
  • Updated linked Marinara Engine documentation

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added safe loading for stored briefs by normalizing recognized legacy and unknown values during world compilation.
    • Exposed normalization details and warnings on compiled worlds.
  • Bug Fixes

    • Prevented valid stored briefs from unnecessarily falling back to legacy world layouts.
    • Preserved stored brief data, metadata, and save identity across repeated loads.
    • Improved handling of forward-compatible and prototype-defined values without applying unrelated validation repairs.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Agents/pull/572 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/25/2026 **Status:** ✅ Merged **Merged:** 8/25/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/566-brief-revalidate` --- ### 📝 Commits (6) - [`73f68c6`](https://github.com/Pasta-Devs/Marinara-Agents/commit/73f68c6e59b869e102782e67e7cd0d40a9bbc27e) fix(pixelforge): a seal that stopped holding the moment the brief was stored - [`9043cea`](https://github.com/Pasta-Devs/Marinara-Agents/commit/9043cea3d50dc39c1cade57b68ddd98f48703095) docs(pixelforge): the sealed spec was still promising a guarantee that ended at the seal - [`4d2d4d3`](https://github.com/Pasta-Devs/Marinara-Agents/commit/4d2d4d346141a2905d75614b84aee0e40699411a) docs(pixelforge): two comments corrected to what measurement showed - [`2359de6`](https://github.com/Pasta-Devs/Marinara-Agents/commit/2359de673daeaba26b75153b44f5a62f4a0dd312) test(pixelforge): the tag fold gets the case the review asked for - [`09c5b90`](https://github.com/Pasta-Devs/Marinara-Agents/commit/09c5b9052ae102d561c13d8ceced96e3727cf435) fix(pixelforge): the theme fold kept its own copy of a vocabulary it does not own - [`b16bd40`](https://github.com/Pasta-Devs/Marinara-Agents/commit/b16bd40fa4e919a007eecb9a5aeb29e20aefbaff) test(pixelforge): the __proto__ map case hands its stubs back ### 📊 Changes **7 files changed** (+722 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `artifacts/pixelforge-0.12.0.zip` (+0 -0) 📝 `packages/pixelforge/client.js` (+147 -3) 📝 `packages/pixelforge/docs/brief-schema.md` (+21 -0) 📝 `packages/pixelforge/manifest.json` (+2 -2) 📝 `packages/pixelforge/src/18-brief.js` (+112 -1) 📝 `packages/pixelforge/src/20-world.js` (+35 -2) 📝 `packages/pixelforge/test-brief.mjs` (+405 -1) </details> ### 📄 Description # Pull request > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #566 ## Why this change - #566 documented that the sealed brief's validation is a seal-time guarantee that does not survive the round-trip through chat metadata: the load path returns the stored brief raw, and ~14 compiler reads trust arbitrary stored strings. Probe-verified: a hostile `prosperity` silently compiled 10 zones where the brief asks 41 with zero warnings; hostile `scale`/`place.kind` silently degraded the whole generated world to the 3-zone legacy layout. The forward-compat angle makes this legitimately reachable — a newer build's new enum value downgrades an older build's world the same way. - **This PR deliberately does NOT implement the issue's proposed fix**, and the reasons are measured, not stylistic. Re-validating in `_configBrief` would (a) **sever an honest save on its first load** — `validate()` is not byte-idempotent (a brief that took repairs at seal time re-validates with an empty `_repairs`, and cast key-order differs between seal paths; either alone re-hashes the brief and trips the S5 severance machinery, which keys on brief identity) — and (b) re-run the seal-time **capacity policy**, recreating the exact silent content loss the issue exists to close (two existing harness fixtures deliberately shrink `scale` post-seal and would lose places on every load). Both hazards were driven red against the rejected design before the shipped one was written. ## What changed - Affected package ID: `pixelforge` (catalog-excluded; the uncatalogued-manifest sweep validates it). - `src/18-brief.js`: **`PF.brief.foldStored(stored, seed)`** — a read-side fold under the contract **seal time may DROP; read time may only FOLD**. It deep-copies (mandatory: `validate()` reorders the caller's cast in place on the leader-hoist path), folds ONLY table-key values (`theme`, `scale`, `surround`, `prosperity`, `places[].kind`, `features[].tag`, `cast[].kind/tint/standing`) to the same defaults seal time would have chosen, never touches lengths/names/ids/prose, never re-runs capacity policy, and records its work in `_folds` on the private copy — surfaced as `world.briefFolds` only when non-empty, never serialized, never written back to metadata. - `src/20-world.js`: `build()` calls the fold between the existing shape gate and `compile()`. `_configBrief` is **byte-untouched** — the load path still returns the stored object by reference, so brief identity (the severance hash) structurally cannot move: nothing anywhere hashes the folded copy. - Harness: six new fail-first cases including the two that matter most — the severance case (an honest brief loads twice through the new seam with an identical hash and nothing severed, while a genuinely changed brief still severs exactly as before) and the rejected-design red (the fold applied at `_configBrief` demonstrably severs an honest save on first load). - `docs/brief-schema.md`: the seal-scope guarantee language updated to describe the fold. - Generated outputs rebuilt in-commit (client.js, manifest, zip); rebuild-after-commit produces zero delta. ## Package and security impact - Affected package IDs: `pixelforge` only - Engine compatibility impact: none — read-side only; no save shape changes, no metadata writes - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: none. Every existing brief fixture compiles byte-identically (verified across 1,449 builds by the implementer and independently re-derived across 398 builds covering every enum value by a second agent — zero mismatches). Only briefs carrying values this build's tables don't know change behavior: they now fold to seal-time defaults with a console warn and a debugger-visible trace, instead of silently losing zones or degrading to the legacy world. Fold cost ≈ 18–29 µs against a ~2.5 ms world build, once per build. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [x] `node scripts/validate-catalog.mjs` passes locally - [x] `git diff --check` passes locally - [x] Rebuilt every affected manifest, payload, artifact, and catalog entry - [x] Installed or updated the affected package through Marinara Engine - [x] Checked supported modes, restart behavior, and uninstall cleanup - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Boxes are the human contributor's list. Agent-verified, independently replayed by a second adversarial agent: - The severance-impossibility argument verified **structurally** (every consumer of brief identity traced to the stored reference; `foldStored` has exactly one call site and its output never escapes except as the unserialized `briefFolds`) **and empirically** (the rejected design replayed: honest save severs on first load, `briefHash 2081522237 → 73619670`; the shipped design: identical hash, nothing severed; a genuinely changed brief still severs — the machinery is not deadened). - Both fold-contract halves have live reds: replacing the fold with a second `validate()` breaks an existing fixture (capacity policy re-run strips content); deleting the deep copy severs immediately (the in-place cast reorder reaching the stored bytes). - Hostile `prosperity`/`scale`/`place.kind` now compile the folded default's full world (e.g. 41 zones, tile-identical to the honest equivalent) instead of 10-zone silent loss or legacy-3-zone degrade. - One correction to the issue while implementing: its `_ids.zones` value-claim does not reproduce (that path is prototype-safe via `Map(Object.entries(…))`); the residual hole there is a `null` shape passing the type gate, with identical pre/post behavior — one boolean if ever wanted, deliberately out of scope. - **Merge-order note:** this branch and #569 both rebuild the generated artifacts, so whichever merges second needs a rebase + rebuild (verified mechanically: everything auto-merges clean except the two generated files, and the rebuilt bundle comes out byte-identical to the auto-merge). I'll handle it as soon as the first one merges. - Optional in-app check: a chat whose stored brief was hand-edited to carry an unknown enum value should now load its full world with a console warn, instead of a shrunken or legacy one. ## Documentation impact - [ ] No documentation changes needed - [x] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **New Features** * Added safe loading for stored briefs by normalizing recognized legacy and unknown values during world compilation. * Exposed normalization details and warnings on compiled worlds. * **Bug Fixes** * Prevented valid stored briefs from unnecessarily falling back to legacy world layouts. * Preserved stored brief data, metadata, and save identity across repeated loads. * Improved handling of forward-compatible and prototype-defined values without applying unrelated validation repairs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-20 17:33:24 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#1032
No description provided.