Some background callbacks do not finish in a multi-page app

Hi all, I encountered this weird behavior in the situation in the minimal example below.

How to reproduce: click on the button, wait for the background callback to finish, click again, repeat.

In this case the background task finishes every second time it is triggered. The other times there is a 204 response for "POST /_dash-update-component?cacheKey=..."

Dash version
dash[diskcache]==3.0.3

app.py

import diskcache
import dash
from dash import html, dcc

cache = diskcache.Cache("./cache")
background_callback_manager = dash.DiskcacheManager(diskcache.Cache("./cache_dm"))

app = dash.Dash(
    __name__,
    use_pages=True,
    suppress_callback_exceptions=True,
    background_callback_manager=background_callback_manager,
)

server = app.server

app.layout = html.Div([
    html.H1("Main App Layout"),
    dcc.Location(id="url"),
    dash.page_container
])

if __name__ == "__main__":
    app.run(debug=False)

pages/home.py

import time
import dash
from dash import html, dcc, Input, Output, callback, clientside_callback

dash.register_page(__name__, path="/", name="Home")

layout = html.Div([
    html.H2("Home Page with Button and Background Task"),
    html.Button("Click Me", id="main-button", n_clicks=0),
    dcc.Store(id="dummy-store"),
    dcc.Store(id="reload-trigger"),
])

clientside_callback(
    """
    function(data) {
        if (data) {
            window.location.reload();
        }
        return null;
    }
    """,
    Output("dummy-store", "data"),
    Input("reload-trigger", "data"),
    prevent_initial_call=True
)

@callback(
    Output("reload-trigger", "data"),
    Input("main-button", "n_clicks"),
    prevent_initial_call=True
)
def update_store(n_clicks):
    time.sleep(5)
    return True


@callback(
    Input("main-button", "n_clicks"),
    background=True,
    prevent_initial_call=True
)
def long_running_task(n_clicks):
    print("Background task started...")
    time.sleep(10)
    print("Background task finished.")

Any ideas on how to correct it? I would need for the app to finish all background tasks even if the window is reloaded.

Thank you.