fix(app): a worker run's late lines keep its run's secrets masked
Each worker run's log sink keeps the values masked when it started (its secrets in use), so a line still being logged after a stop gave up waiting, and after the next start replaced the values in use, is still masked. The debug echo on stderr is masked the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,8 @@ impl std::fmt::Debug for LineSink {
|
||||
}
|
||||
|
||||
/// How long a stop or restart waits for the worker's last output to be logged. A child of the worker
|
||||
/// (an MCP server) may hold its output open after it is gone; then the rest is not read.
|
||||
/// (an MCP server) may hold its output open after it is gone; then the rest is not read. A line
|
||||
/// still being logged after that is masked with its run's values all the same (`run_sink`).
|
||||
const OUTPUT_DRAIN: Duration = Duration::from_secs(5);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -124,6 +125,7 @@ impl WorkerProcess {
|
||||
pub fn start(&self) {
|
||||
let (opts, token, port) = (self.opts.clone(), self.token.clone(), self.port);
|
||||
let (shared, stop, events) = (self.shared.clone(), self.stop.clone(), self.events.clone());
|
||||
let sink = opts.line_sink.clone().unwrap_or_else(run_sink);
|
||||
let task = tokio::spawn(async move {
|
||||
let mut delay = opts.restart_delay;
|
||||
loop {
|
||||
@@ -143,7 +145,6 @@ impl WorkerProcess {
|
||||
shared.lock().unwrap().child_pid = child.id();
|
||||
crate::info_log!("worker", "voice worker started pid={:?} port={port}", child.id());
|
||||
let mut ready_rx = events.subscribe();
|
||||
let sink = opts.line_sink.clone().unwrap_or_else(|| LineSink(Arc::new(worker_line)));
|
||||
let mut readers = vec![];
|
||||
// The worker's own logs hold timings and counts only (voice_worker.spec.md).
|
||||
if let Some(out) = child.stdout.take() {
|
||||
@@ -161,6 +162,7 @@ impl WorkerProcess {
|
||||
}));
|
||||
}
|
||||
if let Some(err) = child.stderr.take() {
|
||||
let sink = sink.clone();
|
||||
readers.push(tokio::spawn(async move {
|
||||
let mut lines = BufReader::new(err).lines();
|
||||
while let Ok(Some(line)) = lines.next_line().await {
|
||||
@@ -256,13 +258,21 @@ fn spawn(opts: &WorkerProcessOptions, token: &str, port: u16) -> std::io::Result
|
||||
cmd.spawn()
|
||||
}
|
||||
|
||||
/// The default sink of a worker started now: the app's log, masking also the values masked at
|
||||
/// this moment (this run's secrets, `logs.rs` `set_secrets_in_use`), so a line it writes late (after
|
||||
/// a stop gave up waiting for it, and the next start replaced the values in use) is still masked.
|
||||
pub fn run_sink() -> LineSink {
|
||||
let masks = crate::logs::installed().map(|h| h.masked_values()).unwrap_or_default();
|
||||
LineSink(Arc::new(move |line: &str| worker_line(line, &masks)))
|
||||
}
|
||||
|
||||
/// A line the voice worker printed: on stderr with debug logging, and always to the log hub (its
|
||||
/// own category picks the tab; warnings and tracebacks reach the log screen without debug logging).
|
||||
fn worker_line(line: &str) {
|
||||
fn worker_line(line: &str, masks: &[String]) {
|
||||
if crate::log::debug_enabled() {
|
||||
eprintln!("{}", crate::log::line("worker", line));
|
||||
eprintln!("{}", crate::log::line("worker", &crate::logs::redact(line, masks)));
|
||||
}
|
||||
if let Some(hub) = crate::logs::installed() {
|
||||
hub.push_worker(line);
|
||||
hub.push_worker_masked(line, masks);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user