docs(adr): decouple process termination from assessment completion in ADR-0002 and ADR-0006
- ADR-0002: Establish that process exit does not equal assessment completion. Define structured lifecycle outcome on stdout (FINALIZED, SUSPENDED, ERROR). Add sequence diagram showing in-browser pause/resume vs 2-hour grace period exit. - ADR-0006: Define Pause as a durable transaction committed to SQLite before ACK. Establish a 2-hour configurable pause grace period allowing seamless in-browser resumption without CLI or agent intervention. Add state diagram for assessment states (RUNNING, PAUSED, COMPLETED, CLOSED_EARLY, TIMED_OUT).
This commit is contained in:
1 parent
521cd30348
commit
8e0adb3248
3 files changed
+76
-13
No files matched your search
@@ -124,8 +124,10 @@ The system explicitly separates:
|
|||||||
### 5.2 Ephemeral SQLite Session Journal
|
### 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`):
|
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.
|
- 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.
|
- **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.
|
||||||
- Unexpected kills (`SIGKILL`, power failure) leave the journal intact.
|
- **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
|
### 5.3 Atomic Publication & Journal Deletion
|
||||||
Upon reaching a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`):
|
Upon reaching a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`):
|
||||||
|
|||||||
@@ -4,15 +4,53 @@
|
|||||||
- Date: 2026-11-10
|
- Date: 2026-11-10
|
||||||
|
|
||||||
## Context
|
## 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
|
## 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
|
## 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.
|
- **Treating Every Process Exit as Assessment Completion:** Rejected. Conflating process termination with assessment finalization leads to evaluating incomplete paused attempts.
|
||||||
- **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.
|
- **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.
|
||||||
- **Polling Loop:** Rejected. Wastes tokens and agent execution turns polling local status endpoints.
|
- **Antigravity Sidecars and `agentapi`:** Rejected. Coupled to internal language server environment variables.
|
||||||
|
|
||||||
|
|
||||||
## Consequences
|
## Consequences
|
||||||
- **Positive:** Complete decoupling from harness internals; standard OS process semantics (`exit 0`); portable across Antigravity, Claude Code, terminal shells, and CI pipelines.
|
- **Positive:** Complete decoupling from harness internals; standard OS process semantics (`exit 0`); portable across Antigravity, Claude Code, terminal shells, and CI pipelines.
|
||||||
|
|||||||
@@ -9,17 +9,40 @@ During an assessment, the application must withstand interruptions (unexpected p
|
|||||||
## Decision
|
## 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:
|
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:**
|
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 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.
|
- *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.
|
- 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.
|
- Clicking **Pause** creates a durable checkpoint: pending drafts are saved, active time is frozen, and `status = PAUSED` is committed before browser acknowledgment.
|
||||||
3. **Journal Destruction Invariant:**
|
- **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. **Journal Destruction Invariant:**
|
||||||
- Upon reaching a terminal state (`COMPLETED`, `CLOSED_EARLY`, `TIMED_OUT`), the server publishes `attempt.json`.
|
- 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**.
|
- The temporary SQLite journal is deleted **only after durable export publication succeeds**.
|
||||||
4. **Explicit Recovery Command:**
|
5. **Explicit Recovery Command:**
|
||||||
- If a process is killed unexpectedly or paused, the journal remains on disk.
|
- If a process is killed unexpectedly (`SIGKILL`) or grace period expires while 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`.
|
- 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.
|
- *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.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user