Preemption is a corridor, not a junction
Emergency vehicle priority in the twin holds a green at every junction the vehicle is about to reach, not the one it has arrived at — and the difference is the whole idea.
Source: src/features/vector/twin/engine.ts.
The obvious way to give an emergency vehicle priority is to turn its light green when it arrives. That is also useless. A vehicle that arrives at a red junction has already braked, and the queue it just joined is still in front of it.
The twin preempts a corridor. Every tick, while an emergency vehicle is live, each junction is tested against three conditions:
ahead = (junction.x - emergency.x) * emergency.dx
lateral = |junction.y - emergency.y|
preempt when: ahead > -20 and ahead < spacing * 2.6 and lateral < 12Read in order: the junction is in front of the vehicle rather than behind it, within about two and a half blocks, and on the vehicle’s own axis rather than a parallel street.
So the green does not follow the vehicle. It arrives before it, and it arrives at several junctions at once — a rolling window of held phases that the vehicle drives into rather than waits for.
The tolerance behind it§
ahead > -20 is the detail worth explaining. A strictly forward test would drop a
junction the instant the vehicle’s centre passed the stop line — while it is still
physically inside the intersection. The twenty-unit tolerance holds the phase until
the vehicle is genuinely clear.
This is the kind of constant that only appears once you watch the thing run. The first version dropped preemption too early and produced a visible stutter: the light flipped back to its normal cycle with the ambulance still crossing.
Preempted junctions leave the controller entirely§
The signal loop begins if (junction.preempted) continue;. A held junction does not
decrement its timer, does not consult its queues, and does not participate in adaptive
control at all until the vehicle clears.
That is a deliberate hierarchy rather than a special case bolted on. Priority is not a large weight in the same optimisation — it is a different decision, taken by a different rule, that the optimiser does not get a vote on. A weighting can always be outvoted by enough traffic on the cross street. An override cannot.
The same shape appears throughout VECTOR: governance sits above intelligence, and the intelligent layer is not consulted about whether the governing one applies.
The cost is real and visible§
Preemption is not free, and the twin does not hide the bill. Held phases mean the cross-street queues keep growing while the corridor is open, and the delay metric rises for everyone who is not the emergency vehicle.
That trade is the correct one and it is still a trade. A system that reported priority as costless would be describing a different simulation from the one that is running.