Files
Ilia Denisov 2ca47eb4df ui/phase-25: backend turn-cutoff guard + auto-pause + UI sync protocol
Backend now owns the turn-cutoff and pause guards the order tab
relies on: the scheduler flips runtime_status between
generation_in_progress and running around every engine tick, a
failed tick auto-pauses the game through OnRuntimeSnapshot, and a
new game.paused notification kind fans out alongside
game.turn.ready. The user-games handlers reject submits with
HTTP 409 turn_already_closed or game_paused depending on the
runtime state.

UI delegates auto-sync to a new OrderQueue: offline detection,
single retry on reconnect, conflict / paused classification.
OrderDraftStore surfaces conflictBanner / pausedBanner runes,
clears them on local mutation or on a game.turn.ready push via
resetForNewTurn. The order tab renders the matching banners and
the new conflict per-row badge; i18n bundles cover en + ru.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 22:00:16 +02:00

65 lines
2.9 KiB
Go

package runtime
import "errors"
// Sentinel errors. Handlers map them to the standard JSON envelope at
// the wire boundary; lobby and admin packages observe them through
// errors.Is when they need to branch on the domain reason.
var (
// ErrNotFound is returned when no row matches the requested
// primary key (engine version, runtime record, player mapping).
ErrNotFound = errors.New("runtime: not found")
// ErrInvalidInput reports request-level validation failures
// (empty fields, malformed semver, unknown enum values).
ErrInvalidInput = errors.New("runtime: invalid input")
// ErrConflict reports that the requested action conflicts with
// the current persisted state (illegal status transition, retry
// while a job is still in-flight, race against the reconciler).
ErrConflict = errors.New("runtime: conflict")
// ErrEngineVersionTaken means a duplicate primary key was
// observed when registering a new engine version row.
ErrEngineVersionTaken = errors.New("runtime: engine version already registered")
// ErrEngineVersionDisabled reports that a referenced engine
// version row exists but is marked disabled.
ErrEngineVersionDisabled = errors.New("runtime: engine version disabled")
// ErrPatchSemverIncompatible reports that an admin-requested
// version patch crosses major or minor boundary, which Galaxy
// disallows for in-place patching (per ARCHITECTURE.md §9).
ErrPatchSemverIncompatible = errors.New("runtime: patch must stay inside the same major/minor line")
// ErrJobQueueFull reports that the worker pool's buffered job
// channel is at capacity. Surfaced as 503 service_unavailable at
// the wire boundary; in practice the pool size and queue depth
// are budgeted in `BACKEND_RUNTIME_*` env vars so the operator
// can absorb peaks.
ErrJobQueueFull = errors.New("runtime: job queue full")
// ErrShutdown means the runtime service has stopped accepting
// work because the parent context was cancelled.
ErrShutdown = errors.New("runtime: shutting down")
// ErrTurnAlreadyClosed reports that the runtime is currently
// producing a turn — runtime status is `generation_in_progress`
// — and the engine is not accepting writes for the closing
// turn. Handlers map this to HTTP 409 with httperr code
// `turn_already_closed`; the UI shows a conflict banner and
// waits for the next `game.turn.ready` push.
ErrTurnAlreadyClosed = errors.New("runtime: turn already closed")
// ErrGamePaused reports that the game is not in a state that
// accepts user-games commands or orders: the runtime row
// carries `paused = true`, or the runtime status lands on any
// terminal value (`engine_unreachable`, `generation_failed`,
// `stopped`, `finished`, `removed`), or the game has not yet
// finished bootstrapping (`starting`). Handlers map this to
// HTTP 409 with httperr code `game_paused`; the UI surfaces a
// pause banner and waits for an admin resume or a fresh
// snapshot.
ErrGamePaused = errors.New("runtime: game paused")
)