Skip to content

[P2] Ambient break event leaks haul reservations and loses carried resources #363

Description

@itsmiso-ai

Ask: Refund carried resources and release their build reservation when the ambient break event clears a worker's task.

Expected files: scripts/colony_sim.gd

Problem:
The ambient break branch in ColonySim.maybe_fire_event (event_roll == 1) unconditionally sets worker.task = {} and grants break_ticks = 6. It only releases the gather reservation (release_resource) when the cleared task was a gather / gather_food with a resource. Two leak paths are not covered:

  1. A worker mid-haul who has already picked up from the stockpile (i.e. worker.carrying[resource] >= 1) loses those carried units when the task is wiped — worker.carrying is never refunded and the worker eventually resets to a new task without delivering.
  2. The reservation that was incremented in _pick_up_for_build is never decremented, because _deliver_carried is what decrements it. gather_haul_tasks subtracts build.reserved from its need calculation, so a leaked reservation starves the build of future hauls — the build silently stalls even though the global stockpile looks fine.

This was masked by the zero-worker guard (#346) but the carry/refund path was never addressed.

Evidence:

  • scripts/colony_sim.gdmaybe_fire_event rolls event_roll == 1, clears worker.task, and only releases the reservation for gather-kind tasks.
  • scripts/colony_sim.gd_pick_up_for_build increments build.reserved[resource]; _deliver_carried is the only call site that decrements it.
  • scripts/colony_sim.gdgather_haul_tasks computes need = cost - delivered - reserved, so a leaked reservation under-counts need.

Acceptance:

  • A break that fires while a worker is mid-haul with carried resources refunds the carried units to the stockpile and decrements the matching build.reserved[resource] before clearing the task.
  • Behavior for idle workers and for gather-kind tasks (which already release reservations) is preserved.
  • A new test in tests/test_reservations.gd (or an existing suite that covers break behavior) exercises a mid-haul break and asserts both the carry refund and the reservation balance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auditAudit, review, or investigation work.priority/p2Normal priority.status/readyReady for Dispatch worker pickup.type/bugBug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions