Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Start with [Contributing](CONTRIBUTING.md). Use [Maintainer context](docs/maintainer-context.md) to trace a contract, failure path, or guard and [Comment hygiene](docs/comment-hygiene.md) for comment changes.

- Verify [HTTP authorization](internal/server/handler.go) through the registered mux under a non-root prefix. Viewer, admin, and producer routes use different credentials. Use the [streaming contract](docs/streaming-architecture.md) for ingestion, recording formats, and playback. Follow the [schema generation instructions](CONTRIBUTING.md#protobuf-schema-changes) for protobuf changes.
- Native v2 recordings get a v1 JSON copy and fall back to it when v2 writing fails; `streaming.protobufOnly` and `streaming.disableV1Fallback` opt out. A download of a v2 recording without the copy converts it on demand. Keep existing v1 JSON and schema-v1 protobuf recordings readable.
- Keep the UI's SolidJS, CSS module, and i18n conventions. Use the [operational runbook](docs/operational-verification.md) for startup, native map tooling, and Arsenal imports.
- Inspect the working tree before editing. Preserve local changes and use synthetic recordings, paths, identities, secrets, and provider responses for local checks. The [testkit](docs/testkit.md) is available without an application startup.
- Match [CI](.github/workflows) for Go tests and UI typecheck, lint, tests, and build when those surfaces change. Build the SPA before packaging the embedded binary. Keep tests close to the code they exercise.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Each archive contains the binary and required assets (markers, ammo icons).

### Build from source

Requires [Go 1.26+](https://golang.org/dl/) and [Node.js 24+](https://nodejs.org/).
Requires [Go 1.27.4+](https://golang.org/dl/) and [Node.js 24+](https://nodejs.org/).

```bash
# Build the frontend
Expand Down Expand Up @@ -227,6 +227,8 @@ Live mission data can be streamed to the server via WebSocket.
| `streaming.resumeGrace` | `OCAP_STREAMING_RESUMEGRACE` | How long a disconnected mission waits for its producer to resume before it is saved as partial | `5m` |
| `streaming.ackInterval` | `OCAP_STREAMING_ACKINTERVAL` | How often received messages are acknowledged to a resuming producer | `1s` |
| `streaming.maxSessions` | `OCAP_STREAMING_MAXSESSIONS` | Missions ingested at once (each is held in memory until saved); a producer turned away retries. `0` = no limit | `0` |
| `streaming.protobufOnly` | `OCAP_STREAMING_PROTOBUFONLY` | Store streamed recordings only as protobuf, without the v1 `.json.gz` copy and the debug `manifest.json`. Their v1 JSON download is generated on request | `false` |
| `streaming.disableV1Fallback` | `OCAP_STREAMING_DISABLEV1FALLBACK` | When a streamed recording cannot be written as protobuf, fail the save instead of keeping the mission as v1 JSON. The producer gets no acknowledgement, the recording is marked failed, and a resumable extension sends the mission again | `false` |

### CORS

Expand Down
26 changes: 19 additions & 7 deletions docs/streaming-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ legacy marker end sentinel and projectile trajectory field name. Unknown future
message types are logged and skipped.

Each accepted mission gets one unique storage key, used for its database row,
v2 directory and legacy `.json.gz` backup. At mission end the web writes:
v2 directory and v1 `.json.gz` copy. At mission end the web writes:

- Native **v2 protobuf** metadata and chunks, retaining the richer entity states,
telemetry, mission metadata, radio/ACE events, placed objects and focus ranges.
Expand All @@ -54,15 +54,25 @@ v2 directory and legacy `.json.gz` backup. At mission end the web writes:
- Player snapshot sidecars using the existing `snapshots/<unitId>.pb` format and
endpoint, keeping large inventories out of the startup manifest. Older v2 files
with inline snapshots remain readable.
- A **v1 JSON.gz backup** for legacy playback, downloads and fallback conversion.
- A **v1 JSON.gz copy** for legacy playback, downloads and fallback conversion,
and a readable `manifest.json` next to `manifest.pb` for debugging.
Existing uploads, v1 conversion, schema-v1 protobuf and JSON playback retain
their existing paths. Legacy conversion never overwrites a native v2 recording.

With `streaming.protobufOnly`, the web writes neither the v1 copy nor
`manifest.json`. The viewer download URL serves a stored v1 JSON.gz when there
is one; for a native v2 recording without it, the server converts the protobuf
recording to v1 JSON on request. Each conversion holds the whole mission in
memory, so the server runs one at a time and queues the rest.

An end-mission acknowledgement is sent only after the recording and operation
are saved. Direct v2 output is already finalized and needs no conversion job.
If v2 writing fails, a successful legacy backup becomes the operation's source
and follows the existing conversion setting. A failed save is reported by closing
the connection without a success acknowledgement, and the row is marked failed.
If v2 writing fails, the v1 JSON becomes the operation's source and follows the
existing conversion setting; with `protobufOnly` it is written at that point.
With `streaming.disableV1Fallback`, the save fails instead and no v1 JSON is
kept. A failed save is reported by closing the connection without a success
acknowledgement, and the row is marked failed. A resumable producer can replay
the mission.

### Resume after a network failure

Expand Down Expand Up @@ -112,6 +122,8 @@ the next section.
| `streaming.resumeGrace` | `5m` | How long a disconnected mission waits for its producer |
| `streaming.ackInterval` | `1s` | How often received envelopes are acknowledged |
| `streaming.maxSessions` | `0` | Missions ingested at once; `0` = no limit |
| `streaming.protobufOnly` | `false` | Store native v2 recordings without the v1 copy and `manifest.json` |
| `streaming.disableV1Fallback` | `false` | Fail a save whose v2 recording cannot be written instead of keeping it as v1 JSON |

Each session holds its mission in memory until it is saved, so many game
servers resending missions in full after a web restart can add up.
Expand Down Expand Up @@ -211,9 +223,9 @@ received data and appends `partial` to the mission's existing tags. Repeated
starts cannot silently discard an active mission. Their reconnect starts a new
recording segment.

The session retains history in web memory for its legacy backup. A web process
The session retains history in web memory until it is saved. A web process
crash is not the same as a producer disconnect and does not guarantee a finalized
backup; this protocol does not yet include a durable ingestion journal.
recording. This protocol does not yet include a durable ingestion journal.

### Verification

Expand Down
8 changes: 5 additions & 3 deletions docs/testkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ go run ./cmd/ocap-testkit run -race stream-recovery

Put `-race` immediately after `run`. It instruments Go steps in the selected cases and records the exact command in the report. UI steps run normally. Use a [supported compiler and platform](https://go.dev/doc/articles/race_detector#Requirements). Coverage and race detection measure different things. The detector reports races on paths exercised by the selected tests. [Go race detector](https://go.dev/doc/articles/race_detector#How_To_Use)

For a diagnostic goroutine-leak profile after three synthetic reconnect-and-discard cycles, run the focused integration test with `OCAP_STREAM_LEAK_PROFILE=1 go test ./internal/server -run '^TestStreamRecoveryLeakProfile$' -count=1`. The profile is written to stderr for inspection and does not impose a process-wide leak threshold. Go's reachability-based profile may miss blockers reachable from globals or runnable goroutines.

## Cases

| Case | Evidence |
| --- | --- |
| `filename-migration` | Repair and rerun, collisions, and no disk or database changes after an incomplete row scan |
| `filename-migration` | Legacy filename repair, collisions, interrupted scans, and additive SQLite indexes |
| `legacy-upload` | Repeated filename replacement, failed reload leaves the prior recording available, and legacy raw JSON playback |
| `route-access` | Prefixed viewer route and admin mutation authorization through the mux, plus producer credential rejection |
| `route-access` | Prefixed viewer access to stored JSON and v2-generated downloads, protected admin mutations, and producer credential rejection |
| `steam-boundary` | Fake OpenID verifier and loopback profile API, denied allowlist access and provider errors |
| `stream-recovery` | Loopback reconnect, repeated starts, partial replacement, durable end, repeated discard, and fake-clock tests for reservation timeouts and a failed keepalive write |
| `conversion-recovery` | Temporary conversion artifacts, status failures and admin retry |
| `playback-delivery` | Synthetic artifact serving and decoding, lazy sidecar replay and Gear exports, event-time factions, and bounded chunk traversal |
| `playback-delivery` | Synthetic artifact serving and decoding, v2 to v1 export, lazy sidecar replay and Gear exports, event-time factions, and bounded chunk traversal |
| `map-boundary` | Synthetic ZIP and job lifecycle, authenticated SSE, stubbed CDN fallback |
| `startup` | Fake dependencies for startup, failure and shutdown wiring |

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/OCAP2/web

go 1.27.2
go 1.27.4

require (
github.com/OCAP2/extension/v5 v5.0.2-0.20261027093953-0a7ce6a9b9a7
Expand Down
60 changes: 16 additions & 44 deletions internal/conversion/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"testing"
"testing/synctest"
"time"

"github.com/OCAP2/web/internal/server"
Expand Down Expand Up @@ -323,26 +324,12 @@ func TestTriggerConversion(t *testing.T) {
ChunkSize: 10,
})

// TriggerConversion is async, so we need to wait for it
worker.TriggerConversion(1, "trigger_mission")

// Wait for async conversion to complete
timeout := time.After(5 * time.Second)
ticker := time.NewTicker(50 * time.Millisecond)
defer ticker.Stop()

for {
select {
case <-timeout:
t.Fatal("Timeout waiting for async conversion")
case <-ticker.C:
if status, ok := repo.status[1]; ok && status == "completed" {
// Conversion completed
assert.Equal(t, "protobuf", repo.format[1])
return
}
}
}
synctest.Test(t, func(t *testing.T) {
worker.TriggerConversion(1, "trigger_mission")
synctest.Wait()
assert.Equal(t, server.ConversionStatusCompleted, repo.status[1])
assert.Equal(t, "protobuf", repo.format[1])
})
}

func TestTriggerConversion_Failure(t *testing.T) {
Expand All @@ -353,25 +340,11 @@ func TestTriggerConversion_Failure(t *testing.T) {
DataDir: dir,
})

// Trigger conversion for non-existent file
worker.TriggerConversion(99, "nonexistent_file")

// Wait for async conversion to fail
timeout := time.After(2 * time.Second)
ticker := time.NewTicker(50 * time.Millisecond)
defer ticker.Stop()

for {
select {
case <-timeout:
t.Fatal("Timeout waiting for async conversion failure")
case <-ticker.C:
if status, ok := repo.status[99]; ok && status == "failed" {
// Conversion failed as expected
return
}
}
}
synctest.Test(t, func(t *testing.T) {
worker.TriggerConversion(99, "nonexistent_file")
synctest.Wait()
assert.Equal(t, server.ConversionStatusFailed, repo.status[99])
})
}

func TestWorker_ContextCancellation(t *testing.T) {
Expand Down Expand Up @@ -722,11 +695,10 @@ func TestTriggerConversion_FailedStatusUpdateError(t *testing.T) {
DataDir: dir,
})

// TriggerConversion is async, just verify it doesn't panic
worker.TriggerConversion(1, "nonexistent")

// Give the goroutine time to run
time.Sleep(100 * time.Millisecond)
synctest.Test(t, func(t *testing.T) {
worker.TriggerConversion(1, "nonexistent")
synctest.Wait()
})
}

func TestComputeStats_DeduplicatesPlayersByName(t *testing.T) {
Expand Down
Loading
Loading