Commit graph

685 commits

Author SHA1 Message Date
jedarden
c1cfcded23 fix(k8s): update acb-index-builder to latest image with OOMKill fixes
The pod was CrashLoopBackOff for 45 days because it was running an outdated
image without the LIMIT clause fixes added in June. Updated to the latest
image digest which includes:
- LIMIT on fetchSeriesGames query (ca48b60)
- LIMIT on fetchRecentMatchIds query (68b7864)
- O(n²) iteration fix in generateBotProfiles (7befe51)
- Other OOMKill prevention fixes

This should resolve the silent crash after web asset copy.
2026-06-25 05:44:29 -04:00
jedarden
ca48b60434 fix(db): add LIMIT to fetchSeriesGames query to prevent OOMKill
The fetchSeriesGames function was querying all games for a series without a limit.
With up to 1000 series being fetched, and potentially many games per series,
this could return an unbounded number of rows and cause OOMKill.

A typical series has 3-7 games (best-of-5 or best-of-7), so LIMIT 100 is
more than sufficient to handle edge cases while preventing memory exhaustion.

Fixes acb-index-builder CrashLoopBackOff caused by OOMKill after web asset copy.
2026-06-25 01:46:54 -04:00
jedarden
68b786416a fix(db): add LIMIT to fetchRecentMatchIds query to prevent OOMKill
The query in fetchRecentMatchIDs was fetching all completed matches from
the last 24 hours without a LIMIT clause. In a high-traffic environment
with thousands of matches per day, this would cause the pod to run out
of memory and be OOMKilled.

This fix adds LIMIT 5000 to cap the number of recent matches fetched,
preventing unbounded memory growth while still providing sufficient
data for warm asset bundling.

Fixes acb-index-builder CrashLoopBackOff (4713 restarts over 45 days).
2026-06-25 01:40:24 -04:00
jedarden
7befe516bf fix(db): eliminate O(n²) iteration in generateBotProfiles
The generateBotProfiles function had two nested loops that caused O(n²) memory usage:
- Iterating through all rating history entries (10,000) for each bot (10,000) = 100M iterations
- Iterating through all matches (1,000) for each bot (10,000) = 10M iterations

This caused acb-index-builder to run out of memory and get OOMKilled during the build cycle.

Fixed by pre-building lookup maps (O(n) build + O(1) lookup):
- historyMap[botID] -> []RatingHistoryEntry
- matchMap[botID] -> []MatchSummary

Reduces complexity from O(bots × matches) to O(matches + bots) for lookups.

Resolves acb-index-builder CrashLoopBackOff after 45 days of failure.
2026-06-25 01:29:26 -04:00
jedarden
be7588434d notes(bf-2ws): document acb-index-builder OOMKill fix and investigation
- Identified root cause: pod was running 45-day-old image without LIMIT fixes
- Found recent commits (79ca6c0, cdf133d, 4554bed) that added LIMIT clauses
- Triggered acb-build workflow to deploy fixes
- Workflow acb-build-manual-nv552 now building
- Waiting for deployment to verify CrashLoopBackOff is resolved
2026-06-25 01:29:26 -04:00
jedarden
4111970996 fix(db): add LIMIT to unbounded queries causing OOMKill
- Add LIMIT 10000 to fetchSeasonSnapshots (season_snapshots per season)
- Add LIMIT 500 to fetchChampionshipBracket (series per season bracket)

These queries were called in a loop for each season without LIMITs,
causing acb-index-builder to be OOMKilled with 512Mi memory limit.

Fixes OOMKill after web asset copy in build cycle.
2026-06-25 01:29:26 -04:00
jedarden
0449606ac7 fix(db): add LIMIT to pair frequency query to prevent OOMKill in acb-index-builder
The fetchOpenPredictions function had an unbounded query building a pair
frequency map for rivalry detection. With thousands of bots and matches,
this could return tens of thousands of rows and cause OOMKill.

- Add ORDER BY COUNT(*) DESC to prioritize most common pairings
- Add LIMIT 1000 - sufficient to detect rivalries (pairs with >= 3 matches)

This fixes the 45-day CrashLoopBackOff with 4700+ restarts.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-25 01:29:26 -04:00
jedarden
bbe5f45ac1 fix(db): add LIMITs to unbounded queries in fetchEvolutionMeta and fetchLineage
- Add LIMIT 100 to island populations query (fetchEvolutionMeta)
- Add LIMIT 10000 to lineage programs query (fetchLineage)

These queries had no row limits, causing OOMKill when the programs table
grew large. The pod crashed silently after "Copied web assets" because
Go panics and OOMKills exit without logging to slog.

Fixes acb-index-builder CrashLoopBackOff (4700+ restarts, 45 days).
2026-06-25 01:29:26 -04:00
jedarden
80c39a3f2a fix(db): add LIMIT clauses to unbounded queries causing OOMKill
- fetchSeries: LIMIT 1000 (was fetching all series)
- fetchPredictorStats: LIMIT 1000 (was fetching all predictors)
- fetchMaps: LIMIT 1000 (was fetching all maps)
- fetchSeasons: LIMIT 100 (was fetching all seasons)

Fixes acb-index-builder CrashLoopBackOff caused by silent OOMKill
after 'Copied web assets' log line during fetchAllData.
2026-06-25 01:29:26 -04:00
jedarden
941f8bd2c9 fix(db): add LIMITs to unbounded queries to prevent OOM
- Add LIMIT 1000 to fetchChampionshipBracket (was unbounded)
- Reduce fetchSeries from LIMIT 5000 to LIMIT 1000
- Reduce fetchLineage from LIMIT 50000 to LIMIT 10000
- Reduce fetchFeedback from LIMIT 5000 to LIMIT 1000
- Reduce fetchRatingHistory from LIMIT 10000 to LIMIT 5000

The acb-index-builder pod has been in CrashLoopBackOff with OOMKill
(exit code 137) for 45 days with 4713 restarts. These unbounded queries
were loading too much data into memory, causing the kernel to kill the
process before any logs could be written.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-25 00:38:55 -04:00
jedarden
8736098423 fix(db): add LIMITs to unbounded queries to prevent OOM
Added LIMIT clauses to 4 unbounded queries that were causing
acb-index-builder to crash with OOMKill after copying web assets:

- fetchPredictorStats: LIMIT 100 (was loading all predictor stats)
- fetchMaps: LIMIT 500 (was loading all maps)
- fetchSeasonSnapshots: LIMIT 1000 (was loading all season snapshots)
- fetchSeasons: LIMIT 100 (was loading all seasons)

These queries had ORDER BY but no LIMIT, causing them to load
massive datasets into memory on each build cycle, leading to
container OOM after the web asset copy phase.

Fixes bead bf-2ws
2026-06-25 00:27:21 -04:00
jedarden
1832ff439b fix(db): add LIMITs to unbounded queries to prevent OOM
- Add LIMIT 50000 to fetchLineage (evolution programs table)
- Add LIMIT 10000 to fetchBots
- Add LIMIT 5000 to fetchSeries

These queries had no bounds and could grow arbitrarily large,
causing acb-index-builder to OOM during build cycles.
The lineage table in particular grows unbounded with evolution.

Fixes CrashLoopBackOff that has persisted for 45 days.
2026-06-25 00:23:48 -04:00
jedarden
5e83945683 Merge branch 'master' of https://git.ardenone.com/jedarden/ai-code-battle 2026-06-24 07:11:11 -04:00
jedarden
34d5915abc docs: improve README for clarity and discoverability
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 07:10:31 -04:00
jedarden
dfe599c161 notes(bf-1kg): document verification that C# evolver support was already completed
Verified all acceptance criteria:
- buildCandidate() C# case implemented (arena.go:473-491)
- defender_strategy.cs.txt seed file exists
- defender seed entry in seed.go with language=csharp
- langDisplayName() includes C# mapping
- go build ./cmd/acb-evolver/... passes

