Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path is not released, after it was reserved through another train causing a crash #8048

Open
RailwAI opened this issue Mar 28, 2020 · 13 comments
Open

Comments

@RailwAI
Copy link

@RailwAI RailwAI commented Mar 28, 2020

A quite interesting one about path reservations. I am familiar with the fact that my AI sometimes may cause edge cases for the game logic, because in its regular checks it may turn around vehicles and replace signals by path-based signals. I have seen crashing trains before, but this time I have a bug that is clearly not the AI its fault and that I can reproduce.

Version of OpenTTD

1.10-RC1
AI: RailwAI version 22

Expected result

Two options:

  • Paths are never reserved through another train, because it leads to crashing trains.
  • If it occurs that a path was reserved through another train and both trains crash, the path of both trains will be released

Actual result

I have added a screen capture to show what is happening in my game (that I can reproduce by reloading the savegame and let it run).
Starting from August 1, 2008 we see the following:
Train 82 (Jar 82 SH '8P') is heading to Grondhattan Train Depot #4 (near station Grondhattan North). The recently bought train 165 is loading passengers at the train station Grondhattan North.
When Train 82 is entering the depot, my AI does its regular checks. Train 165 is ready for departure from Grondhattan North and gets a path reserved, despite that train 82 is still blocking the tracks.
Trains 165 and 82 crash into each other. The path that was reserved by train 165 is never relased (not in 2008, nor in 2050).

OpenTTD 1.10.0-RC1 2020-03-28 09-49-02_Trim_Trim.mp4.zip

Steps to reproduce

Make sure RailwAI version 22 is installed. Download and open the following savegame that starts in 1955. In August 2008 trains 82 and 165 crash into each other. The path that was reserved for train 165 is not released.
jaranja, 3rd sep 1955.zip

@SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Mar 28, 2020

There was a train crash on 3rd April 2005
Unnamed, 2005-04-14

@RailwAI
Copy link
Author

@RailwAI RailwAI commented Mar 29, 2020

Interesting too, but the crash in 2005 is clearly caused by the behaviour of my AI: it turns around train 5 that gets a path reserved up to the one-way path signal between trains 104 and 5. Then it decides to replace that one-way path signal by a normal path signal, allowing train 5 to continue.

@TrueBrain TrueBrain added this to the 1.11.0 milestone Jan 5, 2021
@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Jan 7, 2021

