Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
834872f
intake: stories index intake draft + manifest schema (ge-bvf)
SorraTheOrc Jan 18, 2026
12d5ac3
ge-3gh: Add Director smoke test with manifest-driven story selection
SorraTheOrc Jan 18, 2026
91eaf9e
ge-3gh: Fix manifest loading in smoke test - use hardcoded manifest
SorraTheOrc Jan 18, 2026
f6ad359
bd sync: 2026-01-18 13:57:24
SorraTheOrc Jan 18, 2026
c04442a
bd sync: 2026-01-18 15:52:59
SorraTheOrc Jan 18, 2026
a4391b4
docs(prd): update GDD_M2_ai_assisted_branching with ge-hch.5.16 runti…
SorraTheOrc Jan 18, 2026
dac5f14
docs(prd): incorporate ge-hch.5.16 runtime integration, checkpointing…
SorraTheOrc Jan 18, 2026
463f7f6
style(prd): clarity edits from automated review
SorraTheOrc Jan 18, 2026
fa00fd8
chore(prd): add security & compliance notes from automated review
SorraTheOrc Jan 18, 2026
0d4bb1d
ci(replay): run replay-gate only on Node 20.x (drop 18.x)
SorraTheOrc Jan 19, 2026
2272aee
chore: ignore .opencode/tmp and remove intake draft from PR
SorraTheOrc Jan 19, 2026
6957c18
docs(prd): add dedicated PRD for ge-hch.5.16 Runtime Integration & Hooks
SorraTheOrc Jan 19, 2026
8f334b8
revert change to original prd
SorraTheOrc Jan 19, 2026
8ea71a4
revert(docs/prd): restore GDD_M2_ai_assisted_branching.md from origin…
SorraTheOrc Jan 19, 2026
0eaa867
docs(prd): rename PRD to PRD_M2_Runtime_integration_and_hoks.md
SorraTheOrc Jan 19, 2026
9fd8373
bd: update ge-hch.5.16 status, assignee, comment, and external_ref (l…
SorraTheOrc Jan 19, 2026
d795b15
docs(prd): specify branch_history minimal resume payload, storage, an…
SorraTheOrc Jan 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .beads/issues.jsonl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/replay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]
node-version: [20.x]
os: [ubuntu-latest]
steps:
- name: Checkout
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ ci-artifacts/

# Local test reports
junit-report.xml

# Opencode local temp files
.opencode/tmp/
107 changes: 107 additions & 0 deletions docs/prd/PRD_M2_Runtime_integration_and_hoks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Product Requirements Document

## Introduction

### One-liner
Runtime Integration & Hooks: formalize AI-branch injection with a 12-state integration state machine, atomic checkpoints and rollback, and save/load compatibility so AI branches persist safely across sessions.

### Problem statement
The existing M2 work defines proposal lifecycle and Director/Writer behavior, but runtime integration is underspecified. Without a formal state machine, transactional checkpoints, and clear persistence rules, AI branch injection can lead to inconsistent runtime state, save corruption, or unreproducible playthroughs. This PRD (ge-hch.5.16) defines the runtime contract, deliverables, and acceptance criteria for safe integration of AI-generated branches into live play sessions.

### Goals
- Define a deterministic 12-state integration state machine and transition rules for branch injection.
- Implement atomic checkpoint/commit/rollback semantics that prevent save corruption.
- Persist branch integration metadata and audit logs to support reproducibility and debugging.
- Ensure save/load resumes in-progress branches or safely roll back corrupted ones with a clear player-facing message.

### Non-goals
- This PRD does not redefine Director heuristics, policy rules, or Writer prompts (those remain in M2 core PRD). It focuses only on runtime integration mechanics and persistence.

## Users

### Primary users
- Players (desktop/mobile) who must experience robust save/load and no corruption when AI branches are integrated.

### Secondary users
- Engineers implementing runtime, save, and persistence systems.
- QA and playtesters validating save/load, rollback, and replay behavior.
- Producers needing audit logs to investigate incidents.

## Requirements

