Files
AgentCompany/src
ZacharyZhang-NY ecd1bc2e33 refactor(worker): single active-run map replaces parallel claim structures
Worker scheduling invariants ("one agent at a time", "one exclusive
workspace lock at a time") were enforced across three parallel
structures: `activeByAgent: Map<string, string>`,
`activeByWorkspace: Map<string, string>`, and `queue: RunJob[]`. Every
claim, release, and tick had to update them in lockstep, with defensive
comments explaining the ordering to future readers.

Replace with one `active: Map<runId, ActiveRun>` where ActiveRun
carries agentId + workspaceKey. Busy checks iterate the map (≤ dozens
of entries); dispatch is a single set + splice. Release is a single
delete. No parallel structures to keep in sync.

- Add `isAgentBusy(agentId)` and `isWorkspaceBusy(lockKey)` as local
  helpers — both O(n) over the active map, which is fine at this scale.
- `tickQueue` is claim-before-dispatch: writes `active.set` synchronously
  before `startRun` so no async window exists between claim and
  dispatch.
- Drop the `lockKey` parameter threading through `startRun` — the map
  carries it.
2026-04-17 15:07:27 -04:00
..
2026-04-17 14:03:56 -04:00
2026-04-17 14:03:56 -04:00
2026-04-17 14:03:56 -04:00