← Commit history
Merge PR #633: restart ignores the surface setting: always comes back on the old drainer's surface
7 files changed
+128−23
dev-skills/adom-tts-dev/SKILL.md+12−7@@ -91,13 +91,18 @@ manually, deploy a new version and let supersede do the handoff. If you must the working hydrogen surface, and `check`/`--confirm` say the clip is fine, only the surface failed. - **`adom-tts restart`** = the real reset: kills the drainer, clears the LOCK- (not the portfile), respawns a FRESH drainer of the SAME surface, pinned from- the current env. `reopen` only re-offers the tab and keeps a broken player;- `restart` replaces it. CRITICAL: restart must NOT wipe `player.json`, it once- did, which forced the fresh drainer onto a NEW port while the human's page- kept polling the OLD one forever (the exact wedge port-reuse prevents). Keep- the portfile so `bind_player_server` rebinds the SAME port and the page- reconnects with no `reopen`.+ (not the portfile), respawns a FRESH drainer pinned from the current env, on+ the surface the documented order picks: `--surface` > `$ADOM_TTS_SURFACE` >+ config.toml > the old drainer's surface > hydrogen. The old drainer's+ `__drain --surface X` must come AFTER the settings: read first, it always+ wins (it is always explicit), so a restart could never apply a settings+ change and a hydrogen player stayed hydrogen forever (1.9.63). `reopen` only+ re-offers the tab and keeps a broken player; `restart` replaces it.+ CRITICAL: restart must NOT wipe `player.json`, it once did, which forced the+ fresh drainer onto a NEW port while the human's page kept polling the OLD+ one forever (the exact wedge port-reuse prevents). Keep the portfile so+ `bind_player_server` rebinds the SAME port and the page reconnects with no+ `reopen`. - Never reopen the tab for a clip that already started (`reached > 0`), a reopen reloads the page and REPLAYS the clip (users heard 5× repeats). - **`restart` REFUSES while a clip is playing or human-paused** (exit 5;
dev-skills/adom-tts-test/SKILL.md+1@@ -43,6 +43,7 @@ and the incident behind each: | T12 queue management | issue #4 §2: unscoped `queue clear` refused (exit 5), `--mine` scopes by thread, `queue drop` one, `--all` empties, all dropped clips in History, `control skip` ends the playing clip with verdict `skipped` and no retry | | T13 hydrogen to desktop fall-through | issue #5: with a fake `adom-cli` (no browser session) and a fake `adom-bridge`, a drainer start must log `surface_fallthrough` to desktop, send `hd_api POST /hbw/open` to the pinned target, record `surface: desktop` in the portfile, every `clip_end` names the surface that took it, and (issue #7) the drain opens the desktop window EXACTLY ONCE: the audience wait's first offer lands as `surface_open_skipped`, never a second `/hbw/open`; later offers log `surface_reoffer` with the reason | | T10 second clip survives the swap | "two threads sent clips and you stopped the playing one": stale telemetry from clip A killed clip B on arrival (falsely "ok"). The `stale-done` fake-page mode replays the blob-download window; B must live >4s and never inherit A's `reached` |+| T14 restart follows the settings | 1.9.63: `restart` reused the old drainer's `__drain --surface hydrogen`, so `surface = pup` in config.toml and `$ADOM_TTS_SURFACE` were ignored and the player came back on hydrogen every time. Asserts config beats the old surface, env beats config, `--surface` beats env, and with nothing set a pup player stays pup (issue #10); each fresh drainer's cmdline, `drain_start` and `player.json` name the new surface | Extending: add a `say "TN ..."` block copying an existing test. Trigger the behavior via the real CLI, assert via events.jsonl (`ev <kind>`) or the queue
skills/adom-tts/SKILL.md+4−1@@ -395,7 +395,10 @@ clip from every thread lands in that one tab; nothing opens a second one. settings, never preferences). It writes the same file as the CLI: `adom-tts settings` shows it, `adom-tts settings set surface webview|pup|desktop` changes the default surface. A change takes effect on the next player spawn-(`adom-tts restart` when nothing is playing).+(`adom-tts restart` when nothing is playing). `say --surface X` joins a live+player wherever it is; to move the live player, `adom-tts restart --surface X`+(restart picks `--surface` > `$ADOM_TTS_SURFACE` > settings > the old player's+surface > hydrogen). **The dock and the page.** `adom-tts open` shows the player (starts one if none is live) and returns. `adom-tts open --print-url` is the Hydrogen dock's serve
src/config.rs+36−4@@ -52,6 +52,8 @@ impl Surface { #[derive(Debug, Clone)] pub struct PlayConfig { pub surface: Surface,+ /// True when config.toml names a surface (false = `surface` is the hydrogen default).+ pub surface_set: bool, pub pup_session: String, pub pup_profile: String, }@@ -60,6 +62,7 @@ impl Default for PlayConfig { fn default() -> Self { Self { surface: Surface::Hydrogen,+ surface_set: false, pup_session: "adom-tts".to_string(), pup_profile: "adom-tts".to_string(), }@@ -92,16 +95,23 @@ pub fn load() -> Config { /// Resolve effective surface following the documented precedence: /// CLI flag → env var (`$ADOM_TTS_SURFACE`) → config file → default. pub fn resolve_surface(cli: Option<Surface>, cfg: &PlayConfig) -> Surface {- if let Some(s) = cli {- return s;+ requested_surface(cli, cfg).unwrap_or(cfg.surface)+}++/// The surface the flag, `$ADOM_TTS_SURFACE` or the config file asks for, in+/// that order; None when none of them names one (the hydrogen default applies).+/// `restart` uses it to tell a real setting from the default.+pub fn requested_surface(cli: Option<Surface>, cfg: &PlayConfig) -> Option<Surface> {+ if cli.is_some() {+ return cli; } if let Ok(s) = std::env::var("ADOM_TTS_SURFACE") { if let Ok(parsed) = Surface::from_str(&s) {- return parsed;+ return Some(parsed); } eprintln!("adom-tts: ignoring invalid $ADOM_TTS_SURFACE='{s}'"); }- cfg.surface+ if cfg.surface_set { Some(cfg.surface) } else { None } } /// Write a setting back to config.toml (creates the file if absent). Only the@@ -148,6 +158,7 @@ fn parse(src: &str) -> Config { ("play", "surface") => { if let Ok(s) = Surface::from_str(&value) { cfg.play.surface = s;+ cfg.play.surface_set = true; } else { eprintln!("adom-tts: ignoring invalid surface '{value}' in config"); }@@ -197,6 +208,27 @@ pup_profile = 'my-profile' assert_eq!(cfg.play.pup_session, "adom-tts"); } + #[test]+ fn surface_set_only_when_the_file_names_one() {+ assert!(parse("[play]\nsurface = \"pup\"\n").play.surface_set);+ assert!(!parse("[play]\npup_session = \"x\"\n").play.surface_set);+ assert!(!parse("[play]\nsurface = \"nope\"\n").play.surface_set);+ }++ #[test]+ fn requested_surface_flag_wins() {+ let cfg = parse("[play]\nsurface = \"pup\"\n");+ assert_eq!(requested_surface(Some(Surface::Desktop), &cfg.play), Some(Surface::Desktop));+ }++ #[test]+ fn requested_surface_file_or_none() {+ if std::env::var_os("ADOM_TTS_SURFACE").is_some() { return; } // env outranks the file+ assert_eq!(requested_surface(None, &parse("[play]\nsurface = \"pup\"\n").play), Some(Surface::Pup));+ assert_eq!(requested_surface(None, &parse("").play), None);+ assert_eq!(resolve_surface(None, &parse("").play), Surface::Hydrogen);+ }+ #[test] fn surface_from_str() { assert_eq!(Surface::from_str("hydrogen").unwrap(), Surface::Hydrogen);
src/main.rs+10−4@@ -180,13 +180,19 @@ enum Cmd { /// closed/dead Hydrogen tab) without restarting playback or the queue. Reopen, /// Fully tear down the drainer and spawn a FRESH one that re-reads the- /// current env (pins pup to ADOM_BRIDGE_TARGET). Use when the player is- /// wedged (status shows STALLED / no sink). Queued clips survive. REFUSES- /// while a clip is playing or human-paused (--force overrides).+ /// current env (pins pup to ADOM_BRIDGE_TARGET) and settings. Use when the+ /// player is wedged (status shows STALLED / no sink), or to apply a surface+ /// change. Queued clips survive. REFUSES while a clip is playing or+ /// human-paused (--force overrides).+ ///+ /// Surface: --surface > $ADOM_TTS_SURFACE > config.toml > old player's > "hydrogen". Restart { /// Restart even if a clip is mid-play or paused (the clip is lost) #[arg(long)] force: bool,+ /// Start the fresh player on this surface: "hydrogen", "pup" or "desktop".+ #[arg(long, value_parser = parse_surface_arg)]+ surface: Option<Surface>, }, /// Show or change persistent settings (default playback surface, pup /// session/profile). `settings` shows all; `settings set surface pup`@@ -492,7 +498,7 @@ fn main() -> Result<()> { Cmd::Status => play::show_status(), Cmd::Check { clip } => play::check_clip(&clip), Cmd::Reopen => play::reopen(),- Cmd::Restart { force } => play::restart(force),+ Cmd::Restart { force, surface } => play::restart(force, surface), Cmd::Settings { action } => cmd_settings(action), Cmd::Queue { action } => match action { QueueAction::Clear { mine, all } => play::queue_clear(mine.as_deref(), all),
src/play.rs+11−7@@ -2766,7 +2766,7 @@ fn wait_surface_outcome(from: u64, wait: Duration) -> Option<Result<(), String>> None } -pub fn restart(force: bool) -> Result<()> {+pub fn restart(force: bool, surface_cli: Option<Surface>) -> Result<()> { persist_surface_env(); // capture THIS shell's env (incl ADOM_BRIDGE_TARGET) // PAUSE-IS-SACRED, RESTART EDITION. Field incident: the human paused a clip // (their kid asked a question), an ops restart killed the drainer 81s later,@@ -2811,16 +2811,20 @@ pub fn restart(force: bool) -> Result<()> { // reconnects on its own with no `reopen`. (Removed the wipe here.) } log_event("drain_restart", serde_json::json!({ "killed": killed }));- // Replace the drainer IN KIND: read the surface the dead one was using- // (`__drain --surface pup`) so a pup session doesn't silently come back as- // hydrogen. Fall back to the configured default.+ // Pick the surface the documented way: --surface, $ADOM_TTS_SURFACE, config.toml. The+ // old drainer's `__drain --surface X` always carries an explicit surface, so reading it+ // FIRST made every restart come back on the old surface and ignore a settings change.+ // Only when nothing names a surface is the drainer replaced IN KIND, so a player opened+ // with a one-off `--surface pup` does not come back as hydrogen (issue #10). let cfg = config::load();- let surface = Some(old_cmdline.as_str()).filter(|c| !c.is_empty())+ let old_surface = Some(old_cmdline.as_str()).filter(|c| !c.is_empty()) .and_then(|c| if c.contains("--surface pup") { Some(Surface::Pup) } else if c.contains("--surface hydrogen") { Some(Surface::Hydrogen) } else if c.contains("--surface desktop") { Some(Surface::Desktop) }- else { None })- .unwrap_or_else(|| config::resolve_surface(None, &cfg.play));+ else { None });+ let surface = config::requested_surface(surface_cli, &cfg.play)+ .or(old_surface)+ .unwrap_or(cfg.play.surface); let events_before = events_log_len(); ensure_drainer(surface)?; match killed {
tools/ralph-test.sh+54@@ -19,6 +19,7 @@ # T10 second clip survives the swap: stale telemetry must not kill it # T11 script markers: cue one marker, no auto-advance, re-cue allowed, status # T12 queue management: clear needs scope, --mine, drop one, control skip+# T14 restart follows the surface settings, not the old drainer's --surface # # Usage: tools/ralph-test.sh (builds nothing; uses target/release) # Exit: 0 all pass, 1 any fail. Prints PASS/FAIL per test.@@ -344,6 +345,59 @@ N=$(grep -c '/hbw/open' $FAKE_LOG 2>/dev/null) [ "$N" -eq 1 ] && ok "desktop window opened exactly once per drain (hd_api /hbw/open x$N)" || bad "hd_api /hbw/open called $N times in one drain (issue #7)" ev surface_open_skipped | grep -q 'issue #7' && ok "the repeat offer was logged as skipped (not a second open)" || bad "no surface_open_skipped event" +say "T14 restart follows the settings (--surface > \$ADOM_TTS_SURFACE > config.toml > old player's surface)"+# 1.9.63 field report: config.toml said pup, the player was on hydrogen, and every+# restart came back on hydrogen: it reused the old drainer's `__drain --surface hydrogen`,+# which always outranked the settings. Own HOME and fakes; nothing reaches a real+# Hydrogen session or Bridge machine.+H14=$T/t14; F14=$H14/fakebin; mkdir -p $H14/.adom/tts/queue $F14+cat > $F14/adom-cli <<'EOS'+#!/bin/sh+case "$*" in+ *"hydrogen workspace get"*) echo '{"focusedPanelId":"p1","root":{"type":"leaf","id":"p1","tabs":[]}}';;+ *"hydrogen probe"*) echo '{"browser_connected":true,"sse_connections":1}';;+esac+exit 0+EOS+cat > $F14/adom-bridge <<'EOS'+#!/bin/sh+case "$*" in+ *pup_eval*) echo '{"ok":true,"result":true}';;+ *hd_api*) echo '{"success":true,"ok":true,"status":200}';;+ *targets*) echo '{"targets":[{"name":"fakebox"}]}';;+ *) echo '{"ok":true}';;+esac+EOS+chmod +x $F14/adom-cli $F14/adom-bridge+r14() { env -u ADOM_DESKTOP_TARGET -u ADOM_TTS_SURFACE -u VSCODE_PROXY_URI -u VSCODE_IPC_HOOK_CLI HOME=$H14 PATH=$F14:/usr/bin:/bin \+ ADOM_BRIDGE_BIN=$F14/adom-bridge ADOM_BRIDGE_TARGET=fakebox ADOM_TTS_NO_HINTS=1 "$@"; }+d14() { python3 -c "print(open('$H14/.adom/tts/drainer.lock').read().split()[0])" 2>/dev/null; }+# the surface the LIVE drainer runs on, read from its command line (waits for the fresh one)+s14() { local p c; for i in $(seq 1 30); do p=$(d14); c=$([ -n "$p" ] && tr '\0' ' ' < /proc/$p/cmdline 2>/dev/null)+ [ -n "$c" ] && { echo "$c" | sed -n 's/.*__drain --surface \([a-z]*\).*/\1/p'; return; }; sleep 0.5; done; }+# the surface player.json names, once it names $1 (or whatever it says after ~10s)+j14() { local s; for i in $(seq 1 20); do s=$(python3 -c "import json;print(json.load(open('$H14/.adom/tts/player.json')).get('surface',''))" 2>/dev/null)+ [ "$s" = "$1" ] && break; sleep 0.5; done; echo "$s"; }+last_start14() { grep -h '"drain_start"' $H14/.adom/tts/events.jsonl 2>/dev/null | tail -1 | sed -n 's/.*"surface":"\([a-z]*\)".*/\1/p'; }+printf '[play]\nsurface = "pup"\n' > $H14/.adom/tts/config.toml+mkmp3 $T/t14.mp3 seed-t14 4000+r14 "$BIN" play $T/t14.mp3 --surface hydrogen >/dev/null 2>&1+S=$(s14); J=$(j14 hydrogen)+[ "$S" = hydrogen ] && [ "$J" = hydrogen ] && ok "setup: one-off --surface hydrogen player (config.toml says pup)" || bad "setup: drainer=$S player.json=$J"+r14 "$BIN" restart --force >/dev/null 2>&1+S=$(s14); J=$(j14 pup)+[ "$S" = pup ] && [ "$(last_start14)" = pup ] && ok "restart: config.toml (pup) beats the old drainer's surface (hydrogen)" || bad "restart came back on '$S' (drain_start $(last_start14)), config.toml says pup"+[ "$J" = pup ] && ok "player.json surface replaced: hydrogen -> pup" || bad "player.json still names '$J' after the move to pup"+r14 env ADOM_TTS_SURFACE=desktop "$BIN" restart --force >/dev/null 2>&1+S=$(s14); [ "$S" = desktop ] && [ "$(j14 desktop)" = desktop ] && ok "restart: \$ADOM_TTS_SURFACE (desktop) beats config.toml (pup)" || bad "env desktop restart came back on '$S'"+r14 env ADOM_TTS_SURFACE=desktop "$BIN" restart --force --surface hydrogen >/dev/null 2>&1+S=$(s14); [ "$S" = hydrogen ] && [ "$(j14 hydrogen)" = hydrogen ] && ok "restart --surface hydrogen beats \$ADOM_TTS_SURFACE" || bad "--surface hydrogen restart came back on '$S'"+r14 "$BIN" restart --force --surface pup >/dev/null 2>&1+rm -f $H14/.adom/tts/config.toml+r14 "$BIN" restart --force >/dev/null 2>&1+S=$(s14); [ "$S" = pup ] && ok "nothing set: a pup player restarts as pup (issue #10 kept)" || bad "unset restart of a pup player came back on '$S'"+DP=$(d14); [ -n "${DP:-}" ] && kill -9 $DP 2>/dev/null+ # teardown DP=$(python3 -c "print(open('$T/.adom/tts/drainer.lock').read().split()[0])" 2>/dev/null) [ -n "${DP:-}" ] && kill -9 $DP 2>/dev/null