Worked Examples
Developer reference for persistent saved state — Workspace
Workspace maintains local drafts, account backups, and revision-controlled project records through separate persistence mechanisms. This reference documents their implementation, authorization boundaries, recovery behavior, and the tests required to establish state continuity.
Application: Workspace
Component: Project persistence, browser-state integrity, account backup, revisioned synchronization and recovery
Article type: Developer reference
Status: Source-reviewed; deployment acceptance pending
Estimated reading time: 19 minutes
Source baseline: 04f28743751634ed0bc64a5028290b4d29119400 (November 20, 2026)
Reference scope. Workspace persists local drafts, project and notebook copies, server revisions and synchronization receipts through distinct mechanisms. This reference specifies their schemas, routes, ownership controls and failure semantics, and shows how to confirm the accepted state from a fresh authorized session.
Goal
Describe how Workspace persists drafts, project revisions, notebooks and related outputs; identify the actual authority for each save operation; and define an auditable read-back. The central acceptance condition is that a fresh authorized session retrieves the same accepted project state, not simply that a browser displayed a successful save.
This is an implementation reference, not a user-interface promise: feature availability depends on the installed release and deployment configuration. Preserving a saved project is also distinct from proving the correctness of a scientific result or authorizing publication.
Requirements
- Read access to the inspected Workspace source revision, the release and migration ledger for the intended environment, and the actual authentication mode.
- A disposable staging database, synthetic owner identities, an isolated browser profile and a known-good backup. Never use real research or production credentials for contract tests.
- A canonical
projectId,sourceProjectId, accepted server revision,projectFingerprint, and separately the whole-packagefingerprint. Keep their meanings distinct. - Stable
operationIdandenvelopeIdfor a test write, plus an independent session and a different-owner negative test identity. - Any notebook IDs, artifact/source hashes, method versions, output bindings and publication authority required to interpret the project beyond its JSON document.
- Named staging owner approval for write, conflict, recovery and restore tests; record deployment-specific configuration and exclusions.
Procedure
- Determine whether the project is browser-local, manually backed up, actively synchronized or rendered through a thin-client projection.
- Read the current authoritative project head, record the owner-scoped ID, accepted revision, project fingerprint and package fingerprint.
- Commit one approved synthetic change using the appropriate complete schema and persistence pathway; retain operation identifiers for replay safety.
- Retrieve the accepted head from an independent, freshly authenticated session and compare document and metadata separately.
- Exercise a foreign-owner denial, stale-revision conflict, replay and earlier-revision read; verify none rewrites the accepted state.
- Inspect notebooks and external artifacts at their own authorities; record scientific provenance and publication exclusions.
- Keep the test evidence metadata-only, preserve a rollback-ready backup and explicitly record unresolved checks.
The steps below provide the field-level contracts and failure handling for these operations.
1. Persistence architecture and sources of authority
The repository contains several persistence designs corresponding to different Workspace experiences. Do not conflate them or infer which one is deployed from repository presence alone.
| Surface | Current source behavior | What establishes persistence |
|---|---|---|
| Browser-local canonical state | The extracted local runtime manages localStorage["sc_workspace"], read-after-write verification, write journal, last-known-good state and quarantine. |
A verified local save followed by a same-browser reload; not a server or cross-device guarantee. |
| Backend account project | ProjectHead and ProjectRevision rows are owner-scoped in PostgreSQL; GET /v1/projects/{project_id} returns the stored package. |
Read after write under a new authenticated session with the same owner. |
| Manual account backup | POST /v1/projects using sc-workspace-cloud-backup/1.0 writes manual-backup storage mode. |
An explicit backup plus confirmed indexed and retrievable server copy. |
| Revision-controlled sync | POST /v1/sync/envelopes records conditional mutations and durable receipts. Pending offline operations are drafts. |
Accepted revision, receipt, server head rehydration and fresh read-back. |
| Thin-client read model | /v1/thin-client-state/bootstrap is a server-generated projection; its client canonical cache is described as transient. |
Inspect authoritative server objects, not a client-only cache. |
| Notebooks and publication | Notebooks have distinct server records; publication/approval uses separate scoped workflows. | Verify each downstream object in its own authoritative service. |
Source: browser persistence runtime; project repository; local-first synchronization; thin-client state profile.
2. Canonical browser-local save transaction
The extracted browser persistence runtime uses a storage-compatible adapter with load(), save() and inspect(). Its default canonical key is sc_workspace; related keys include sc_workspace_last_good_v1 and sc_workspace_recovery_v0_8_2. Additional transaction and integrity keys are documented in the earlier persistence-integrity design.
- The runtime prepares a normalized state and stages an integrity transaction when an integrity adapter is present.
- It writes serialized state, reads it back and rejects the save if the bytes do not match.
- It commits integrity metadata where supported, and returns an
okresult; an exception returnsok:false. - On ambiguous failure, the runtime preserves available journal and recovery material and does not automatically overwrite readable canonical evidence.
Trust boundary: a byte-for-byte browser write check does not authenticate the actor, encrypt saved material, establish source validity, or prove that a backend backup exists. The documented FNV-1a integrity receipt is a drift detector, not a secure cryptographic signature.
3. Persistence contracts and schema identifiers
| Contract | Implemented fields or role | Notes |
|---|---|---|
sc-workspace-project/20.0 |
Project document with required id, persistence, objects and other nested fields. |
The actual JSON Schema has more required fields than the brief examples below. Validate the full document before submission. |
sc-workspace-cloud-backup/1.0 |
ProjectStoreRequest: sourceProjectId, optional title/time, project. |
Manual backup; no revision precondition. Cannot overwrite an existing sync-head. |
sc-workspace-sync-push/1.0 |
ProjectStoreRequest with expectedRevision, optional operationId. |
Server requires matching revision; returns 409 on stale write. |
sc-workspace-sync-envelope/1.0 |
envelopeId, operationId, deviceId, objectKind, objectId, baseRevision, optional baseFingerprint, mutation. |
Applies put or delete to project/notebook; records a replayable receipt. |
sc-workspace-sync-reconcile-request/1.0 |
deviceId, clientRevisionVector, optional projectIds. |
Generates comparison statuses; no automatic semantic merge. |
sc-workspace-local-first-sync-receipt/1.0 |
receiptId, operationId, status, serverRevision, canonicalFingerprint. |
Metadata record for applied/conflict operations, not the entire project payload. |
Source: Pydantic request definitions; complete project v20 schema; sync-push schema.
4. Backend routes and HTTP contract
| Method and path | Purpose | Required interpretation |
|---|---|---|
GET /v1/projects |
List the authenticated owner’s stored project heads. | Response declares automaticSync:false and explicitSync:true. |
POST /v1/projects |
Store a manual backup or conditional sync-push project. | A successful response has ok, replayed and project item. |
GET /v1/projects/{project_id} |
Read the current stored package and project metadata. | A fresh read is essential; the response includes the project package. |
GET /v1/projects/{project_id}/revisions |
List historical project revisions. | Revision history is separate from browser-local restore-point history. |
GET /v1/projects/{project_id}/revisions/{revision} |
Read one historical revision. | Inspect historical package without replacing the active head. |
GET/POST /v1/notebooks |
List or persist a notebook. | Project persistence alone does not establish notebook persistence. |
GET /v1/sync and GET /v1/sync/bootstrap |
Discover sync profile and revision vector. | Use server revision vector as authority, not unconfirmed local state. |
POST /v1/sync/envelopes |
Apply one bounded mutation with an operation ID. | Applied or conflict receipts; rehydrate the server head. |
POST /v1/sync/reconcile |
Compare the client revision vector with the server. | server-ahead, client-ahead, missing-server, up-to-date. |
GET /v1/sync/receipts |
List owner-scoped sync receipts. | Retain metadata for audit and interrupted-operation investigation. |
GET /v1/thin-client-state/bootstrap |
Obtain canonical read projections and transient client state hints. | Projection is not an independent scientific record. |
Route source: backend/app/main.py. API paths are backend paths and must not be assumed to be public WordPress routes or callable without the configured identity bridge.
5. Identity, authorization and owner isolation
Backend routes depend on require_service_identity, which resolves the accepted Workspace session or other configured credential and enforces server-side route authorization. The caller does not supply a trusted project owner through its JSON body. Repository lookups include user_key in the project key.
A project belonging to one identity must not appear in a different identity’s list or be returned by the private GET. Missing and foreign project lookups are designed to return 404 without disclosing another owner’s content. When Sustainable Catalyst Identity is required, a bare user identifier plus shared service bearer is not a valid human identity.
Source: identity resolver; owner-scoped data queries. Never test tenant isolation by transferring private project payloads to public incident reports.
6. Project metadata: revision versus fingerprint
| Field | Meaning | Comparison rule |
|---|---|---|
projectId |
Stable server-side project identifier. | Match exactly across write and fresh read. |
revision |
Accepted server project revision. | Must match the accepted write when no authorized concurrent update occurred. |
projectFingerprint |
Fingerprint of the project document generated by workspace_project_fingerprint. |
Compare with the same field returned by the server; do not replace with local JSON hashing. |
fingerprint |
SHA-256-derived fingerprint of the stored package. | Treat separately from projectFingerprint. |
storageMode |
manual-backup or sync-head. |
Do not attempt manual replacement of a sync head. |
objectCount / bytes |
Derived metadata for stored package/project. | Useful consistency signals, not scientific validation. |
backedUpAt |
Server recorded backup timestamp. | Record clock and snapshot context; timestamps alone do not prove correctness. |
When comparing exact content, compare the retrieved package.project with the authoritative submitted document under an agreed canonicalization. A local SHA-256 can be useful for test records, but is not automatically equal to either of the backend fingerprint fields.
7. Manual project backup: request shape
The backend Pydantic model accepts a complete validated Workspace project document. This example shows the outer request contract only; the abbreviated nested document is not a production-valid project.
{
"schema": "sc-workspace-cloud-backup/1.0",
"sourceProjectId": "synthetic-project-01",
"projectTitle": "Synthetic project",
"project": {
"schema": "sc-workspace-project/20.0",
"id": "synthetic-project-01",
"title": "Synthetic project",
"objects": []
}
}
Before submitting, populate every required property of the current project JSON Schema (including nested state), validate domain constraints and authenticate through the supported deployment boundary. No server token should be embedded in a front-end or documentation example.
8. Revisioned synchronization: request shape
For a local-first sync operation, retain stable identifiers across retries. A baseRevision mismatch, or an optional baseFingerprint mismatch, produces a conflict receipt rather than overwriting the server head.
{
"schema": "sc-workspace-sync-envelope/1.0",
"envelopeId": "synthetic-envelope-003",
"operationId": "synthetic-operation-003",
"deviceId": "synthetic-device-01",
"objectKind": "project",
"objectId": "synthetic-project-01",
"baseRevision": 2,
"baseFingerprint": "<use-current-server-projectFingerprint>",
"mutation": {
"action": "put",
"title": "Synthetic project",
"document": {"schema": "sc-workspace-project/20.0", "id": "synthetic-project-01"}
}
}
The above is a shape illustration, not a runnable backend write. The document must contain a complete project. A real integration first retrieves the current server head, validates the complete project document, submits the conditional mutation, and retrieves the head again. Browser-only drafts and queued offline mutations are not server-authoritative.
9. Write sequence and independent read-back
- Capture a private baseline: source project ID, current revision, server
projectFingerprint, packagefingerprint, and hashes of externally stored inputs. Record owner identity as an opaque test identifier. - Save through exactly one authorized persistence path. For an enrolled sync project, send a conditional operation with stable
envelopeIdandoperationId. - Capture the returned
itemor syncreceipt. Recordstatus, new revision, returned fingerprint and whether the operation was replayed. - Close the writing session. Open a new authenticated session for the same test owner (not merely a cached view in the writer session).
- Issue a fresh GET for the project, verify stable identity, revision, package fingerprint and exact project content, and check the notebook/artifact authority separately.
- Repeat the GET with a different synthetic owner; require a denial and no private project content. Submit a stale revision from the correct owner and require a 409 with no silent overwrite.
- Inspect the previous revision through the read-only history route. Retain metadata-only evidence of the test and keep raw project content in restricted storage.
Pass condition: accepted server head and independently retrieved state agree under the intended owner, while wrong-owner access and stale mutation both fail safely. Any divergent state is a failure or requires a documented concurrent-write explanation.
10. Idempotent retries and interrupted operations
local_first_sync.apply_envelope() looks for an existing owner-scoped receipt matching the incoming envelope ID or operation ID. A replay returns the previously stored result, including a conflict if the original operation conflicted. The lower-level project store also recognizes the last accepted sync operation ID.
Client code must not mint a new operation ID merely because a network response was lost. First check GET /v1/sync/receipts or retry with the same identity and payload, then read the current server head. Reusing an identifier for a different payload is an application error; inspect the receipt’s requestFingerprint and reject mismatched client intentions.
For an unresolved 409, preserve both branches and run the revision-vector reconciliation. The server advertises automaticSemanticMerge:false and a requirement to rehydrate after conflict.
11. Manual backup and sync-head collision
When a project’s stored head has storageMode="sync-head", a later sc-workspace-cloud-backup/1.0 request for the same owner and project ID returns 409. This prevents an unconditional manual backup from bypassing the sync revision precondition. Reverse the proposed action: read the current head, preserve any local-only changes as a separate copy, and use the supported conditional sync or explicit restore workflow.
12. Historical revisions and controlled recovery
The backend stores a ProjectRevision record with its own revision, fingerprint, project fingerprint, storage mode and package. Use the read-only revisions endpoints to compare accepted history. Separately, browser-local restore points are copy-based: the documented cloneProject() operation remaps project, object and relationship IDs so restoring does not silently overwrite the active project.
For browser integrity drift, preserve the readable current payload, the last-known-good candidate and the metadata-only integrity report before choosing a recovery action. A damaged-state quarantine contains private material and must be handled as restricted research evidence. Do not treat FNV-1a integrity receipts as signatures or claim malicious tamper resistance.
13. Notebooks, artifacts and scientific context
NotebookStoreRequest defines distinct notebook backup and sync schemas. A successful project mutation does not prove that the notebook head, dataset blob, figure source, citation collection or publication draft was saved in its own store. For each dependent record, preserve:
- Its stable ID and owning project ID, reference type, accepted revision and authoritative store.
- Its full source hash when byte-level integrity matters, plus method version and transformation inputs.
- Any materialized execution receipts, notebook provenance, figure lineage or external dataset references required to reproduce the result.
- Explicit limitations for files, outputs or linked services that could not be fetched during the test.
Do not infer a Research publication or independent peer review from a saved Workspace project. Publication release, rights and scientific assessment remain distinct governed transitions.
14. Common typed failures and diagnostics
| Observation | Likely source or condition | Safe response |
|---|---|---|
400 |
Invalid domain project or unsupported sync mutation; missing put document may also produce 400. |
Inspect the declared schema and complete document; do not retry unchanged invalid payloads. |
401 / 403 |
Missing/invalid identity or a denied authenticated action. | Confirm the supported session and policy from server logs; never weaken access checks. |
404 |
Missing project/revision or an owner-scoped record that the caller is not entitled to read. | Check ID and authorized account; avoid revealing whether another owner holds the ID. |
409 |
Stale sync revision/fingerprint, manual-backup vs sync-head collision, account quota, or concurrent revision. | Retain both candidates, inspect server head and receipt, reconcile without silent overwrite. |
413 |
Project payload exceeds configured backend size limit. | Inspect configured limits and source bundle size; do not split scientific records without preserving links. |
422 |
Pydantic validation failure such as missing required request fields. | Correct request shape before resubmitting. |
503 |
Required backend credential, signing or service configuration unavailable, depending on route. | Stop writes; escalate configuration with nonsecret diagnostics. |
Browser save().ok=false |
Storage failure, journal failure or failed read-after-write. | Preserve the in-memory draft and any recovery state; do not clear storage or refresh blindly. |
These are code-path classifications, not a guarantee that every deployment returns the same message. Preserve a sanitized trace identifier and explicit request context, never raw cookies, tokens, private project text or embedded file bytes.
Symptoms
The user sees a saved indicator but cannot retrieve the new revision; two devices show divergent project content; a sync retry returns 409; a manual backup is refused because a sync head already exists; notebook references are present but the notebook document is absent; a fresh session sees an older project; a browser integrity warning reports drift; or an unrelated owner can access the same project ID.
Cause
Distinguish unsaved local in-memory changes from a verified browser-local write; a browser-local write from a server backup; a manual backup from revisioned sync; and a server-authoritative read from an old browser cache. Other causes include owner mismatch, stale base revision, wrong digest field, interrupted operation replay, incompatible project schema, changed linked artifacts or a missing recovery reference.
Troubleshooting
- Identify the actual persistence mode and the authoritative store for the missing object. Determine whether the expected behavior is local reload, account backup retrieval, or cross-session sync.
- Confirm source
projectId, owner scope and last accepted revision. Retrieve the server head through an independent authenticated request. - Compare
projectFingerprinttoprojectFingerprint; comparefingerprintonly to the package field. Separately compare the actualpackage.projectcontent. - Look for an earlier receipt with the same envelope/operation IDs. A replay is not a second mutation.
- On 409, inspect server revision and
base-revision-mismatchorbase-fingerprint-mismatch. Do not force last-write-wins. - If local state is damaged, quarantine and export recovery candidates before restore. Test a copy-based restore in staging.
- Trace each notebook, artifact, figure and publication reference to its own source; record which dependencies were unavailable.
- Run denied-owner and stale-revision tests in disposable staging, then compare the accepted head and historical revisions after the tests.
Resolution
Resolve a local-only save issue by preserving the readable current project or last-known-good candidate and restoring through the supported Workspace recovery interface. Resolve backend drift through authenticated rehydration, a deliberate conflict choice or a new conditional mutation based on the latest server revision. Resolve identity failures at the identity/policy layer rather than by manipulating owner IDs. Reissue incomplete writes only after checking prior receipts; use the original operation ID for a true retry.
Never silently delete revision history, mutate a foreign user’s records, overwrite a sync head using manual backup, or interpret a recovered draft as an approved scientific output.
Verification
Perform the entire procedure twice: first with synthetic project revisions and clean sessions; then, only if authorized, in production-equivalent staging. The following checks are independently required:
| Acceptance case | Pass condition | Evidence |
|---|---|---|
| P1 — same-owner fresh session | The second authenticated session retrieves exact accepted ID, revision, document and server fields. | Metadata-only before/after record plus controlled content comparison. |
| P2 — owner isolation | Foreign owner GET returns an appropriate denial with no private content. | Sanitized HTTP status, not the response body. |
| P3 — stale revision | Stale sync mutation returns 409 and cannot replace the accepted head. | Conflict receipt and later GET of unchanged head. |
| P4 — duplicate retry | Repeat the identical operation ID returns a replay rather than another revision. | Receipt IDs and final revision. |
| P5 — historical revision | Earlier revision is retrievable read-only; active head remains unchanged. | Revision index and selected historical metadata. |
| P6 — recovery | Copy-based or staged recovery retains both evidence and provenance. | Before/after IDs, source fingerprints and rollback receipt. |
| P7 — links and publication | Notebook/source IDs remain resolvable; private status is not incorrectly public. | Authority-specific link checks and rights/publishing state. |
| P8 — scientific reproducibility | Methods, source inputs, hashes and versions are available for an independent rerun. | Separate scientific acceptance, not a storage-status substitute. |
15. Offline evidence fixture and executable check
The companion package includes a stdlib-only Python checker and synthetic fixture. It compares expected and fresh-read observations, verifies both server fingerprint fields are unchanged, checks a local JSON comparison digest, tests recorded denial codes and ensures the previous revision and linked source references are represented. Its synthetic document is deliberately abbreviated; it is not a valid full Workspace project for API submission.
cd sc-persistent-state-developer-reference
python3 verify_persistence_contract.py synthetic-evidence.json --json
python3 -m unittest -v test_verify_persistence_contract.py
Expected result: structural-pass-only. That status cannot establish independent session authentication, actual PostgreSQL behavior, approved deployments or scientific validity; it only checks the recorded fixture for internal consistency.
16. Backend test entry points
After provisioning a disposable database, signed test identities and isolation boundaries in a checked-out repository, exercise the source test suites. The following are commands to run, not tests performed as part of this article revision:
cd backend
python -m pytest -q tests/test_local_first_sync_v2310.py
python -m pytest -q tests/test_thin_client_state_v2300.py
python -m pytest -q tests/test_sc_research_project01_project_workspace.py
Review the test fixtures and required environment variables before execution; some source tests require PostgreSQL or other runtime configuration. Add an integration assertion for the exact fresh-session round trip and old-revision retention if it is not already present. Do not treat unit-test pass counts as production acceptance.
17. Audit receipt and evidence packet
For a real staging acceptance run, capture the following metadata and store the raw project comparison separately under restricted access:
{
"runId": "synthetic-staging-run-01",
"repoCommit": "04f28743751634ed0bc64a5028290b4d29119400",
"deploymentVersion": "<verified-release-identifier>",
"projectId": "synthetic-project-01",
"ownerScope": "<opaque-owner-marker>",
"writeSession": "<opaque-session-marker-1>",
"freshReadSession": "<opaque-session-marker-2>",
"acceptedRevision": 2,
"readRevision": 2,
"projectFingerprintMatched": true,
"packageFingerprintMatched": true,
"documentMatched": true,
"foreignOwnerGet": 404,
"staleSyncPush": 409,
"previousRevisionReadable": true,
"linkedArtifactsVerified": false,
"publicationVerified": false,
"deploymentVerified": false
}
The Boolean example fields are proposed evidence labels, not API response properties. Record exact acceptance criteria, test-actor separation, source commit, image digest, migration version, authorization decisions, rollback readiness and any failed checks before marking the guide deployed-verified.
18. Migration, rollback and restore constraints
The canonical browser persistence extraction did not itself require a schema migration. That does not mean the entire Workspace backend has no migrations. Check the current deployed migration head, off-host backup validity, restore rehearsal and feature-flag state before staging write tests. A rollback must preserve newly accepted project revisions and durable sync receipts; do not point an old app version at incompatible data merely because an image rollback is available.
Use a disposable database for mutation tests. Do not connect test scripts to production PostgreSQL, mount production volumes, or run a copy-based restore into the active project. Escalate any data-integrity discrepancy with sanitized, metadata-only evidence.
19. Trust limits and non-claims
Source inspection establishes that the named modules, schemas and route handlers exist at the pinned commit. The companion checker establishes only that its synthetic fixture is internally consistent. Neither demonstrates which feature flags are enabled, the production migration state, current service availability, access after real session rotation, or scientific validation of a saved result.
A persistence fingerprint attests to a representation of data under a specific algorithm and trust context. It does not establish whether a scientific hypothesis is valid, whether measurements are unbiased, whether use rights are adequate or whether a Research article is approved for publication.
20. Required implementation anchors
- Pin the repository commit and deployed image digest; state whether the exact version has passed staging.
- Record the route mapping actually exposed by the deployment, its authentication mechanism and authorized operator role.
- Record the project and notebook schema versions and the applied migration set, plus the isolation of disposable test data.
- Link CI results for the real backend tests, observed fresh-session round-trip, owner-isolation refusal and stale-write conflict, and proof that historical revisions were not lost.
- Attach independent backup/restore evidence, rollback decision, cross-product publication gate state and any unresolved source integrity or access limitation.
21. Technical references
- Repository: owner-scoped project heads, fingerprints, revisions and conflict handling
- Local-first sync: envelopes, conflict receipts, replay and rehydration
- Backend routes: projects, revisions, notebooks, sync and thin-client state
- Typed request schemas and complete project schema
- Identity and authorization selection
- Canonical browser persistence runtime
- Persistence integrity and quarantine design
- Canonical state/persistence boundary
- Copy-based browser-local restore points
- Sync contract tests and thin-client state tests
Source review: November 20, 2026. Inspected commit: 04f28743751634ed0bc64a5028290b4d29119400. Documentation verification remains distinct from deployed or independent scientific acceptance.
