Skip to content

(WIP) Fix silent agent attrition when spawn positions can't fit goals - #531

Open
eugenevinitsky wants to merge 1 commit into
3.0from
ev/spawn-goal-retry
Open

(WIP) Fix silent agent attrition when spawn positions can't fit goals#531
eugenevinitsky wants to merge 1 commit into
3.0from
ev/spawn-goal-retry

Conversation

@eugenevinitsky

@eugenevinitsky eugenevinitsky commented Jul 21, 2026

Copy link
Copy Markdown

What

Fixes gigaflow spawn silently dropping agents whose sampled position can't fit a route + goals, and adds tests that fail on any agent attrition.

  • spawn_agent: the state commit, route computation, and goal generation now live inside the position rejection loop — a position on short/dead-end lanes is rejected and resampled exactly like a colliding or offroad one. This extends the same retry principle the map goal source already uses (generate_new_goals_from_map's fresh-cell retry, covered by test_map_goal_source_no_attrition).
  • generate_new_goals_from_route: returns failure without invalidating/removing the agent; each caller now handles failure explicitly (resample at spawn, remove with a warning at replay init/reset, remove at mid-episode regen as before).
  • Init no longer re-rolls goals for gigaflow agents (they already got goals in spawn_agent); the re-roll could fail and strand a removed=1 agent inside the active set.
  • test_drive_goals: new test_route_goal_source_no_attrition — on the nuPlan map, all 32 requested agents must spawn live with full goal sets, both at env creation and through the episode-boundary respawn path. Also updates the test_route_goals_full_set_or_removed contract comment to the new caller-owns-removal semantics.
  • test_drive_env_smoke: asserts gigaflow spawns every requested agent and that no active agent is ever removed (checked after creation and at every step, which covers the mid-run episode reset).

Why

On the nuPlan test map, 8 of 32 requested agents were silently dropped at env creation (25% batch shrinkage), one agent sat in the active set already removed with re-rolled goals, and after the first episode reset 8 of 24 active agents (33%) spent the whole episode as dead, terminal-masked observation slots. The only traces were [GIGAFLOW ERROR] printfs — no test failed and no metric moved. The failures are position-specific (nuPlan bins are cropped scenario-local maps whose lane graph dead-ends at the crop boundary), so resampling fixes them: with this change all 32 agents spawn and survive on the same map/seed.

Notes

  • Before the fix, both new tests fail with active_agent_count == 24, expected 32 (verified against the unfixed header); after it, the full C suite and the Python unit tests (81 passed) are green, and the [GIGAFLOW WARNING/ERROR] spam in the smoke test output is gone.
  • Replay mode is unaffected by the spawn change (replay agents don't go through spawn_agent); its total-failure paths keep the previous remove-the-agent semantics, now with explicit call-site handling and a single warning.

🤖 Generated with Claude Code

@eugenevinitsky eugenevinitsky changed the title Fix silent agent attrition when spawn positions can't fit goals (WIP) Fix silent agent attrition when spawn positions can't fit goals Jul 21, 2026
On small maps (e.g. nuPlan bins), goal generation regularly fails for
spawn positions on short or dead-end lanes. spawn_agent computed the
route and goals only after the position rejection loop had accepted a
position, so such failures were never resampled: agents were silently
excluded from the batch at env creation (8/32 on the nuplan test map)
and left as permanently removed, terminal-masked slots after every
episode reset (8/24). The init-time goal re-roll could additionally
strand a removed agent inside the active set.

- spawn_agent: move state commit + route + goal generation inside the
  rejection loop, so a position whose routes can't hold the goals is
  rejected and resampled like a collision.
- generate_new_goals_from_route: return failure without mutating
  removal state; every caller now decides explicitly (resample at
  spawn, remove with a warning at replay init/reset and mid-episode
  regen).
- init: skip the redundant goal re-roll for gigaflow agents, which
  already received goals inside spawn_agent.
- test_drive_env_smoke: assert gigaflow spawns every requested agent
  and that no active agent is ever removed. Fails with
  "active_agent_count == 24, expected 32" before this fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant