docs(architecture): define draft preservation, recovery paths, and terminal export contracts in Issue 4

- Establish the response state triad (SUBMITTED, DRAFT, UNANSWERED) in attempt.json.
- Decouple interaction submission status from demonstrated cognitive attainment.
- Mandate valid lifecycle combinations: COMPLETED requires all SUBMITTED; CLOSED_EARLY and TIMED_OUT require at least one DRAFT or UNANSWERED.
- Enforce generalized server-side serialization with strictly absorbing terminal states.
- Commit final required response submission and transition to COMPLETED atomically.
- Delineate nonterminal recovery (live resume) from terminal export recovery (retry publication without reopening session).
- Define evaluator rules across response states: evaluate drafts without penalty; report no evidence for UNANSWERED without negative knowledge inference.
- Clarify that drafts require learner-generated modifications; untouched initial fields remain UNANSWERED.
This commit is contained in:
kiskaadee committed 2026-11-11 14:45:46 -05:00
1 parent b28ed51026
commit 5f3295b948
4 files changed
+54 -19

No files matched your search

+23 -11
View File
@@ -92,9 +92,22 @@ The system communicates strictly across four versioned JSON contracts:
2. **`rubric.json` (Private Evaluation Contract):**
Retained by the calling agent workflow and supplied only to the evaluator. Contains learning objectives, observable criteria (Complete / Partial / Insufficient), categorical failure modes, misconception signatures, and explicit canonical objective references for each criterion (or a deterministic question-to-criterion mapping) to eliminate ambiguous natural-language inference.
3. **`attempt.json` (Durable Execution Evidence):**
Produced by `live-quiz` via atomic publication. Must conform structurally to the versioned attempt schema contract (`attempt.schema.json`). Contains attempt identity, assessment/version hashes, workspace attribution, terminal status (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`), active and wall-clock durations, pause event logs, and submitted responses (preserving question-level canonical objective references verbatim).
Produced by `live-quiz` via atomic publication. Must conform structurally to the versioned attempt schema contract (`attempt.schema.json`). Contains attempt identity, assessment/version hashes, workspace attribution, terminal lifecycle status (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`), active and wall-clock durations, pause event logs, and an array of responses preserving question-level canonical objective references verbatim. Every item in the responses array explicitly records its interaction state via the **Response State Triad**:
- `SUBMITTED`: Explicitly confirmed by the learner (including explicit blank submissions).
- `DRAFT`: Latest acknowledged autosave payload and receipt timestamp preserved at session termination, even if unsubmitted. A draft represents an acknowledged learner-generated modification (initial empty fields remain `UNANSWERED`). (Per-question active duration is provisional pending measurement definitions).
- `UNANSWERED`: Zero acknowledged learner input recorded (payload is null).
*Valid Lifecycle & Response Combinations:*
While interaction status and demonstrated criterion attainment remain independent dimensions, lifecycle outcomes constrain valid response combinations:
- `COMPLETED`: Strictly requires every questionnaire item to have `response_status: SUBMITTED` (explicit blank submissions qualify).
- `CLOSED_EARLY`: At least one response must be `DRAFT` or `UNANSWERED`, following an explicit learner termination action.
- `TIMED_OUT`: At least one response must be `DRAFT` or `UNANSWERED`, following authoritative timer expiration.
*Generalized Server-Side Serialization & Absorbing Terminal States:* All response mutations (autosaves and submissions) and terminal transitions (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`) are serialized server-side within SQLite transactions. The final required response submission and transition to `COMPLETED` must be committed atomically. Once any terminal lifecycle transition commits, its status is strictly immutable and absorbing: all subsequent response mutations and competing terminal transition attempts are rejected.
4. **`evaluation.json` (Diagnostic Assessment Report):**
Produced by `quiz-evaluator`. Contains criterion-level attainment ratings correlated deterministically to canonical objective references, failure-mode classifications (`CONCEPTUAL`, `LOGICAL`, `SYNTACTIC`, `OMISSION`, `REGRESSION`), misconception hypotheses with confidence levels, and discussion probes for debriefing.
*Evaluator Contract Across the Response State Triad:*
- Explicit Blank `SUBMITTED`: Evaluated as an intentional empty response against rubric criteria.
- `DRAFT`: Evaluated as available evidence of learning (identifying valid intermediate reasoning and progress) without automatic penalty for draft status. Discloses draft provenance, avoids hallucinating what the learner would have written with more time, and distinguishes demonstrated criteria from unestablished criteria.
- `UNANSWERED`: Reports that no response evidence exists. Must not infer a misconception or conclude that the learner lacks underlying competency solely because no response was recorded.
---
@@ -137,21 +150,20 @@ During active assessment, `live-quiz` maintains state in a temporary SQLite data
### 5.3 Atomic Publication & Journal Deletion
Upon reaching a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`):
1. The server serializes the final attempt payload.
2. Writes to a temporary file in the destination directory.
1. The server serializes the final attempt payload, preserving all submitted responses, acknowledged unsubmitted drafts (as `DRAFT`), and unattempted questions (as `UNANSWERED`).
2. Writes to a temporary file (`.attempt.json.tmp`) in the destination directory.
3. Validates the JSON structure and flushes/syncs to disk.
4. Atomically renames the file to the final destination (`attempt.json`).
5. Closes database handles and unlinks the temporary SQLite journal.
5. Closes database handles and unlinks the temporary SQLite journal file set (`.sqlite3`, `-wal`, `-shm`).
6. Exits with code 0.
*Invariant:* The temporary journal is never deleted if export publication fails.
*Invariant:* The temporary journal file set is never deleted if export publication fails. Recovery (`live-quiz recover`) retries publication under the exact same `attempt_id`.
### 5.4 Explicit Recovery Command
To resume an interrupted or paused attempt:
```bash
live-quiz recover --from-path ~/.local/state/live-quiz/sessions/<attempt-id>.sqlite3
```
Recovery validates the journal, restores the authoritative clock, re-mounts drafts, and starts the server without altering the attempt identity.
### 5.4 Two Distinct Recovery Paths
Invoking `live-quiz recover --from-path ~/.local/state/live-quiz/sessions/<attempt-id>.sqlite3` routes deterministically based on journal state:
1. **Nonterminal Recovery:** If the journal records an active or paused attempt (`RUNNING` or `PAUSED`), recovery restores the authoritative countdown clock, re-mounts acknowledged drafts, resumes the local HTTP server, and displays an in-browser resume control under the exact same `attempt_id`.
2. **Terminal Export Recovery:** If the journal already records a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`) but atomic export failed, recovery reconstructs and retries `attempt.json` publication *without reopening the assessment, restarting the timer, or permitting further modifications*.
In both paths, the temporary SQLite journal file set (`.sqlite3`, `-wal`, `-shm`) is unlinked only after durable export publication succeeds.
---
@@ -44,12 +44,14 @@ stateDiagram-v2
- **Storage Location & Journal File Set:** Journals reside on persistent local storage (`~/.local/state/live-quiz/sessions/`), never in volatile tmpfs. In WAL mode, the journal consists of the primary database (`<attempt-id>.sqlite3`) and its companion files (`<attempt-id>.sqlite3-wal`, `<attempt-id>.sqlite3-shm`). Because committed transactions may reside in the `-wal` file before checkpointing, recovery and lifecycle operations must manage and preserve the entire journal file set.
- **Crash Recovery Scope:** Recovery guarantees restoration of all *acknowledged* state. Unacknowledged in-flight client keystrokes that never completed an HTTP transaction are explicitly excluded.
- **Active-Time Recovery:** Active time is measured via a monotonic clock and checkpointed periodically (~1s interval). On recovery after an unexpected crash, the active countdown resumes from the last committed checkpoint. Process downtime while dead is excluded from the active-time budget and recorded separately as an interruption event.
5. **Journal Destruction Invariant:**
- Upon reaching a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`), the server publishes `attempt.json`.
- The temporary SQLite journal file set (`.sqlite3`, `-wal`, `-shm`) is unlinked **only after durable export publication succeeds** and all database connections are closed.
6. **Explicit Recovery Command:**
5. **Journal Destruction Invariant & Draft Preservation:**
- Upon reaching a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`), the server serializes `attempt.json`, preserving all submitted responses, acknowledged unsubmitted drafts (as `DRAFT`), and unattempted questions (as `UNANSWERED`).
- The temporary SQLite journal file set (`.sqlite3`, `-wal`, `-shm`) is unlinked **only after durable export publication succeeds** and all database connections are closed. If publication fails, the journal remains intact for retry via recovery.
6. **Explicit Recovery Command & Two Recovery Paths:**
- If a process is killed unexpectedly (`SIGKILL`) or grace period expires while paused, the journal set remains on disk.
- Running `live-quiz recover --from-path <journal.sqlite3>` validates the journal set (leveraging companion `-wal` for recovery), restores the authoritative clock, reloads drafts, and resumes the server under the exact same `attempt_id`.
- Running `live-quiz recover --from-path <journal.sqlite3>` inspects journal state and executes one of two deterministic paths:
1. **Nonterminal Recovery:** For `RUNNING` or `PAUSED` attempts, validates the journal set (leveraging companion `-wal`), restores the authoritative clock, reloads drafts, and resumes the server under the exact same `attempt_id`.
2. **Terminal Export Recovery:** If the journal already records a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`) but publication failed, recovery retries `attempt.json` publication directly from the journal without reopening the assessment session, restarting the timer, or permitting further modifications.
- *Recovery Idempotency:* If recovery is invoked on a journal whose `attempt.json` was already successfully published, it verifies the export, cleans up the journal file set, and exits cleanly.
## Alternatives Considered
@@ -13,10 +13,11 @@ Establish **`attempt.json` as a standardized, versioned JSON contract** publishe
- Written to a temporary file (`.attempt.json.tmp`) within the target directory.
- Validated for structural correctness and flushed/fsynced to persistent storage.
- Atomically renamed to the final destination path (`attempt.json`).
- *Failure Guarantee:* If publication fails at any stage (e.g. disk full, permissions error), the temporary SQLite journal is retained, and the process exits with an error status.
- *Failure Guarantee:* If publication fails at any stage (e.g. disk full, permissions error), the temporary SQLite journal file set is retained intact, and the process exits with an error status. Recovery (`live-quiz recover`) retries publication under the exact same `attempt_id`.
2. **Reattempt vs. Recovery Semantics:**
- **Recovery (`live-quiz recover`):** Resumes an interrupted attempt, preserving the existing `attempt_id` and journal state.
- **Reattempt (`live-quiz start`):** Launches a fresh execution against the *same* immutable assessment definition, generating a distinct new `attempt_id`.
- **Nonterminal Recovery (`live-quiz recover`):** Resumes an interrupted or paused attempt, restoring clock and drafts under the existing `attempt_id`.
- **Terminal Export Recovery (`live-quiz recover`):** Retries failed atomic publication directly from the terminal journal without reopening the assessment, restarting the timer, or permitting answer modifications.
3. **Contract Attributes & Canonical Objective Traceability:**
Every exported attempt contains explicit provenance:
- `schema_version`
@@ -29,6 +30,25 @@ Establish **`attempt.json` as a standardized, versioned JSON contract** publishe
*Structural vs. Semantic Validation Invariant:*
The exported payload must conform structurally to the versioned attempt schema contract (`attempt.schema.json`). However, the engine maintains zero semantic awareness of external registries: it does not validate, resolve, or query objective identifiers against external catalogs, preserving them verbatim for downstream evaluation. The exact schema layout for preserving question-to-objective response traceability remains open until the JSON schema contracts are formally authored.
4. **Response State Triad & Attainment Decoupling:**
Each item in `responses[]` represents its interaction state independently of the assessment lifecycle status (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`):
- `SUBMITTED`: Explicitly confirmed by the learner. Includes explicit blank submissions where the learner intentionally submitted an empty response.
- `DRAFT`: Autosaved input acknowledged by SQLite commit-before-ack but unsubmitted when session terminated. Represents an acknowledged learner-generated modification (initial empty fields remain `UNANSWERED`). The latest acknowledged draft payload and server-side receipt timestamp are preserved verbatim. (Per-question active duration is designated provisional pending formal measurement definitions).
- `UNANSWERED`: Zero acknowledged learner input recorded (payload is `null`).
*Valid Terminal/Response State Constraints:*
- `COMPLETED`: Strictly requires every questionnaire item to have `response_status: SUBMITTED` (explicit blank submissions qualify).
- `CLOSED_EARLY`: At least one response must be `DRAFT` or `UNANSWERED`, following an explicit learner termination action.
- `TIMED_OUT`: At least one response must be `DRAFT` or `UNANSWERED`, following authoritative timer expiration.
*Generalized Server-Side Serialization & Absorbing Terminal States:*
All response mutations (draft autosaves, explicit submissions) and terminal lifecycle transitions (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`) are serialized server-side within SQLite transactions. The final required response submission and transition to `COMPLETED` must be committed atomically. Once any terminal lifecycle transition commits, its status is strictly immutable and absorbing: all subsequent response mutations and competing terminal transition attempts are rejected.
*Attainment vs. Submission Independence:*
Submission status describes the user interaction, not the correctness or cognitive quality of the content. `quiz-evaluator` enforces evidence-first principles across the response triad:
- Explicit Blank `SUBMITTED`: Evaluated as an intentional empty response against rubric criteria.
- `DRAFT`: Evaluated as available evidence of learning without automatic penalty for draft status, disclosing draft provenance and reporting demonstrated vs. unestablished criteria.
- `UNANSWERED`: Reports that no response evidence exists; must not infer misconceptions or conclude that the learner lacks underlying knowledge solely due to absence of recorded input.
## Alternatives Considered
- **Direct SQLite Database Querying by Evaluators / Future LMS:** Rejected. Exposing internal database tables couples external consumers to `live-quiz` schema migrations.
@@ -14,7 +14,7 @@ Provide an MVP collection of five modular, portable reference skills in the repo
| **`learning-objectives`** | Formulates observable, assessable competencies; searches external catalog to propose new records and relationships. | Topic / Goals / Context, Registry candidates | Proposed objectives & evidence criteria |
| **`quiz-designer`** | Compiles an approved Assessment Brief into public and private contracts; uses learning history to inform context and difficulty. | Assessment Brief, Learner history | `questionnaire.json`, `rubric.json` |
| **`live-quiz`** | Operational CLI wrapper executing and recovering assessments; structurally preserves canonical objective references. | Questionnaire path, CLI flags | Browser session URL, `attempt.json` |
| **`quiz-evaluator`** | Context-isolated post-hoc evaluation of attempt against rubric; deterministically correlates evidence with canonical objective references. | `rubric.json`, `attempt.json` | `evaluation.json` |
| **`quiz-evaluator`** | Context-isolated post-hoc evaluation of attempt against rubric; evaluates submitted answers and drafts as learning evidence without automatic penalty; deterministically correlates evidence. | `rubric.json`, `attempt.json` | `evaluation.json` |
| **`tutor`** | Orchestrates learning dialogue, proposes scope, logs contextual observations against stable objective IDs, and leads debrief. | Learner interaction, Registry/History | Consolidated learning experience, Contextual observations |
### Architectural Invariants:
@@ -34,6 +34,7 @@ Provide an MVP collection of five modular, portable reference skills in the repo
- **Exposure vs. Mastery:** Prior exposure informs assessment design to avoid redundant introductory testing, but exposure is never equated to mastery. Difficulty calibration accounts for familiarity, task complexity, context novelty, assistance level, and demonstrated independent performance.
- **Scoping Gate:** Assessment readiness is evaluated contextually when the Tutor compiles the **Assessment Brief**, rather than as an intrinsic boolean flag in the catalog.
- **Deterministic Evaluation Correlation:** Evaluation evidence is correlated deterministically to canonical objective references using explicit mappings across rubric criteria and attempt responses, eliminating ambiguous natural-language guessing.
- **Evidence-First Evaluation Across Response States:** The evaluator evaluates available work in `DRAFT` responses (e.g. partial derivations, code approaches) against the rubric without penalizing draft status. It discloses draft provenance, distinguishes demonstrated criteria from unestablished criteria, and does not speculate on unwritten thoughts. For `UNANSWERED` questions, it reports that no response evidence exists without inferring misconceptions or concluding that the learner lacks underlying knowledge solely from missing input.
- **Abstract Capability Dependency:** Reference skills depend on an abstract registry and history capability (e.g. via CLI, local HTTP, or file protocols) rather than hardcoding specific storage implementations or database technologies. Detailed registry architecture, sync strategies, and exact schema mappings remain open design questions.
## Alternatives Considered