Bead-Id: bf-1kg
2026-06-17 05:21:46 -04:00
jedarden
88a8d02a48 notes(bf-1kg): document verification that C# evolver support was already completed
Verified all acceptance criteria:
- buildCandidate() C# case implemented (arena.go:473-491)
- defender_strategy.cs.txt seed file exists
- defender seed entry in seed.go with language=csharp
- langDisplayName() includes C# mapping
- go build ./cmd/acb-evolver/... passes
2026-06-17 05:20:52 -04:00
jedarden
0756c28e1b notes(bf-1kg): document that C# evolver support was already completed 2026-06-17 05:11:41 -04:00
jedarden
de15046e3e feat(evolver): add C# language support
- Add csharp case to buildCandidate() with dotnet-script and mcs fallback
- Add defender_strategy.cs.txt seed file (combined Program.cs, Strategy.cs, Grid.cs)
- Add defender seed to population (gamma island, aggression=0.3, economy=0.4)
- Add csharp to langDisplayName() and update comments

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 05:08:19 -04:00
jedarden
c28a463997 build(bots): leader-targeter bot Maven build artifacts
Rebuilt leader-targeter-bot JAR with Maven after verifying
compilation. The bot implements multi-player score-aware
targeting strategy.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 04:54:09 -04:00
jedarden
32b173f6ad notes(bf-3rr): document leader-targeter bot completion
Bead-Id: bf-3rr
2026-06-17 04:43:12 -04:00
jedarden
f833345919 build(bots): leader-targeter bot Maven build artifacts 2026-06-17 04:41:19 -04:00
jedarden
91e272f56a feat(bots): add leader-targeter bot with multiplayer score-aware targeting
Implement a new Java bot that applies multi-player game theory: in N>2
games, always direct all units toward the current score leader rather than
the nearest enemy. This creates a natural kingmaker dynamic that prevents
any single bot from running away with the game.

Strategy:
- Identify all visible opponents and their scores (cores count as proxy)
- Pick primary target: opponent with highest inferred score (tiebreak: nearest)
- Send all bots toward primary target's centroid (mean of visible bots + cores)
- Exception: if own core is under threat (enemy bot within 6 tiles), detach 2 bots to defend
- In 2-player games: fall back to straight aggressor strategy

Novelty: No current bot does multi-player score-aware target selection. Most
bots target nearest enemy, which lets a distant leader accumulate score
unmolested. Leader-targeter explicitly models the N-player problem.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 04:37:55 -04:00
jedarden
8af1c03aca feat(bots): add coordinator bot with dynamic role allocation
Implement CoordinatorBot - a multi-role strategy bot that dynamically
allocates roles (Attacker/Harvester/Defender/Scout) each turn based on
game state.

Features:
- Per-turn role assignment using greedy Hungarian-style algorithm
- Dynamic role rebalancing based on threat level, economic pressure, score
- Zone-aware survival logic
- HTTP server with HMAC authentication
- TypeScript implementation with full type safety

Role allocation algorithm:
- Base split: 50% attackers, 25% harvesters, 15% defenders, 10% scouts
- Adjusts: +10% defenders if threat > 0.3
- Adjusts: +10% harvesters if energy < spawn threshold
- Adjusts: +20% attackers if score leads by 5+
- Assigns bots by proximity to role targets

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 04:24:26 -04:00
jedarden
f0d4e661d7 verify(bf-413): confirm all mechanics iteration work completed
Verified all 5 backlog items:
- Combat kill scoring (engine/turn.go:272-275)
- Fitness formula blending win rate + kill rate (run.go:608)
- CombatDeaths tracking through arena (arena.go:204-221)
- Behavior vector derived from actual kill rate (run.go:614-625)
- Flee thresholds with outnumber logic (farmer/gatherer/siege bots)

