restart ignores the surface setting: always comes back on the old drainer's surface #3
adom-tts 1.9.63 · adom/core 4.15.3 · adom-wiki 1.8.36 · Linux cloud workspace, pup player on a Windows PC through Adom Bridge
The bug
adom-tts restart always starts the fresh player on the surface the old drainer was using, so the surface setting is ignored. adom-tts settings documents --surface flag > $ADOM_TTS_SURFACE > this file > hydrogen default and says a surface change takes effect on restart, but once a player is on hydrogen, every restart comes back on hydrogen.
Repro (seen live, then reproduced in an isolated HOME)
~/.adom/tts/config.tomlhas[play] surface = "pup", and the shell hasADOM_TTS_SURFACE=pup.- A player is running on hydrogen (
__drain --surface hydrogen). - Run
adom-tts restart.
Expected: a pup player. Got:
- the fresh drainer runs as
adom-tts __drain --surface hydrogen(pgrep) ~/.adom/tts/player.jsonstays{"port":...,"surface":"hydrogen"}; events.jsonl showsport_reused, thendrain_start surface="hydrogen"ADOM_TTS_SURFACE=desktop adom-tts restartalso comes back on hydrogensay --surface pupdoes not move it either: the clip joins the live hydrogen player. That part is the shared-player design, but restart was the only way to move the player, and restart could not.
The same thing from the 1.9.63 source in an isolated HOME, with fake adom-cli and adom-bridge:
== start a hydrogen player (one-off --surface hydrogen), config.toml says pup
== adom-tts restart --force (config.toml surface = pup)
→ restarted: killed stale drainer 3174117; spawned a fresh hydrogen player.
drainer: adom-tts __drain --surface hydrogen
player.json: {"port":46361,"surface":"hydrogen"}
== ADOM_TTS_SURFACE=desktop adom-tts restart --force
→ restarted: killed stale drainer 3174156; spawned a fresh hydrogen player.
Cause
play::restart (src/play.rs) reads the old drainer's command line first and uses its --surface X whenever it finds one; it falls back to config::resolve_surface only when it finds none. ensure_drainer always spawns __drain --surface <surface> with an explicit flag, so the old command line always has one, and the env and config never get a say. This came with the issue #10 fix (keep a pup player on pup), which put "restart in kind" ahead of the settings instead of after them. It also made restart's own hint (settings set surface hydrogen then adom-tts restart) a dead end for a pup player.
Fix
config::requested_surface(flag, cfg): the surface the flag,$ADOM_TTS_SURFACEor config.toml names, or None when none does.PlayConfig.surface_setrecords whether config.toml names one.resolve_surfaceis nowrequested_surface(..).unwrap_or(cfg.surface), so every other caller behaves as before.restartpicksrequested_surface(--surface, cfg), then the old drainer's surface, then hydrogen. A settings change now takes effect on restart, and a player opened with a one-off--surface pupwith no setting still comes back on pup (issue #10 kept).- New
restart --surface hydrogen|pup|desktop, so the documented "--surface flag" step exists for restart too and a live player can be moved in one command. - player.json: the fresh drainer already rewrites it at start (
{"port":N}, same port reused) and records the surface it opened on, so with the right surface the old one is replaced; T14 checks it. - Docs: the restart bullet in the dev skill, the Settings paragraph in the user skill, and T14 in the test skill.
No version bump or changelog here; left for the release.
How it was tested
cargo test --release: 13 pass, 3 of them new in config.rs (surface_setonly when the file names one, the flag wins, file or none).tools/ralph-test.sh: 36 pass, 0 fail, including the new T14 (its own HOME, fakeadom-cliandadom-bridge, nothing reaches a Hydrogen session or a Bridge machine):- config.toml (pup) beats the old drainer's surface (hydrogen); the drainer's command line,
drain_startand player.json all say pup ADOM_TTS_SURFACE=desktopbeats config.tomlrestart --surface hydrogenbeats$ADOM_TTS_SURFACE- nothing set: a pup player restarts as pup
- config.toml (pup) beats the old drainer's surface (hydrogen); the drainer's command line,
- T14 against the unpatched 1.9.63 build: 4 of 6 fail (each restart comes back on hydrogen).
- Port reuse is unchanged: T9 passes, and the isolated repro keeps one port across hydrogen, pup and desktop restarts.
- Not tested: a real pup window or Hydrogen tab (fakes only), and macOS.
Workaround until this ships
Kill the drainer by its pid (first line of ~/.adom/tts/drainer.lock), then start one by hand on the surface you want:
ADOM_BRIDGE_TARGET=<machine> ADOM_TTS_SURFACE=pup setsid nohup ~/.local/bin/adom-tts __drain --surface pup </dev/null >/dev/null 2>&1 &
🤖 Generated with Claude Code
Diff Skip to comments (1)
@@ -1,206 +1,239 @@⋯ 51 unchanged lines ⋯ #[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, }⋯ 2 unchanged lines ⋯ fn default() -> Self { Self { surface: Surface::Hydrogen,+ surface_set: false, pup_session: "adom-tts".to_string(), pup_profile: "adom-tts".to_string(), }⋯ 26 unchanged lines ⋯ /// 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⋯ 40 unchanged lines ⋯ ("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"); }⋯ 44 unchanged lines ⋯ } #[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); assert_eq!(Surface::from_str("Pup").unwrap(), Surface::Pup); assert!(Surface::from_str("nope").is_err()); } }+@@ -1,1134 +1,1141 @@⋯ 179 unchanged lines ⋯ /// 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`⋯ 299 unchanged lines ⋯ 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),⋯ 633 unchanged lines ⋯ assert!(first_words(&"word ".repeat(40), 60).chars().count() <= 60); } }+@@ -1,3138 +1,3143 @@⋯ 2765 unchanged lines ⋯ 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,⋯ 38 unchanged lines ⋯ // 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 {⋯ 309 unchanged lines ⋯ assert_eq!(strip_proxy_prefix("/"), "/"); } }+@@ -1,352 +1,407 @@⋯ 18 unchanged lines ⋯ # 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.⋯ 319 unchanged lines ⋯ [ "$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 echo echo "RESULT: $PASS pass, $FAIL fail (rig: $T)" [ $FAIL -eq 0 ]+@@ -1,466 +1,470 @@⋯ 394 unchanged lines ⋯ 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⋯ 62 unchanged lines ⋯ ## Audio playback via pup, not new port mappings For one-off audio playback (TTS test, narration preview), base64-inline the mp3 into a small auto-play HTML, then `pup_open_window` with a data URL, then force-play with `pup_eval` if Chrome's autoplay policy blocks it. Don't create a new public port mapping just to serve one audio file. Past pattern: `port-add 8888` for a one-time TTS preview, never cleaned up.+@@ -1,362 +1,368 @@⋯ 90 unchanged lines ⋯ 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;⋯ 256 unchanged lines ⋯ `adom-tts` is a client of `service-tts` (shared container, NEVER install a local TTS engine as a fallback; report outages instead). Client-side synth robustness lives in `synth_chunk`/`split_into_chunks` in `src/main.rs`.+@@ -1,128 +1,130 @@⋯ 42 unchanged lines ⋯ | 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⋯ 77 unchanged lines ⋯ 2. `./tools/ralph-test.sh` → 0 fail. 3. UI pass (section 2) if player.html changed. 4. Only then: build.sh → deploy → publish (see adom-tts-publish).+
Comments
Log in to comment.