fix(allocator): publish signed assignment rosters before servers start

The root blocker (issue #14). The worker bound the provider allocation
and stopped. Service.PublishRoster and store.SaveVerifiedAssignmentRoster
both existed, fully tested, with zero non-test callers, and the
production allocator configured neither a roster store nor a signing
key. Nothing ever wrote the assignments table.

The allocated supervisor fetches a non-empty roster before it launches
the game child, so every real allocation failed at that fetch: no match
could reach ASSIGNMENT_READY or accept a player. Existing tests seeded
assignments directly, which is exactly why the missing hand-off went
unnoticed.

The worker now builds one join authorisation per durable participant,
signs each with the active key, and publishes them. Participants are
read through the same query SaveVerifiedAssignmentRoster re-validates
against, so the allocator cannot construct a roster the persistence
boundary would reject. The manifest commits to a digest over the whole
roster, so a server cannot be handed a truncated roster whose surviving
entries are each individually valid.

Persist the provider endpoint on the allocation: it arrived on the
provider response and was never stored, so a worker crashing between
allocating and publishing had no endpoint to recover and would have
stranded the match permanently. Republishing is idempotent, so that
crash now simply retries.

cmd/allocator refuses to start without key material rather than running
an allocator that binds allocations and silently strands every match.
The k8s allocator Deployment mounts the same key set the Fleet does, and
both now take the JSON key map so a rotation can publish several.

New integration test drives the real worker through to the supervisor's
own roster read path without seeding the assignments table. Verified it
fails with "assignments = 0, want 2" when the publish step is removed.
This commit is contained in:
Josh Creek
2026-09-05 10:42:31 +01:00
parent b8bcc1f3c1
commit 5765532409
19 changed files with 786 additions and 17 deletions
+44
View File
@@ -329,3 +329,47 @@ func GetAssignmentRoster(ctx context.Context, db *sql.DB, matchID, serverID stri
}
return roster, nil
}
// LoadAssignmentParticipants reads the authoritative roster for an allocated
// match. It reuses AssignmentExpectedRosterSQL -- the same query
// SaveVerifiedAssignmentRoster re-validates against -- so the allocator cannot
// build a roster the persistence boundary would then reject for disagreeing
// with the durable participants.
func LoadAssignmentParticipants(ctx context.Context, db *sql.DB, allocation domain.Allocation) ([]domain.AssignmentParticipant, error) {
if db == nil || allocation.MatchID == "" || allocation.AllocationID == "" || allocation.ServerID == "" {
return nil, fmt.Errorf("invalid assignment participant arguments")
}
rows, err := db.QueryContext(ctx, AssignmentExpectedRosterSQL,
allocation.MatchID, allocation.AllocationID, allocation.ServerID,
allocation.Region, allocation.Protocol, allocation.Build, allocation.Transport)
if err != nil {
return nil, err
}
defer rows.Close()
var participants []domain.AssignmentParticipant
for rows.Next() {
var participant domain.AssignmentParticipant
if err := rows.Scan(&participant.PlayerID, &participant.SteamID, &participant.Slot, &participant.Team); err != nil {
return nil, err
}
if participant.PlayerID == "" || participant.SteamID == "" || participant.Slot < 0 || participant.Slot > 5 || participant.Team < 0 || participant.Team > 1 || participant.Slot/3 != participant.Team {
return nil, fmt.Errorf("assignment participant %q has an invalid slot/team", participant.PlayerID)
}
participants = append(participants, participant)
}
if err := rows.Err(); err != nil {
return nil, err
}
if len(participants) == 0 {
return nil, fmt.Errorf("allocated match %s has no durable participants", allocation.MatchID)
}
return participants, nil
}
// AssignmentRosters adapts the participant loader to the allocator's
// AssignmentRosterSource interface.
type AssignmentRosters struct{ DB *sql.DB }
func (a AssignmentRosters) LoadAssignmentParticipants(ctx context.Context, allocation domain.Allocation) ([]domain.AssignmentParticipant, error) {
return LoadAssignmentParticipants(ctx, a.DB, allocation)
}