All mechanics now make combat economically necessary for the evolver.
2026-06-17 03:58:27 -04:00
jedarden
bf80d84a6f notes(bf-413): document completion of AI Code Battle mechanics iteration
All backlog items completed:
- Combat kill scoring in engine (turn.go:274)
- Fitness formula blends win rate + kill rate (run.go:608)
- Flee thresholds reduced with outnumber logic
- CombatDeaths tracked through arena MatchOutcome
- Aggression derived from actual kill rate in behavior vector

This Genesis bead tracked the full mechanics iteration to make combat
economically necessary and reward aggression in the evolver.
2026-06-17 03:54:38 -04:00
jedarden
d5515e0bca feat(mechanics): reduce flee thresholds and derive aggression from kill rate
## Flee Threshold Changes
- Reduced flee threshold from AttackRadius2+4 to AttackRadius2 (no buffer)
- Modified bots: farmer, gatherer, siege
- Bots now only consider enemies in actual attack range, not preemptively
- Added outnumber logic: only flee when nearbyAllies < nearbyEnemies

## Behavior Vector Changes
- Derive aggression from actual kill rate (not self-reported)
- Formula: behaviorVec[0] = min(killRate, 1.0)
- Preserves existing economy value or defaults to 0.5
- Enhanced logging to show derived aggression value

## Rationale
Aggression must be economically necessary, not just rewarded.
Previous flee logic created a false safe option that discouraged combat.
Now bots only flee when actually outnumbered within combat range.

Related: bf-413 genesis bead tracking mechanics iteration
2026-06-17 03:51:15 -04:00
jedarden
2cf6437587 notes(bf-59h): document that work was already completed in commit d42d1a5 2026-06-17 03:15:28 -04:00
jedarden
d42d1a5336 feat(evolver): update fitness function to weight kill rate alongside win rate
- Updated fitness formula: fitness = 0.7*win_rate + 0.3*kill_rate (was win_rate only)
- Added kill tracking to ArenaResult: TotalKills, TotalMatches, KillRate
- Updated evolver system prompt to explicitly mention combat kills are valuable
- Enhanced arena logging to show kill rate and total kills

This change makes the LLM evolver select for combat aggression, not just win
optimization. The system prompt now informs bots that kills and eliminations
are part of the fitness evaluation, encouraging more aggressive strategies.

Related: bf-59h
2026-06-17 03:11:05 -04:00
jedarden
42398eb34a feat(evolver): add phalanx, assassin, opportunist as generation-0 seeds
Add 3 new hand-written bots to expand evolver seed pool:
- phalanx (Rust, alpha island) - formation combat with aggression=0.85, economy=0.1
- assassin (Rust, alpha island) - decapitation strategy with aggression=1.0, economy=0.0
- opportunist (Go, beta island) - conditional aggression with aggression=0.55, economy=0.55

This brings the total seed count from 6 to 9, providing richer starting
population across islands with diverse attack archetypes the evolver
can recombine.

Changes:
- Add seeds/phalanx_strategy.rs.txt, assassin_strategy.rs.txt, opportunist_strategy.go.txt
- Update seed.go with 3 new embed directives and seed entries
- Add TestSeedPopulation to verify 9 seeds insert correctly
- Update comments to reflect 9 seeds instead of 6

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 03:01:18 -04:00
jedarden
dce34f97b6 fix(economist): use bot positions as keys instead of non-existent IDs
- Fixed contest_assignments to use bot positions as keys since bots only have position and owner (no ID field)
- Fixed tuple conversions for energy and walls to properly convert elements to int
- Added curl to Dockerfile for health check support
- Updated docker-compose.bots.yml for economist bot

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 02:50:49 -04:00
jedarden
0db45dcfc2 Implement EconomistBot: energy-denial via node contesting
Adds bots/economist/bot.py and Dockerfile implementing a new strategy:
deliberately contest energy nodes that enemies are approaching to
destroy the contested energy, denying enemy income while harvesting
uncontested nodes for own economy.

