IntCars13 Bug Analysis
How the IntCars13 UPPAAL model was explained and why its Monitor can reach ERROR. The boxes in purple show which tool was used at each step. Session date: 7 October 2026.
Tools used, in order
| # | Tool | Purpose | Outcome |
|---|---|---|---|
| 1 | mcp__uppaal__getModel | Read the full XML of the model open in the UPPAAL editor | Declarations, the templates Decisions, Car, Monitor, and the existing queries |
| 2 | ToolSearch | Load the schema of the deferred tool getQueryTrace | Tool became callable |
| 3 | mcp__uppaal__verifyQueries [1] | Model-check query 1, E<> Monitor.ERROR (shortest diagnostic trace option already set) | satisfied, 0.026 s, symbolic trace of 21 transitions |
| 4 | mcp__uppaal__getQueryTrace (1) | Retrieve that counterexample trace step by step | The collision run summarised below |
| — | none | Explanation of the model, root cause, and proposed fix | Done by reasoning over the model text and the trace; the fix was not run in UPPAAL |
Afterwards, Write created this HTML file. The earlier HTML of the whole session was created with Write and shown with SendUserFile.
The conversation
Read the current model from the UPPAAL editor. Everything in “What the model represents” below comes from this XML.
What the model represents source: getModel
The model describes two cars on a one-lane road (CARS = 2, LANES = 1) driving towards a finish line at Finish = 700. Time runs in discrete steps of 1 second. At each step every car picks an acceleration, and then all positions and speeds are updated together.
Global state
pos[i],vel[i],acc[i],lane[i]hold each car's position, speed, acceleration and lane. Car 1 starts at position 0 and car 2 at position 10, both standing still.accis one of −2, 0 or +2. The car picksa ∈ {-1,0,1}and storesacc = 2*a. Speeds start at 0 and change by ±2, so they are always even.brk_dist(v, 2) = v²/4is the distance a car needs to stop from speedvwhen braking at −2. With the integer update rule this is exact: braking fromv = 2kcovers1 + 3 + … + (2k−1) = k²units. own calculationupdateDiscrete()applies one second of motion to every car:pos += vel + acc/2,vel += acc, and it recomputesbd.
int brk_dist(int v, int a) { return (v*v)/(2*a); }
void updateDiscrete() {
for (i : car_t) {
pos[i] = pos[i] + vel[i] + acc[i]/2;
vel[i] = vel[i] + acc[i];
bd[i] = brk_dist(vel[i],2);
}
}
Decisions (the scheduler)
- In its urgent location it sends
go[1], thengo[2], all at the same moment. - It waits exactly 1 time unit in
Wait. - It calls
updateDiscrete()and starts the next round.
So the cars decide one after the other within the same instant, both using the same positions and speeds. Then the physics update moves everything at once.
Car(id)
When a car receives go[id] it enters the urgent location Choose and either:
- finishes: if
pos ≥ Finish, it moves toFinand setsvel = acc = 0; or - picks an action: it non-deterministically selects
aand a lanel, subject to this guard:- the new speed
vel + 2amust lie in[0, MaxVel); - the lane change is only allowed if no car overlaps in front of it or behind it in the target lane (with one lane,
l == lane[id]always holds, so this part does nothing); - the safety rule:
a ≥ 0 imply !exists front: overlap_forward(front, l). This means the car may keep its speed or speed up only if no car ahead is within its current braking distancebrk_dist(vel[id]).
- the new speed
bool overlap_forward(car_t front, lane_t l) {
return front!=id && lane[front]==l
&& (pos[front]-pos[id]) >= 0
&& (pos[front]-pos[id]) <= brk_dist(vel[id],2);
}
Monitor
The monitor moves to ERROR as soon as pos[1] == pos[2] and the cars are in the same lane, which counts as a collision. The urgent broadcast ASAP! makes it take that transition immediately, without letting time pass.
select:mcp__uppaal__getQueryTrace
Loaded the trace-retrieval tool so the counterexample could be read.
[1], timeout 120 s
Model-checked query 1:
`E<> Monitor.ERROR` : satisfied
resources: 0.026 s, engine memory peak 26 MB
symbolic trace: 21 transitions -> getQueryTrace(1)(1, 0, 30)
Retrieved all 22 states (21 transitions) of the shortest trace. The table below condenses it to the state after each updateDiscrete() step.
Why the Monitor can reach ERROR source: verifyQueries + getQueryTrace
E<> Monitor.ERROR is satisfied. This is the shortest trace UPPAAL produced:
| time | car 1 (pos, vel) | car 2 (pos, vel) | gap | bd(vel[1]) | car 1 chooses | trace steps |
|---|---|---|---|---|---|---|
| 0 | 0, 0 | 10, 0 | 10 | 0 | accelerate (+2) | [0]–[4] |
| 1 | 1, 2 | 10, 0 | 9 | 1 | accelerate (+2) | [5]–[9] |
| 2 | 4, 4 | 10, 0 | 6 | 4 | brake (−2) | [10]–[14] |
| 3 | 7, 2 | 10, 0 | 3 | 1 | accelerate (+2), allowed because 3 > 1 | [15]–[19] |
| 4 | 10, 4 | 10, 0 | 0 | ERROR | [20]–[21] |
Car 2 never moves; it picks a = 0 every time. At time 3, car 1 is 3 units behind it at speed 2. Its braking distance is only 1, so overlap_forward is false and the guard allows it to accelerate. In the following second car 1 moves vel + acc/2 = 2 + 1 = 3 units and lands exactly on car 2. In trace step [21] the Monitor takes ASAP! into ERROR.
The root cause reasoning, no tool
The safety check looks at the wrong moment. It compares the gap with the braking distance at the current speed, bd(v). Because a decision is held for a full second, the condition that actually matters is this:
gap > (distance moved this step) + (braking distance after this step) = (v + acc/2) + bd(v + acc)
The guard ignores two things:
- The distance travelled during the step before the car can react again.
- The higher braking distance after accelerating.
At time 3 the correct condition would have required 3 > 3 + bd(4) = 7, so accelerating would have been forbidden.
The leader's behaviour is irrelevant here. Car 2 just stands still, so the bug shows up even against a parked car. A moving leader cannot help either: its speed is never negative, so it never moves backwards towards the follower.
A fix proposed, not verified
Replace the forward check with one that looks one step ahead:
bool safe_forward(car_t front, lane_t l, int a2) { // a2 = 2*a
int step = vel[id] + a2/2;
return !(front!=id && lane[front]==l
&& pos[front]-pos[id] >= 0
&& pos[front]-pos[id] <= step + brk_dist(vel[id]+a2, 2));
}
The guard then uses forall (i:car_t) safe_forward(i, l, 2*a) for every value of a, including braking, instead of the current a>=0 imply …. This should guarantee no collisions, for the following reason:
- The check keeps
gap > bd(v)true at every decision. - Braking always preserves that property, because
(v−1) + (v−2)²/4 = v²/4. - Holding still at
v = 0is always safe.
So a safe choice always exists and the gap can never close to 0. This fix has not been run in UPPAAL. Checking it would take setLocalDeclarations / modifyEdge on the Car template followed by verifyQueries [1].
A side note on the Monitor reasoning, no tool
ERROR checks only pos[1] == pos[2]. Positions change in jumps, so a car can skip over the other without ever being at the same position. For example, a car at 9 with speed 6 that is forced to brake moves to 14, passing a car at 10, and the monitor never sees it. Because car 1 starts behind car 2 on a single lane, pos[1] >= pos[2] would be a more reliable collision condition.