This is very difficult to reproduce. You supply a savegame from 1955, but the problem happens in 2008. This is a very long time to fast-forward :D Do you happen to have a savegame that is close before the crash or anything? Anything I can reproduce in a minute, instead of a few hours would be very helpful. Otherwise I am afraid this will be really difficult to reproduce :(

@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Jan 7, 2021

On the included movie you can see that train 165 makes a track reservation while train 82 is still on the rails. This most likely means train 82 releases his reservation, causing the accident. Why train 165 doesn't clean up his reservation might be related or not.

I tried to reproduce this issue in various of ways on a recent version, but I cannot. Playing the savegame with a recent version results in a completely different network (makes sense, I guess).

What makes this difficult, that it might happen in 1.10-RC1, but it might have been a problem that has long been fixed in master. So the amount of time we would have to invest in tracing this problem (not to forget fast-forwarding a game for 60 years every time) is not worth the effort for what seems to be an extreme edge-case caused by an AI. I am really sorry about that, but I also have to be honest here.

If you can reproduce this in a way that doesn't require me to reply 60 years of game, that would be awesome! In general, if you run into this again, please do let us know. The movie is somewhat useful, just too bad the other train was not opened on screen :D For sure this is a bug, but it currently is hiding :D

Again, I am sorry, but I am going to close this ticket, as there is not enough information to reproduce and/or triage this :(

PS: tnx for the detailed ticket, that was very useful :D Just the 1955 -> 2008 is such a long time to reply .. :(

@MingweiSamuel
Copy link
Contributor

@MingweiSamuel MingweiSamuel commented Jan 20, 2021

I have encountered this bug in normal play. I'll see if I can reproduce it.

@auge8472
Copy link
Contributor

@auge8472 auge8472 commented Jan 20, 2021

I have encountered this bug in normal play. I'll see if I can reproduce it.

@MingweiSamuel In which version you encountered the problem?

@MingweiSamuel
Copy link
Contributor

@MingweiSamuel MingweiSamuel commented Jan 20, 2021

@MingweiSamuel In which version you encountered the problem?

openttd-1.10.3-windows-win64

@RailwAI
Copy link
Author

@RailwAI RailwAI commented Sep 18, 2021

Today I encountered the same problem as more than one year ago while developing a new version of my AI. Again it was a long time to reproduce (1955 -> 2003), but I managed to get more information and I would suggest to reopen this issue.

First I have a video, showing the cause of the crash: the AI does remove a part of track in front of train 148, then rebuilds it. Train 9 gets a path reservation and train 148 continues.
Second I have a savegame made after the dumb AI action. The savegame can be used to reproduce the crash. After the crash, the path reservation of train 9 is never cleared properly.

https://user-images.githubusercontent.com/42977884/133889547-134949b1-aad0-4aff-9060-f5c7d62c8052.mp4
Unnamed, 2003-04-17.zip

@TrueBrain TrueBrain reopened this Sep 18, 2021
@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Sep 18, 2021

So basically, what happens (correct me if I misunderstand the situation):

  • Train reserves tracks
  • Rail is removed -> Train unreserves track, as it will no longer go that way
  • Rail is placed back
  • Train is not passing a PBS signal, so is not creating a new track reservation
  • Train enters track where another train has a reservation
  • Trains "collide"

I am not sure this a bug, or just expected behaviour.
If my memory serves me right, trains only update their reservation when they hit a PBS signal (or leave a depot/station, which have implied PBS signals).

Technically, this might also be really difficult to fix if we do consider it a bug, as how is the train to know the track was put back? Or that it is in a PBS block? It would require a completely different type of pathfinder.

I leave it to people who did a bit more with these kind of things to confirm if my reasoning is correct, but I am afraid this is a situation: if you shoot yourself in the foot, it hurts. Sorry :(

PS: I delved into the part "should these trains crash". The bug is about "the reservation is not released", which of course should be looked into.

@michicc
Copy link
Member

@michicc michicc commented Sep 18, 2021

It is more or less the same thing as what happens if you remove a signal in front of a train. The pathfinder/PBS implementation is not designed to refresh all train reservations every time the track/signals change.

The difficulty here is of course that while it is very easy for a human to notice and anticipate such a situation, it is not easy for an AI.

@RailwAI
Copy link
Author

@RailwAI RailwAI commented Sep 19, 2021

I agree that colliding of the two trains can be expected behaviour, but if it is expected behaviour, then the game should handle it well.
At the moment the track reservation is never released. After a while the crashed trains are removed, but the track reservation keeps occupying the track until eternity.

@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Sep 19, 2021

Yup, and I got a bit distracted if the crash should happen at all :) Updated my comment to make that more clear :)

Sorry for derailing the topic at hand :( My bad :)

@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Sep 19, 2021

The problem is that the train entering the section "illegally" is also eating the reserved tracks as it moves along (this is what trains do, when they find a rail that is reserved and they are on, they remove the reservation). This is what messes up the reservation. Even if the trains wouldn't crash, the situation would be bad.

This also happens if you force a train through a red light. So the problem is really easy to reproduce now:

Build a single line, put two PBS signals on both sides, build trains on both sides. Let one run, so it reserves the track between the two PBS signals. Stop the train. Start the other train, force it through the red light .. and the path reservation is now broken :)

image
image

@TrueBrain TrueBrain removed this from the 1.11.0 milestone Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants