Files
juli 363fa1eb07 Write narration outside the room lock
The relay held a room's lock while it waited up to 30 seconds for optional
narration. The new round was already saved, so a crewmate could see it and
act, but their action failed with "This room is resolving an action" once
the app's retries ran out. Narration is now written after the lock is
released and added only if the game is still in that round, so a late line
never lands among the next round's events.
2026-10-25 21:30:19 +01:00

6.3 KiB
Raw Permalink Blame History

Architecture and implementation boundaries

One source of truth

The server owns rolls, preparation, objective flags, pending actions, pressure and endings. Android submits an intent and a description; it cannot supply a roll or write world state. The model receives a recent resolved transcript and objective flags, and can only return an atmospheric paragraph.

flowchart LR
    A[Android operator A] <-->|HTTP + polling| S[Kotlin relay server]
    B[Android operator B] <-->|HTTP + polling| S
    S --> C[Campaign rules]
    C --> D[Atomic room snapshots]
    S --> N[Optional local LLM narrator]

The first server uses the JDK HTTP server to keep the runtime small. It has a bounded pool of eight request threads. A room lock serializes joining, starting and acting; polling reads atomic snapshots without waiting on optional narration. Narration is written outside the lock, after the round is saved, so crewmates can act in the new round meanwhile; it is added only if the game is still in that round. Separate rooms can progress concurrently. Room files are private server state; API snapshots exclude bearer tokens and unrevealed pending text. Atomic file replacement prevents partial snapshots. This is not a multi-process or distributed store.

HTTP contract (API version 2)

All requests/responses use JSON. Room requests must send X-DePraxis-Api: 2; older apps without it receive 426 with an "update the app" message. Private endpoints use Authorization: Bearer <operator token>. A room code alone permits seeing its lobby and joining it, not reading its contents. Responses use Cache-Control: no-store.

Method Path Body Response
GET /health — { "status": "ok", "api": 2, "name": "<relay name>" }
GET /campaigns — campaigns offered: id, version, title, tagline, players, minutes, warnings, roles, clock
POST /rooms { "name": "Juli", "role": "engineer", "campaign": "dead-channel" } token, playerId, snapshot
GET /rooms/{code}/lobby — the room's campaign, crew count and whether it can be joined
POST /rooms/{code}/join { "name": "Jegor", "role": "analyst" } token, playerId, snapshot
GET /rooms/{code} — snapshot
POST /rooms/{code}/start {} snapshot; host only
POST /rooms/{code}/actions request below snapshot
{
  "requestId": "unique-per-operator-action",
  "round": 1,
  "action": "restore",
  "text": "I bridge the corroded emergency contacts with my probe.",
  "target": null
}

action is an id from the snapshot's actions; target is the destination for the built-in move action in campaigns with locations.

Snapshots are personal. Each operator receives their own log (private lines filtered out), objectives (hidden role goals only for that role until the end), action menu, exits, items and stats. Each action carries enabled, the reason it is unavailable, and a check preview (sides, dc, bonus, success chance) computed by the relay, so the app holds no rules. Roll log entries carry a structured roll with the authoritative die, bonus, total, DC and result.

Rooms run on the campaign engine (server/.../campaign/). Each room pins the exact campaign document it started with by SHA-256, stored under DATA_DIR/campaigns/pinned/, so campaign updates never change a game in progress. Rooms written by relay versions before API 2 are reported as unknown, with a message to start a new one.

Action IDs are persisted and scoped to the operator. Retrying an accepted ID returns the current snapshot without repeating the action, including after server restart. Stale rounds and a second distinct action in the same round return 409. The Android client uses player ID + round as its action ID. All operators' pending actions resolve together in campaign-defined order (first, crew order, last). New operators cannot join an active campaign.

Errors use { "error": "message" } with 400 (invalid input), 401 (invalid token), 403 (host-only operation), 404 (unknown resource), 409 (invalid state), 413 (oversized body), or 426 (app too old). Names allow 1–24 printable characters; action descriptions allow 1–500 characters; request bodies are limited to 8 KiB.

Narrative contract

The authored scenario guarantees that required information is available: the introduction names the two escape objectives and optional containment, and successful Decode reveals the isolation procedure. There are no random mandatory clues. Failed checks cost time and reveal a persistent shared +2 approach bonus for that task, capped at +4; they cannot erase an objective or introduce an impossible dependency. The countdown guarantees an ending after at most twelve fully submitted rounds; it does not advance in real time while a player is disconnected.

Scenes, investigation clues, failure recovery and the Android reading flow are described in experience.md.

The optional LLM is a presentation layer in v0.1. Its prose is not mechanically parsed. A model could still describe an inconsistent detail, so the structured objective panel, roll events and authored outcomes remain authoritative. A future DM implementation should return typed proposals for validation rather than mutating state directly.

Next vertical slices

  1. Flexible adjudication: translate a player's free-text action into a typed proposed intent, target and check. Validate against scene affordances, and ask the player to clarify ambiguous or consequential interpretations. Add a recorded DM exception event with a reason and bounded effect.
  2. Campaign content: done: campaigns are validated data files; see campaign-system.md for packages, the Studio and sharing.
  3. Tactical encounters: enemy profiles, player resources, damage, powers and combat turn order. Keep rolls and combat resolution deterministic under injected randomness for testing.
  4. Co-op resilience: recoverable invite/account identities, AFK policy, host tools, and push updates. Retain action IDs and authoritative sequencing.
  5. Lore and skins: separate scenario structure from setting vocabulary, then support curated lore retrieval and consistent affordances per setting.

Keep scope focused until two people can finish the same short campaign reliably and want to replay it.