> For the complete documentation index, see [llms.txt](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/phases/phase_34/session_06_persistence_schema_contracts.md).

# Session 06: Persistence Schema Contracts

**Session ID**: `phase34-session06-persistence-schema-contracts` **Status**: Not Started **Estimated Tasks**: \~12-25 **Estimated Duration**: 2-4 hours

***

## Objective

Make AI Rogue durable claim and saved-run contracts schema-owned, explicit, and harder to confuse during future refactors.

***

## Migrated Audit Source

* Former audit sessions: 2026-06-25 Sessions 05 Economy And Persistence, 09 Types And Schemas, and 13 Refactor Map.
* Primary findings: AR-D5-001 and AR-D5-002, with D3 privacy evidence showing no promoted hosted-storage, raw private persistence, public-demo server-write, or seed-share leak finding.
* AR-D5-001 evidence: direct `recordAiRogueClaim` validation does not reuse the durable claim schema or enforce the 100-shard daily cap consistently; a direct oversized `amount: 250` claim can produce wallet balance 100, ledger amount 250, and balanceAfter 100.
* AR-D5-002 evidence: live runtime snapshots and durable save-slot snapshots share confusing names while React bridge code casts saved run state back into hand-authored runtime payload types.
* Preserve the contract that Zod save/economy schemas are the durable source of truth, and that public-demo state remains browser-local.
* Source details are preserved in `PRD_phase_34.md` Appendix A.

***

## Scope

### In Scope (MVP)

* Replace direct claim validation drift with `aiRogueClaimEntrySchema` parsing or one normalized claim path shared by wallet and ledger writes.
* Ensure oversized direct claims cannot produce wallet/ledger amount mismatch.
* Rename the durable runtime snapshot type so it cannot be confused with the live runtime controller snapshot.
* Add a schema-owned durable-to-runtime save helper or explicit hydration path.
* Replace casts in the React/runtime bridge with the new helper where feasible.
* Add focused migration/save/load and direct claim tests.

### Out of Scope

* IndexedDB adapter rewrite.
* New wallet/economy rules.
* New save-slot UI.

***

## Prerequisites

* [ ] Session 01 claim and durable snapshot coverage exists.
* [ ] Current save schema migration tests are passing or baseline failures are documented.

***

## Deliverables

1. Normalized durable claim write path.
2. Clear durable snapshot naming and conversion helper.
3. Updated persistence/runtime-canvas usage without unsafe casts where possible.
4. Regression tests for oversized direct claims and saved-run hydration.

***

## Success Criteria

* [ ] Wallet and ledger cannot disagree on direct oversized claim amount.
* [ ] Live runtime snapshots and durable saved-run snapshots have distinct, clear type names.
* [ ] Saved-run load paths use schema-owned hydration or explicit validation.
* [ ] Persistence and save-schema focused tests pass.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/phases/phase_34/session_06_persistence_schema_contracts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