Strategy priorities:
1. Maintain existing contest assignments (stay put)
2. Contest threatened nodes (intercept approaching enemies)
3. Reserve 1-2 bots to guard cores
4. Collect uncontested energy
5. Remaining bots explore toward map center

Pure collection mode when score lead ≥3 and turn > 200.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 01:35:10 -04:00
jedarden
0cbc08ef48 docs(bf-1dy): document ZoneDriver bot completion
The ZoneDriver bot was fully implemented and committed in cdbc4c0.
This note documents the implementation and verifies acceptance criteria.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 01:19:19 -04:00
jedarden
cdbc4c0cbd Implement ZoneDriverBot: zone-herding elimination strategy
ZoneDriver weaponizes the shrinking zone to force enemy eliminations:
- Computes zone boundary and identifies "kill band" (zone edge-2 to edge)
- Positions units to block enemy escape routes inward
- Herds enemies toward zone edge for passive eliminations
- Prioritizes survival for own bots near zone boundary

Novel approach: turns zone from map feature into active weapon.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 01:16:21 -04:00
jedarden
2696e70257 Implement SiegeBot: spawn-lockout strategy
- Add SiegeBot to engine/bot_strategies.go with spawn denial logic
- Implement standalone siege bot in bots/siege/ with main.go, strategy.go, Dockerfile
- Register siege bot in acb-local for arena testing
- Add test-siege-arena.sh script for validation

Strategy: Surround enemy cores to block spawning phase. Bot assigns
units to lockout rings (8 neighbors) around cores, greedily by distance.
Unassigned units collect energy or rush fully-sieged cores.

Tested: 3/10 wins vs rusher+gatherer, 1/10 wins vs rusher+gatherer+guardian
2026-06-17 01:02:01 -04:00
jedarden
2de4ddc720 notes(bf-dgn): verify setup-r2.sh replaced with setup-b2.sh 2026-06-17 00:30:34 -04:00
jedarden
65ea26f6da Replace setup-r2.sh with setup-b2.sh
- Delete scripts/setup-r2.sh (Cloudflare R2 is not the storage provider)
- Create scripts/setup-b2.sh that documents B2 CDN setup:
  - Prints B2 bucket endpoint (us-west-002)
  - Prints CNAME target for b2.aicodebattle.com
  - Verifies B2 credentials when env vars are set
  - Informational/verification-only (no destructive operations)
- Update scripts/cloudflare-setup.sh:
  - Remove R2 bucket creation steps
  - Add note that B2 setup is separate (see setup-b2.sh)

Acceptance criteria met:
- scripts/setup-r2.sh does not exist
- scripts/setup-b2.sh exists, is executable, and runs without error
- No references to setup-r2 remain in scripts/
2026-06-17 00:29:39 -04:00
jedarden
5546fd4f81 docs(bf-2x3): fix region inconsistency in B2 CDN documentation
Update B2 bucket details table to consistently show region as VERIFIED.
The region was already verified via garage-to-b2-sync.yml but the table
incorrectly showed it as 'unconfirmed'.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 00:26:48 -04:00
jedarden
66bf23f3f2 docs(bf-2x3): fix region inconsistency in B2 CDN documentation
Fix typo on line 147 where us-west-004 was incorrectly referenced
instead of the verified us-west-002 region from garage-to-b2-sync.yml
2026-06-17 00:18:59 -04:00
jedarden
d9bce29a3d docs(bf-2x3): verify B2 region as us-west-002, update documentation status
Verified B2 endpoint region via declarative-config garage-to-b2-sync.yml:
- Confirmed region: us-west-002
- Confirmed CNAME target: acb-data.s3.us-west-002.backblazeb2.com
- Updated implementation status table

