fix(order): surface rejection reason, keep sync green, hydrate verdicts
Tests · UI / test (push) Has been cancelled
Tests · Go / test (push) Successful in 2m3s
Tests · Go / test (pull_request) Successful in 2m5s
Tests · Integration / integration (pull_request) Successful in 1m44s
Tests · UI / test (pull_request) Failing after 4m28s

Three issues surfaced once the per-command rejection from the previous
commit actually reached the UI:

1. Sync banner falsely red. `OrderDraftStore.runSync` flipped
   `syncStatus = "error"` whenever any command was rejected and
   advertised a Retry button. A per-command rejection is a
   player-correctable state — the round trip succeeded, the engine
   just refused that command — so the retry can't help. Keep
   `syncStatus = "synced"` on `success`; the red row highlight is
   the visible cue.

2. Rejection reason missing. Add `cmd_error_message: string` to
   `CommandItem` in `pkg/schema/fbs/order.fbs` (appended last to
   preserve existing slot offsets) and regenerate the Go + TS stubs
   for that one type. Plumb the message through `CommandMeta`,
   `Controller.applyCommand`'s `m.Result(code, message)` call, the
   Go transcoder, the UI decoders in `submit.ts` /  `order-load.ts`,
   and the `OrderDraftStore.errorMessages` map. `order-tab.svelte`
   renders it as an italic danger-coloured line under rejected
   commands, with new CSS for `.error-reason`.

3. Verdict lost on navigation. `order-load.ts.decodeCommand` never
   read `cmdApplied`/`cmdErrorCode`, so `hydrateFromServer` fell
   back to a blanket "applied" status — a previously-rejected
   command came back green after a lobby → game round trip. Extend
   the fetch decoder to populate `statuses`/`errorCodes`/
   `errorMessages` maps and have `hydrateFromServer` use them.
   Engine-side persistence already records the verdict on disk —
   verified against the live `0000/order/<id>.json`.

`flatbuffers@25` elides default-int8/int64 fields on write; the Go
transcoder force-slots `cmd_applied=false` / `cmd_error_code=0`
already, the new test fixtures flip `builder.forceDefaults(true)` to
mirror that behaviour so the round trip survives.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-29 11:42:27 +02:00
parent e038ea6154
commit 723885e74e
17 changed files with 404 additions and 40 deletions
+2 -2
View File
@@ -109,11 +109,11 @@ func (c *Controller) applyCommand(actor string, cmd order.DecodableCommand) (err
}
if ge, ok := errors.AsType[*e.GenericError](err); ok {
m.Result(ge.Code)
m.Result(ge.Code, ge.Error())
} else if err != nil {
panic(fmt.Errorf("error applying command has unknown origin: %w", err))
} else {
m.Result(0)
m.Result(0, "")
}
return
+4 -4
View File
@@ -75,14 +75,14 @@ func TestSaveOrder(t *testing.T) {
for i := range o.Commands {
if v, ok := order.AsCommand[*order.CommandRaceVote](o.Commands[i]); ok {
m := &v.CommandMeta
m.Result(0)
m.Result(0, "")
} else if v, ok := order.AsCommand[*order.CommandRaceQuit](o.Commands[i]); ok {
v.Result(10)
v.Result(10, "race quit failed")
} else if v, ok := order.AsCommand[*order.CommandShipClassCreate](o.Commands[i]); ok {
m := &v.CommandMeta
m.Result(33)
m.Result(33, "ship class create failed")
} else if v, ok := order.AsCommand[*order.CommandShipGroupMerge](o.Commands[i]); ok {
v.Result(0)
v.Result(0, "")
}
}
+10
View File
@@ -520,6 +520,16 @@ components:
`0` when the command was applied, a non-zero `GenericError`
code (shelves `2xxx`/`3xxx` in `pkg/error/generic.go`) when
the command was rejected. Omitted on requests.
cmdErrorMessage:
type: string
description: |
Per-command rejection reason, formatted by the engine's
`GenericError.Error()` (e.g.
`Entity does not exists: ship type "Drone"`). Set alongside
`cmdApplied=false`/`cmdErrorCode!=0`, omitted when the
command was applied. Provided so clients can surface the
specific reason without keeping their own code → text
catalog in sync with the engine.
CommandType:
type: string
description: Discriminator identifying the game command variant carried in a `cmd` element.