fix(nip46): gate remaining trace writes to live relay sessions

The wrong-identity refusal test and the auto-name retry loop still wrote
into the live pairing-trace.log on every e2e run: three bogus "restored
signer answered as a different account" npubs and phantom "auto-name
attempt" lines were test traffic, not live Amber misbehaviour, and they
kept derailing the forensics review. fail and the background enrichment
traces now check live_relays like every other trace site.
Verified: running the e2e suite appends zero lines to the trace file.
This commit is contained in:
Avi 2026-09-26 20:34:08 -05:00
commit 332ab647c9

View file

@ -1305,7 +1305,22 @@ impl Nip46ClientSigner {
let message = message.into(); let message = message.into();
eprintln!("[nip46] session failed: {message}"); eprintln!("[nip46] session failed: {message}");
eprintln!("[NIP46] session failed: {message}"); eprintln!("[NIP46] session failed: {message}");
// Forensics-log only LIVE sessions. The e2e harness deliberately
// fails restored sessions (wrong-identity refusal test), and its
// "session failed" lines were landing in pairing-trace.log among
// real ones — three different bogus "restored signer answered as a
// different account" npubs turned out to be test runs, not live
// Amber misbehaviour. Read the relays under a short lock before the
// mutating one below.
let relays = self
.inner
.try_lock()
.ok()
.and_then(|g| g.connection.as_ref().map(|c| c.relays.clone()))
.unwrap_or_default();
if live_relays(&relays) {
pairing_trace(&format!("session failed: {message}")); pairing_trace(&format!("session failed: {message}"));
}
if let Ok(mut inner) = self.inner.try_lock() { if let Ok(mut inner) = self.inner.try_lock() {
// First failure wins: the demux loop exits with a generic // First failure wins: the demux loop exits with a generic
// "Connect handshake failed" AFTER the handshake task already // "Connect handshake failed" AFTER the handshake task already
@ -2328,6 +2343,7 @@ impl Nip46ClientSigner {
// UI polls status and vault, so the row fills in a moment later. // UI polls status and vault, so the row fills in a moment later.
{ {
let app = self.app.clone(); let app = self.app.clone();
let live_enrichment = live_relays(&connection.relays);
tokio::spawn(async move { tokio::spawn(async move {
let relays_for_meta = { let relays_for_meta = {
let app = app.lock().await; let app = app.lock().await;
@ -2358,15 +2374,27 @@ impl Nip46ClientSigner {
meta = Some(found); meta = Some(found);
break; break;
} }
Ok(Ok(None)) => pairing_trace(&format!( Ok(Ok(None)) => {
if live_enrichment {
pairing_trace(&format!(
"auto-name attempt {attempt}: no kind-0 found on any relay" "auto-name attempt {attempt}: no kind-0 found on any relay"
)), ));
Ok(Err(join_err)) => pairing_trace(&format!( }
}
Ok(Err(join_err)) => {
if live_enrichment {
pairing_trace(&format!(
"auto-name attempt {attempt}: fetch task panicked: {join_err}" "auto-name attempt {attempt}: fetch task panicked: {join_err}"
)), ));
Err(_) => pairing_trace(&format!( }
}
Err(_) => {
if live_enrichment {
pairing_trace(&format!(
"auto-name attempt {attempt}: fetch timed out (75s budget)" "auto-name attempt {attempt}: fetch timed out (75s budget)"
)), ));
}
}
} }
if attempt < 4 { if attempt < 4 {
tokio::time::sleep(Duration::from_secs(20)).await; tokio::time::sleep(Duration::from_secs(20)).await;
@ -2376,10 +2404,12 @@ impl Nip46ClientSigner {
Some(meta) => meta, Some(meta) => meta,
None => return, None => return,
}; };
if live_enrichment {
pairing_trace(&format!( pairing_trace(&format!(
"auto-name: kind-0 fetched (display_name={:?} name={:?})", "auto-name: kind-0 fetched (display_name={:?} name={:?})",
meta.display_name, meta.name meta.display_name, meta.name
)); ));
}
let mut app = app.lock().await; let mut app = app.lock().await;
let mut changed = false; let mut changed = false;
if let Some(row) = app if let Some(row) = app