### Functional requirements (MVP)
- Integration state machine
- Formalize a 12-state state machine covering: ProposalAccepted, PreInjectCheckpoint, Injecting, Executing, CheckpointOnBeat, CommitPending, Committed, RollbackPending, RollingBack, RolledBack, TerminalSuccess, TerminalFailure. Define allowable transitions and idempotency guarantees.
- Atomic checkpoint/rollback
- Checkpoints capture necessary runtime state (player inventory, variables, scene index, branch progress markers). Checkpoints must be verifiable (checksums) and restorable deterministically.
- Rollback restores to the last valid checkpoint and clears transient branch markers.
- Save/load compatibility
- Save files must include `branch_history` metadata that records in-progress branches and a minimal resume payload. Required fields (types):
- `schema_version` (integer) — branch_history schema version.
- `branch_id` (string) — unique branch instance id.
- `proposal_hash` (string|null) — content hash of the proposal, if available.
- `created_at` (string, date-time)
- `updated_at` (string, date-time)
- `integration_state` (string, enum: ProposalAccepted, PreInjectCheckpoint, Injecting, Executing, CheckpointOnBeat, CommitPending, Committed, RollbackPending, RollingBack, RolledBack, TerminalSuccess, TerminalFailure)
- `last_checkpoint_id` (string|null)
- `last_checkpoint_ts` (string, date-time|null)
- `resume_payload` (object|null) — small engine-specific payload required to resume (for example: next scene index, pending actions). Keep this minimal to avoid large save files.
- Minimal resume payload rule: the save should embed only the small, deterministic information required to resume or rollback (ids, timestamps, and a compact `resume_payload`). Full audit logs (detailed transition records, validation reports, director decisions) must not be embedded by default.
- Audit logs and diagnostics: send full integration logs to the telemetry/external store with configurable retention. Saves may carry `branch_history.audit_ref` (string) which references the external audit id when telemetry is available; loader falls back to embedded data if external logs are unavailable.
- Privacy & security: embedded `branch_history` must redact PII. Prefer storing sensitive details in the external telemetry store where access control and encryption at rest can be enforced. Document what is considered PII in `docs/dev/`.
- Migration & versioning: include `schema_version` and a migration strategy. Loaders must accept older `schema_version` values and either migrate them or conservatively rollback if migration is unsafe.
- Resume policy (deterministic & conservative): when loading, resume a branch only if `last_checkpoint_id` exists and the checkpoint's checksum/version matches the expected value. If a deterministic resume cannot be guaranteed, perform an automatic rollback to the last valid checkpoint, log the decision, and notify the player with the graceful recovery message.
- Resume timing: resumption should occur at the next safe beat (see hook points `pre_checkpoint`/`post_checkpoint`) so the runtime can re-establish transient systems before continuing execution.
- Suggested canonical artifacts: provide a canonical JSON Schema and examples to live at `docs/dev/branch-history.schema.json` and `docs/dev/examples/branch-history-example.json` so implementers have an exact reference.
- Audit logging and persistence
- Record transitions, decisions, validation references, and rollback causes in an append-only integration log associated with a save id and player id (redact PII).
- Hook manager API
- Provide `src/runtime/hook-manager` with events: `pre_inject`, `post_inject`, `pre_checkpoint`, `post_checkpoint`, `pre_commit`, `post_commit`, `on_rollback` and allow subscribers for telemetry, persistence, and UI.

### Non-functional requirements
- Determinism
- Checkpoint/restore must be deterministic; running the same sequence from the same checkpoint reproduces state.
- Reliability
- No save file corruption allowed; recoverable errors must trigger a rollback path and be logged.
- Performance
- Checkpoint and commit operations must complete within a reasonable window (configurable), default target 2s.
- Security & privacy
- Integration logs must redact PII; access to logs must be access-controlled and encrypted at rest.

### Integrations
- Ink runtime save/load system (must be extended to carry `branch_history` metadata). Suggest adding `src/runtime/save-adapter.js` / `src/runtime/load-adapter.js` hooks.
- Telemetry system (emit integration events and lifecycle transitions).

## Release & Operations

### Rollout plan
- Phase A — Design & tests
- Finalize state machine; add unit tests for each transition and idempotency.
- Create a save metadata schema and migration plan.
- Phase B — Internal pilot
- Implement hook manager and checkpoint/rollback primitives; run pilot on internal demo story with feature flag enabled.
- Phase C — Soft launch
- Expose to small subset of users with monitoring and operator alerts for frequent rollbacks or save issues.
- Phase D — General availability
- Remove pilot flags and extend to more stories.

### Quality gates
- Unit tests covering state machine transitions and checkpoint/rollback logic (≥ 80% coverage for new runtime module).
- Fuzzed save/load test suite that generates corrupted checkpoints and validates rollback behavior.
- End-to-end Playwright smoke tests: save mid-branch, reload, and verify either resume or graceful rollback.

### Risks & mitigations
- Risk: Partial checkpoint writes corrupt saves
- Mitigation: write checkpoints to temporary file and atomically rename on success; include checksums and versioned migration support.
- Risk: Inconsistent branch resumption logic leads to subtle divergences
- Mitigation: conservative resume policy — prefer rollback unless deterministic resume conditions are met; log decisions for audit.

## Open Questions
- Exact fields and formats for `branch_history` (I can propose a schema).
- Where to store integration logs (local file vs telemetry warehouse) and retention policy.
- Whether to expose an operator tooling endpoint to force rollback or replay a branch for debugging.

---

Change log:
- 2026-01-19: Created dedicated PRD `docs/prd/ge-hch.5.16.md` focusing runtime integration, state machine, checkpoint/rollback, and save/load behavior. This complements the broader M2 PRD which remains unchanged.
Loading