Compare commits
2
Commits
521cd30348
...
2280595c33
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2280595c33 | ||
|
|
8e0adb3248 |
No files matched your search
@@ -124,8 +124,10 @@ The system explicitly separates:
|
||||
### 5.2 Ephemeral SQLite Session Journal
|
||||
During active assessment, `live-quiz` maintains state in a temporary SQLite database (`~/.local/state/live-quiz/sessions/<attempt-id>.sqlite3`):
|
||||
- Server commits acknowledged draft updates, answer submissions, and timing events atomically to SQLite.
|
||||
- Pausing commits state and **allows the server process to exit cleanly**, preventing idle background processes.
|
||||
- Unexpected kills (`SIGKILL`, power failure) leave the journal intact.
|
||||
- **Durable Pause Checkpoint & In-Browser Resume:** Clicking **Pause** commits state, freezes active time, records `status = PAUSED` in SQLite, and displays an in-browser Resume control.
|
||||
- **Configurable Pause Grace Period (Default: 2 Hours):** The server remains alive and accessible in the browser during a 2-hour window (`--pause-grace-period 2h`). If resumed within this window, the assessment continues instantly in the browser.
|
||||
- **Grace-Period Expiration:** If the 2-hour grace period expires without resumption, the server process terminates cleanly to prevent zombie processes, retaining the journal with status `PAUSED` and emitting `outcome: SUSPENDED` on stdout.
|
||||
- Unexpected kills (`SIGKILL`, power failure) leave the journal intact for recovery.
|
||||
|
||||
### 5.3 Atomic Publication & Journal Deletion
|
||||
Upon reaching a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`):
|
||||
|
||||
@@ -4,15 +4,53 @@
|
||||
- Date: 2026-11-10
|
||||
|
||||
## Context
|
||||
When an AI agent or skill invokes `live-quiz`, the execution must not block agent reasoning indefinitely, yet the agent must be notified when the assessment concludes. We needed a process coordination mechanism that works cleanly without tight coupling to proprietary agent harnesses.
|
||||
When an AI agent or skill invokes `live-quiz`, the execution must not block agent reasoning indefinitely, yet the agent must be notified when the assessment concludes or suspends. We needed a process coordination mechanism that works cleanly without tight coupling to proprietary agent harnesses, while correctly distinguishing between process exit and assessment completion.
|
||||
|
||||
## Decision
|
||||
Design `live-quiz` as a standard foreground UNIX process whose termination signals session conclusion. In agent environments that support managed asynchronous tasks (such as Antigravity background tasks), the agent launches `live-quiz start`, yields the URL to the user, and terminates its turn. When `live-quiz` reaches a terminal state, its process exits with code 0, naturally triggering reactive wakeup of the agent harness.
|
||||
Design `live-quiz` as a standard foreground UNIX process whose termination signals that an execution cycle has ended, but **not necessarily that the assessment has concluded**:
|
||||
|
||||
1. **Independent Lifecycles:**
|
||||
$$\text{Process State (Running / Exited)} \neq \text{Assessment State (RUNNING / PAUSED / COMPLETED)}$$
|
||||
A process exit indicates only that the current HTTP execution cycle has ended.
|
||||
2. **Structured Lifecycle Outcome:**
|
||||
Upon process termination, `live-quiz` emits a machine-readable JSON outcome on stdout:
|
||||
- **`FINALIZED`:** The assessment reached a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`). `attempt.json` was durably exported. Caller proceeds to evaluation.
|
||||
- **`SUSPENDED`:** The assessment was paused and the 2-hour grace period expired (or process terminated). The SQLite journal is retained. Caller does **not** invoke evaluation.
|
||||
- **`ERROR`:** An operational error occurred. The SQLite journal is retained for recovery.
|
||||
3. **Sequence Diagram:**
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
autonumber
|
||||
actor Learner
|
||||
participant Browser
|
||||
participant Server as live-quiz Server
|
||||
participant SQLite as SQLite Journal
|
||||
participant Caller as Agent / Harness
|
||||
|
||||
Learner->>Browser: Click Pause
|
||||
Browser->>Server: POST /api/session/pause
|
||||
Server->>SQLite: Commit drafts & transition status to PAUSED
|
||||
SQLite-->>Server: Transaction committed
|
||||
Server-->>Browser: 200 OK (Suspension confirmed)
|
||||
Browser->>Learner: Display "Assessment Paused" + Resume button
|
||||
|
||||
alt Resumed within 2-hour grace period
|
||||
Learner->>Browser: Click Resume
|
||||
Browser->>Server: POST /api/session/resume
|
||||
Server->>SQLite: Commit status RUNNING & unfreeze clock
|
||||
Server-->>Browser: 200 OK
|
||||
else Grace period (2h) expires without resume
|
||||
Server->>Caller: Process exits (stdout: outcome=SUSPENDED)
|
||||
Caller->>Caller: Inspect outcome: SUSPENDED (Do NOT invoke Evaluator)
|
||||
end
|
||||
```
|
||||
|
||||
## Alternatives Considered
|
||||
- **Antigravity Sidecars and `agentapi`:** Rejected. Testing revealed that `agentapi` relies on Antigravity internal language server environment variables (`ANTIGRAVITY_LS_ADDRESS`, `ANTIGRAVITY_CSRF_TOKEN`), breaking execution when run outside the agent environment and introducing unnecessary daemon infrastructure.
|
||||
- **Indefinite Synchronous Blocking Command:** Rejected. Fails over human time scales; if a learner pauses or steps away, long-running agent tool calls timeout or hang.
|
||||
- **Polling Loop:** Rejected. Wastes tokens and agent execution turns polling local status endpoints.
|
||||
- **Treating Every Process Exit as Assessment Completion:** Rejected. Conflating process termination with assessment finalization leads to evaluating incomplete paused attempts.
|
||||
- **Immediate Process Exit on Pause:** Rejected. Turning an ordinary short interruption (e.g. 2-minute phone call) into an unrecoverable dead browser tab destroys UX.
|
||||
- **Antigravity Sidecars and `agentapi`:** Rejected. Coupled to internal language server environment variables.
|
||||
|
||||
|
||||
## Consequences
|
||||
- **Positive:** Complete decoupling from harness internals; standard OS process semantics (`exit 0`); portable across Antigravity, Claude Code, terminal shells, and CI pipelines.
|
||||
|
||||
@@ -9,27 +9,56 @@ During an assessment, the application must withstand interruptions (unexpected p
|
||||
## Decision
|
||||
Use a temporary, local SQLite database (`~/.local/state/live-quiz/sessions/<attempt-id>.sqlite3`) strictly as an ACID-compliant **write-ahead session journal** during active execution:
|
||||
1. **Three Separated Lifecycles:**
|
||||
- *Server Process:* Ephemeral (runs on demand, exits on terminal state or explicit pause).
|
||||
- *Server Process:* Ephemeral (runs on demand, exits on finalization or pause grace-period expiration).
|
||||
- *Assessment Instance:* Persistent concept identified by stable IDs and immutable questionnaire version hashes.
|
||||
- *Assessment Attempt:* Persistent run representing a single pass against an immutable assessment version.
|
||||
2. **Transactional State Journaling:**
|
||||
2. **Transactional State Journaling & Durable Checkpoints:**
|
||||
- Every acknowledged answer submission, draft update, and timing event is committed immediately to SQLite.
|
||||
- Pausing commits state and **terminates the server process cleanly**, eliminating zombie processes.
|
||||
3. **Journal Destruction Invariant:**
|
||||
- Clicking **Pause** creates a durable checkpoint: pending drafts are saved, active time is frozen, and `status = PAUSED` is committed before browser acknowledgment.
|
||||
- **Configurable Pause Grace Period (Default: 2 Hours):** The local server stays running during a 2-hour window (`--pause-grace-period 2h`). Resuming within this window is instant in the browser without CLI/agent interaction.
|
||||
- If the 2-hour window expires without resumption, the server terminates cleanly to prevent zombie processes, retaining the journal with status `PAUSED`.
|
||||
3. **Assessment State Machine:**
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> RUNNING: Attempt started
|
||||
|
||||
RUNNING --> PAUSED: Learner clicks Pause\n(Durable commit in SQLite)
|
||||
PAUSED --> RUNNING: Learner clicks Resume\n(In-browser within 2h grace period)
|
||||
|
||||
RUNNING --> COMPLETED: Final question submitted
|
||||
RUNNING --> CLOSED_EARLY: Learner explicitly closes early
|
||||
RUNNING --> TIMED_OUT: Active duration budget exhausted
|
||||
|
||||
note right of PAUSED
|
||||
Server stays alive for up to 2 hours.
|
||||
If grace period expires, server exits cleanly,
|
||||
retaining journal with status PAUSED.
|
||||
Resume via: live-quiz recover --from-path <db>
|
||||
end note
|
||||
```
|
||||
|
||||
4. **Durability Invariants & Engine Pragmas:**
|
||||
- **Commit-Before-Ack:** The HTTP server commits transactions to SQLite *before* returning a successful `200 OK` acknowledgement to the client for any submission or autosaved draft.
|
||||
- **Engine Configuration:** SQLite runs in Write-Ahead Logging mode (`PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;`). `synchronous=FULL` ensures SQLite performs the required WAL synchronization after each transaction commit, providing durability against process and system failures under the documented filesystem and storage assumptions.
|
||||
- **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 is deleted **only after durable export publication succeeds**.
|
||||
4. **Explicit Recovery Command:**
|
||||
- If a process is killed unexpectedly or paused, the journal remains on disk.
|
||||
- Running `live-quiz recover --from-path <journal.sqlite3>` validates the journal, restores the authoritative clock, reloads drafts, and resumes the server under the exact same `attempt_id`.
|
||||
- *Recovery Idempotency:* If recovery is invoked on a journal whose `attempt.json` was already successfully published, it verifies the export, cleans up the journal, and exits cleanly.
|
||||
- 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:**
|
||||
- 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`.
|
||||
- *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
|
||||
- **Permanent SQLite LMS Database:** Rejected. Burdening `live-quiz` with multi-workspace relational history, cross-project analytics, and long-term migrations creates severe scope creep. `live-quiz` is an assessment execution harness, not a full Learning Management System.
|
||||
- **Flat-File JSON Appending:** Rejected. Subject to partial-write corruption during sudden process kills (`SIGKILL`) or power failures.
|
||||
|
||||
## Consequences
|
||||
- **Positive:** Guarantees zero data loss for acknowledged submissions and drafts under crashes; allows pausing without running background processes; leaves zero state accumulation upon clean completion.
|
||||
- **Negative / Trade-offs:** Requires an explicit recovery command (`live-quiz recover`) and managing temporary journal files in the XDG state directory.
|
||||
- **Positive:** Guarantees reliable recovery of all acknowledged submissions and drafts across process termination (`SIGKILL`, application crash) under documented WAL mode assumptions; prevents active-time budget leakage during crash downtime; allows in-browser pause without indefinite background processes; leaves zero state accumulation upon clean completion.
|
||||
- **Negative / Trade-offs:** Requires an explicit recovery command (`live-quiz recover`) and managing temporary journal files (`.sqlite3`, `-wal`, `-shm`) in the XDG state directory; does not protect against unacknowledged client-side keystrokes that never completed an HTTP transaction.
|
||||
|
||||
## Related Decisions
|
||||
- [ADR-0002: Harness-Agnostic Process Lifecycle](./0002-harness-agnostic-process-lifecycle.md)
|
||||
|
||||
Reference in new issue
Block a user