Wether or not Anvil will provide the option to set a time out, it seems you can communicate with background tasks (e.g. check status, kill them etc.). Maybe use a scheduled task to check the status every x minutes and kill the other task when it takes too long. This allows you to build your own simple task management solution, e.g. task type X is allowed to run for X minutes and this or that needs to happen when it runs too long, a time out or an exception occurs.
Note, I dont know the effect of a server load of 100% on the execution of scheduled tasks. But that should be fairly easy to test.
I do this quite often similar to the method that @gerbertdelangen suggests. Others who heavily use background tasks have had many previous discussions on how they register the task objects or ID’s in tables to handle management with some kind of supervisor background task that runs as a scheduled task checking states against the table.
This could include timestamps of when the task was registered, and so could be managed to no run after a specified time, however…
This sounds like an even better idea, like something either passed in the background task decorator or the background task call itself like max_timeout=300 or something. (For a 5 minute automatic task kill/timeout)