Implement runBattle() orchestrator #130

Closed
opened 2026-08-30 10:22:06 +02:00 by SirStone · 3 comments
Owner

Wayfinder child of: #126

Wire together server manager + bot compiler/launcher + result parser into the single runBattle() API call. Handle the full lifecycle: ensure server is up, compile bots, generate bot JSON configs (with InitialPosition if specified), start battle, wait for completion, parse results, return BattleResult.

Blocked by: #127, #128, #129

Grilling Revisions

Server connection: BattleRunner connects to external server via serverUrl("ws://localhost:PORT"). BotEntry.of(directory) works in external mode — Booter launches bots locally.

API parameters:

  • bots: seq[string] — paths to .nim source files
  • rounds: int — number of rounds (default 1)
  • initialPositions: Table[string, InitialPosition] — optional per-bot positions (keyed by source path)
  • timeout: Duration — default timeout, kills battle on expiry
  • outputFlags: seq[string] — raw passthrough to Java runner (@["--positions", "--scanned"] etc.)

Process model: startProcess for server (long-lived singleton), execCmdEx for runner (blocking, captures stdout+exitcode). Stdout parsed into BattleResult, stderr passes through to terminal.

**Wayfinder child of:** #126 Wire together server manager + bot compiler/launcher + result parser into the single `runBattle()` API call. Handle the full lifecycle: ensure server is up, compile bots, generate bot JSON configs (with InitialPosition if specified), start battle, wait for completion, parse results, return BattleResult. **Blocked by:** #127, #128, #129 ### Grilling Revisions **Server connection**: `BattleRunner` connects to external server via `serverUrl("ws://localhost:PORT")`. `BotEntry.of(directory)` works in external mode — Booter launches bots locally. **API parameters:** - `bots: seq[string]` — paths to .nim source files - `rounds: int` — number of rounds (default 1) - `initialPositions: Table[string, InitialPosition]` — optional per-bot positions (keyed by source path) - `timeout: Duration` — default timeout, kills battle on expiry - `outputFlags: seq[string]` — raw passthrough to Java runner (`@["--positions", "--scanned"]` etc.) **Process model**: `startProcess` for server (long-lived singleton), `execCmdEx` for runner (blocking, captures stdout+exitcode). Stdout parsed into BattleResult, stderr passes through to terminal.
SirStone added the wayfinder:task label 2026-08-30 10:22:06 +02:00
Author
Owner

Spec additions from grilling

  • runBattle() must use defer blocks to clean up bot processes and BattleRunner process on any exception.
  • Overall timeout: 120s hard ceiling per runBattle() call.
  • Battle execution timeout: 60s per round.
  • Timeouts should be optional params with sensible defaults.
## Spec additions from grilling - `runBattle()` must use `defer` blocks to clean up bot processes and BattleRunner process on any exception. - Overall timeout: **120s** hard ceiling per `runBattle()` call. - Battle execution timeout: **60s** per round. - Timeouts should be optional params with sensible defaults.
Author
Owner

Dependency addition

Blocked by: #127, #128, #129, #134 (adding #134 — BattleRunner process lifecycle must be implemented before the orchestrator can wire it in).

## Dependency addition Blocked by: #127, #128, #129, #134 (adding #134 — BattleRunner process lifecycle must be implemented before the orchestrator can wire it in).
Author
Owner

Implemented in commit 57a1915.

Implemented in commit 57a1915.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#130