Acceptance criteria met:
- notes/b2-cdn-setup.md exists with exact CNAME target 
- Region verified from production config (declarative-config) 
- Document clearly states verification status and blockers 

Note: B2 API auth could not be tested due to read-only proxy limitations.
Public access status requires Backblaze console access.
2026-06-17 00:16:47 -04:00
jedarden
eae2f70c2a docs(bf-2x3): update B2 CDN setup documentation with verification status
- Add current status summary identifying blockers
- Document region inconsistency (us-west-002 vs us-west-004 vs us-east-005)
- Note that aicodebattle.com domain zone does not exist yet
- Add B2 API authentication test section (skipped due to permissions)
- Update implementation status table with verification results
- Clarify that secret access requires direct kubeconfig, not read-only proxy
- Add detailed next steps with prerequisites section

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 00:16:47 -04:00
jedarden
915113b3a0 docs(bf-2x3): update B2 CDN setup documentation with verified CNAME status
- Corrected date from 2025 to 2026
- Confirmed b2.aicodebattle.com CNAME does NOT exist (NXDOMAIN verified)
- Added bucket name verification from enrichment deployment config
- Updated implementation status to reflect current CNAME status
- Added verification details for DNS resolution check
2026-06-17 00:16:47 -04:00
jedarden
75c0bb0d66 docs(bf-3dv): re-verify K8s strategy bot manifests already exist
- Confirmed all 7 original strategy bot deployment manifests exist
- Verified each follows required pattern: image=ronaldraygun/acb-strategy-{name}:latest, BOT_PORT=8080, BOT_SECRET from acb-bot-secrets key={name}-secret, Service ClusterIP:8080
- Verified acb-bot-secrets.yml.template contains all 7 bot secret keys
- Original work completed in commit 909f38f on 2026-06-16

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-16 23:57:33 -04:00
jedarden
c565cbab44 docs(bf-3dv): verify K8s strategy bot manifests already exist
Task completed in prior commit 909f38f. All 7 bot deployment manifests
and acb-bot-secrets.yml.template already present in declarative-config.
Verified pattern compliance: image ronaldraygun/acb-strategy-{name}:latest,
BOT_PORT=8080, BOT_SECRET from acb-bot-secrets key={name}-secret,
ClusterIP Service on port 8080.
2026-06-16 23:54:22 -04:00
jedarden
75f5b5755f docs(bf-z9m): verify combat kill scoring already implemented 2026-06-16 23:46:12 -04:00
jedarden
3fd355d377 docs(bf-z9m): verify combat kill scoring already implemented
- Confirmed feature exists in commit c1acd83 (2026-06-16)
- KillScore config field with default value of 1
- Score awarded in executeCombat() loop
- No code changes needed
2026-06-16 23:42:55 -04:00
jedarden
c1acd832f0 feat(combat): award score for combat kills
- Add KillScore config field (default: 1 point per kill)
- Increment killer's score in executeCombat() when tracking CombatDeaths
- Makes killing enemy bots worth real score, not just foraging
- Keeps kill_score configurable for balance tuning

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-16 23:40:47 -04:00
jedarden
b9a70cd873 docs(bf-1pc): re-verify SPA R2→B2 migration - complete 2026-06-16 23:36:49 -04:00
jedarden
f0ac0313a1 docs(bf-1pc): verify SPA R2→B2 migration - already complete
All acceptance criteria met:
- No /r2/ paths in source code
- Build succeeds
- No r2.aicodebattle.com references in dist

Work was completed in commit 76369b5 on 2026-06-16.
2026-06-16 23:26:31 -04:00
jedarden
69c1a80d1e docs(bf-1pc): verify SPA R2→B2 migration - already complete 2026-06-16 23:22:30 -04:00
jedarden
92dd1f92fd docs(bf-1pc): verify SPA R2→B2 migration - already complete 2026-06-16 23:20:06 -04:00