From fb4182f68dbafa96e07834a52b4d3c08cdd537e5 Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Thu, 4 Jun 2026 19:49:28 +0200 Subject: [PATCH] fix(admin): clear session-expired flag on successful browser restart (0.53.1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A successful `coordinated_restart` re-runs `on_launch`, which re-injects PHPSESSID and re-probes via `verify_session_with_recircuit` — so reaching `Ok(())` proves the session is live. But the handler never dropped the sticky `session_expired` flag, so the admin UI continued to report "Session Expired" and chapter workers kept idling until the operator made a second click on "Clear expired" (or pushed a new cookie). The fix is one line in `restart_browser`: on `Ok(())`, call `c.session.clear_expired()`. The error path still leaves the flag set since a failed restart means the probe didn't confirm. Adds a focused `clear_expired_flips_sticky_flag_without_touching_session` unit test to pin the controller-side semantic; the existing `update_persists_and_clears_expired_then_round_trips` test continues to cover the cookie-refresh path. Co-Authored-By: Claude Opus 4.7 (1M context) --- backend/Cargo.lock | 2 +- backend/Cargo.toml | 2 +- backend/src/api/admin/crawler.rs | 7 +++++++ backend/src/crawler/session_control.rs | 13 +++++++++++++ frontend/package.json | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 7037e40..92937d9 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1470,7 +1470,7 @@ checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" [[package]] name = "mangalord" -version = "0.53.0" +version = "0.53.1" dependencies = [ "anyhow", "argon2", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 161dd14..ecdaedd 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mangalord" -version = "0.53.0" +version = "0.53.1" edition = "2021" default-run = "mangalord" diff --git a/backend/src/api/admin/crawler.rs b/backend/src/api/admin/crawler.rs index 804ba4f..c3e8ad4 100644 --- a/backend/src/api/admin/crawler.rs +++ b/backend/src/api/admin/crawler.rs @@ -233,6 +233,13 @@ async fn restart_browser( ) -> AppResult> { let c = require_crawler(&state)?; let result = c.browser_manager.coordinated_restart(c.drain_deadline).await; + // A successful coordinated_restart re-runs on_launch, which re-injects + // PHPSESSID and re-probes — i.e. the session is live. Drop the sticky + // `session_expired` flag so chapter workers stop idling without + // requiring a second click on "Clear expired". + if result.is_ok() { + c.session.clear_expired(); + } // Push the post-restart browser phase to live subscribers immediately. c.status.poke(); repo::admin_audit::insert( diff --git a/backend/src/crawler/session_control.rs b/backend/src/crawler/session_control.rs index 6558316..811953e 100644 --- a/backend/src/crawler/session_control.rs +++ b/backend/src/crawler/session_control.rs @@ -164,4 +164,17 @@ mod tests { Some("good-sid-123") ); } + + #[sqlx::test(migrations = "./migrations")] + async fn clear_expired_flips_sticky_flag_without_touching_session(pool: PgPool) { + // The flag starts `true` per `controller(pool)`'s test wiring. + let c = controller(pool); + assert!(c.is_expired(), "test fixture starts with the flag set"); + c.clear_expired(); + assert!(!c.is_expired(), "clear_expired flips the sticky flag to false"); + assert!( + c.current().await.is_none(), + "clear_expired does not invent a session" + ); + } } diff --git a/frontend/package.json b/frontend/package.json index 00793c0..95a2575 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "mangalord-frontend", - "version": "0.53.0", + "version": "0.53.1", "private": true, "type": "module", "scripts": {