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

#ToolPurposeOutcome
1mcp__uppaal__getModelRead the full XML of the model open in the UPPAAL editorDeclarations, the templates Decisions, Car, Monitor, and the existing queries
2ToolSearchLoad the schema of the deferred tool getQueryTraceTool became callable
3mcp__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
4mcp__uppaal__getQueryTrace (1)Retrieve that counterexample trace step by stepThe collision run summarised below
—noneExplanation of the model, root cause, and proposed fixDone 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

User
I have just uploaded a new model: IntCars13. Please explain the model. Also explain why the Monitor can enter the ERROR location.
Toolmcp__uppaal__getModel

Read the current model from the UPPAAL editor. Everything in “What the model represents” below comes from this XML.

Claude

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

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)

  1. In its urgent location it sends go[1], then go[2], all at the same moment.
  2. It waits exactly 1 time unit in Wait.
  3. 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:

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.

ToolToolSearch select:mcp__uppaal__getQueryTrace

Loaded the trace-retrieval tool so the counterexample could be read.

Toolmcp__uppaal__verifyQueries [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)
Toolmcp__uppaal__getQueryTrace (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.

Claude

Why the Monitor can reach ERROR source: verifyQueries + getQueryTrace

E<> Monitor.ERROR is satisfied. This is the shortest trace UPPAAL produced:

timecar 1 (pos, vel)car 2 (pos, vel)gapbd(vel[1])car 1 choosestrace steps
00, 010, 0100accelerate (+2)[0]–[4]
11, 210, 091accelerate (+2)[5]–[9]
24, 410, 064brake (−2)[10]–[14]
37, 210, 031accelerate (+2), allowed because 3 > 1[15]–[19]
410, 410, 00ERROR[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:

  1. The distance travelled during the step before the car can react again.
  2. 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:

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.