> For the complete documentation index, see [llms.txt](https://faction-os.gitbook.io/faction-os-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase22-session06-persistence-lifecycle/tasks.md).

# Task Checklist

**Session ID**: `phase22-session06-persistence-lifecycle` **Total Tasks**: 18 **Estimated Duration**: 2-3 hours **Created**: 2026-07-05

***

Legend: `[x]` completed; `[ ]` pending; `[P]` parallelizable; `[SNNMM]` session ref; `TNNN` task ID.

***

## Setup (3 tasks)

* [x] T001 \[S2206] Verify Session 05 store integration artifacts and current projection helper exports (`.spec_system/specs/phase22-session05-store-folding-and-selectors/validation.md`, `apps/web/src/store/useGameStore.ts`, `apps/web/src/lib/gameProjection.ts`)
* [x] T002 \[S2206] \[P] Review existing replay persistence test patterns and teardown requirements (`apps/web/tests/replayPersist.test.ts`, `apps/web/tests/gameProjectionStore.test.ts`)
* [x] T003 \[S2206] \[P] Add projection persistence imports for storage key, cadence constants, write helper, and guard helper (`apps/web/src/store/useGameStore.ts`)

***

## Foundation (4 tasks)

* [x] T004 \[S2206] Refactor the store-local projection fold helper to return the next projection plus persistence context derived from `replayingSinceMs` and `useSettingsStore` (`apps/web/src/store/useGameStore.ts`)
* [x] T005 \[S2206] Add module-local projection persistence pending state, idle timer, max-latency timer, and latest-projection tracking (`apps/web/src/store/useGameStore.ts`)
* [x] T006 \[S2206] Implement `flushGameProjectionPersist()` and exported `__flushGameProjectionPersist()` with timer cleanup and storage failure tolerance (`apps/web/src/store/useGameStore.ts`)
* [x] T007 \[S2206] Add idempotent page lifecycle listener installation for hidden `visibilitychange`, `pagehide`, and `beforeunload` flushes with cleanup-safe handlers (`apps/web/src/store/useGameStore.ts`)

***

## Implementation (7 tasks)

* [x] T008 \[S2206] Schedule projection persistence from `applyEvent(e)` only when the reducer changes `gameProjection` and `shouldPersistGameProjection(ctx)` allows writes (`apps/web/src/store/useGameStore.ts`)
* [x] T009 \[S2206] Preserve existing replay-buffer capture, event switch behavior, and selector behavior while adding projection scheduling (`apps/web/src/store/useGameStore.ts`)
* [x] T010 \[S2206] Update `resetToSeed()` to clear pending projection writes, remove `GAME_PROJECTION_STORAGE_KEY`, and create a fresh in-memory projection (`apps/web/src/store/useGameStore.ts`)
* [x] T011 \[S2206] Add debounce and synchronous flush tests proving changed projection state persists only after `__flushGameProjectionPersist()` or timer expiry (`apps/web/tests/gameProjectionStore.test.ts`)
* [x] T012 \[S2206] Add max-latency tests proving a burst of changed events flushes by `GAME_PROJECTION_PERSIST_MAX_LATENCY_MS` even when the idle debounce keeps resetting (`apps/web/tests/gameProjectionStore.test.ts`)
* [x] T013 \[S2206] Add replay and mock no-write tests proving changed in-memory projection state does not persist while replaying or when `mockEnabled` is true (`apps/web/tests/gameProjectionStore.test.ts`)
* [x] T014 \[S2206] Add page lifecycle and unavailable-storage tests for hidden `visibilitychange`, `pagehide`, `beforeunload`, null storage, and throwing storage behavior (`apps/web/tests/gameProjectionStore.test.ts`)

***

## Testing (4 tasks)

* [x] T015 \[S2206] Update reset tests to prove `resetToSeed()` removes `localStorage["factionos-game-v1"]` and leaves a fresh projection (`apps/web/tests/gameProjectionStore.test.ts`)
* [x] T016 \[S2206] Run focused projection persistence, reducer, and replay persistence tests (`npm test -- apps/web/tests/gameProjectionStore.test.ts apps/web/tests/gameProjection.test.ts apps/web/tests/replayPersist.test.ts`)
* [x] T017 \[S2206] Run web package typecheck and changed-file Biome check (`npm --workspace @factionos/web run typecheck`, `npm exec -- biome check apps/web/src/store/useGameStore.ts apps/web/src/lib/gameProjection.ts apps/web/tests/gameProjectionStore.test.ts apps/web/tests/replayPersist.test.ts`)
* [x] T018 \[S2206] Validate ASCII and LF requirements for session artifacts and changed files (`.spec_system/specs/phase22-session06-persistence-lifecycle`, `apps/web/src/store/useGameStore.ts`, `apps/web/src/lib/gameProjection.ts`, `apps/web/tests/gameProjectionStore.test.ts`, `apps/web/tests/replayPersist.test.ts`)

***

## Completion Checklist

* [x] All tasks marked `[x]`
* [x] All tests and checks passing
* [x] All files ASCII-encoded with LF line endings
* [x] implementation-notes.md updated
* [x] Ready for `creview` (next step in the implement -> creview -> validate sequence)

***

## Next Steps

Run the `creview` workflow step.


---

# 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://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase22-session06-persistence-lifecycle/tasks.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.
