Skip to content

Commit abfa715

Browse files
Add opt-in device redraw diagnostics
1 parent d5f9530 commit abfa715

3 files changed

Lines changed: 173 additions & 11 deletions

File tree

‎apps/decksmith-daemon/src/device_execution.rs‎

Lines changed: 130 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub struct Runtime {
107107
mics: Option<shared_microphone::Service>,
108108
mic_fatal_reported: bool,
109109
mirror: Arc<RwLock<View>>,
110+
display_diagnostics: bool,
110111
dirty: BTreeSet<DeviceId>,
111112
strip_dirty: BTreeSet<DeviceId>,
112113
render_pending: BTreeSet<DeviceId>,
@@ -202,6 +203,8 @@ impl Runtime {
202203
mics,
203204
mic_fatal_reported: false,
204205
mirror,
206+
display_diagnostics: std::env::var_os("DECKSMITH_DISPLAY_DIAGNOSTICS").as_deref()
207+
== Some(std::ffi::OsStr::new("1")),
205208
dirty: ids.into_iter().collect(),
206209
strip_dirty: BTreeSet::new(),
207210
render_pending: BTreeSet::new(),
@@ -284,7 +287,7 @@ impl Runtime {
284287
if !self.controls.manager().current(&context) {
285288
return Err("stale_device_context");
286289
}
287-
self.revoke(context.device);
290+
self.revoke(context.device, "edit_reservation");
288291
let binding = self.controls.fence_input(context.device, context.binding)?;
289292
let ticket = EditTicket {
290293
context: DeviceContext { binding, ..context },
@@ -307,7 +310,7 @@ impl Runtime {
307310
.find(|s| s.id == id)
308311
.ok_or("unknown_device")?
309312
.binding;
310-
self.revoke(id);
313+
self.revoke(id, "edit_cancel");
311314
self.controls.fence_input(id, binding)?;
312315
self.edits.remove(&id);
313316
self.sync();
@@ -373,6 +376,7 @@ impl Runtime {
373376
self.edits.remove(&id);
374377
self.touch.get_mut(&id).unwrap().levels.clear();
375378
self.next_meter = Instant::now();
379+
self.trace_display(id, "invalidate", "edit_apply");
376380
self.dirty.insert(id);
377381
self.sync();
378382
Ok(())
@@ -433,7 +437,15 @@ impl Runtime {
433437
})
434438
.collect()
435439
}
436-
fn revoke(&mut self, id: DeviceId) {
440+
fn trace_display(&self, id: DeviceId, event: &'static str, reason: &'static str) {
441+
if self.display_diagnostics
442+
&& let Some(slot) = self.layouts.keys().position(|candidate| *candidate == id)
443+
{
444+
tracing::info!(target: "decksmith::display_diagnostics", device_slot = slot, event, reason, "display diagnostic");
445+
}
446+
}
447+
fn revoke(&mut self, id: DeviceId, reason: &'static str) {
448+
self.trace_display(id, "invalidate", reason);
437449
// Connection/page/desktop fences cancel any old edit reservation too.
438450
// reserve_edit installs its new ticket only after this revocation.
439451
self.edits.remove(&id);
@@ -538,7 +550,7 @@ impl Runtime {
538550
.map(|s| s.id)
539551
.collect();
540552
for id in lost {
541-
self.revoke(id);
553+
self.revoke(id, "discovery_lost");
542554
}
543555
let revision = self.controls.discover(discovery)?;
544556
self.sync();
@@ -571,14 +583,14 @@ impl Runtime {
571583
.spawn(id, device)
572584
.map_err(|_| "device_actor_unavailable")?;
573585
let lease = proxy.lease();
574-
self.revoke(id);
586+
self.revoke(id, "device_attach");
575587
let attached = self.controls.attach(revision, slot, Box::new(proxy))?;
576588
self.leases.insert(id, lease);
577589
self.sync();
578590
Ok(attached)
579591
}
580592
pub fn disconnect(&mut self, id: DeviceId) -> Result<()> {
581-
self.revoke(id);
593+
self.revoke(id, "device_disconnect");
582594
let result = self.controls.disconnect(id);
583595
self.sync();
584596
result
@@ -587,7 +599,7 @@ impl Runtime {
587599
if self.edits.contains_key(&context.device) {
588600
return Err("profile_update_pending");
589601
}
590-
self.revoke(context.device);
602+
self.revoke(context.device, "page_navigation");
591603
let result = self.controls.navigate(context, page).map(|_| ());
592604
self.sync();
593605
result
@@ -715,7 +727,7 @@ impl Runtime {
715727
.ok_or("profile_update_epoch_exhausted")?;
716728
let ids: Vec<_> = self.layouts.keys().copied().collect();
717729
for id in ids {
718-
self.revoke(id);
730+
self.revoke(id, "desktop_gate");
719731
}
720732
self.controls.fence_gate(state.0, state.1)?;
721733
// Reservations cannot survive a desktop lifecycle fence. A worker that
@@ -768,7 +780,7 @@ impl Runtime {
768780
.checked_add(1)
769781
.ok_or("profile_update_epoch_exhausted")?;
770782
for status in self.statuses() {
771-
self.revoke(status.id);
783+
self.revoke(status.id, "foreground_change");
772784
self.controls.fence_input(status.id, status.binding)?;
773785
}
774786
self.mirror.write().unwrap().foreground = revision;
@@ -788,7 +800,7 @@ impl Runtime {
788800
} else {
789801
None
790802
};
791-
self.revoke(id);
803+
self.revoke(id, "profile_apply");
792804
self.controls.apply_saved_profile(&catalog, id, binding)?;
793805
self.layouts
794806
.insert(id, Arc::from(catalog.profile(id)?.document().bytes()));
@@ -882,6 +894,7 @@ impl Runtime {
882894
})
883895
.is_some_and(|page| page.homebridge)
884896
{
897+
self.trace_display(unit.id, "invalidate", "plugin_state");
885898
self.dirty.insert(unit.id);
886899
}
887900
}
@@ -921,6 +934,7 @@ impl Runtime {
921934
&& touch.system != state
922935
{
923936
touch.system = state;
937+
self.trace_display(unit.id, "invalidate", "system_state");
924938
self.dirty.insert(unit.id);
925939
}
926940
}
@@ -930,6 +944,7 @@ impl Runtime {
930944
return Err("render_state_too_large");
931945
}
932946
*self.touch.get_mut(&id).ok_or("unknown_device")? = state;
947+
self.trace_display(id, "invalidate", "touch_state");
933948
self.dirty.insert(id);
934949
Ok(())
935950
}
@@ -989,6 +1004,7 @@ impl Runtime {
9891004
.brightness;
9901005
self.controls
9911006
.brightness(event.context, (i16::from(b) + percent).clamp(0, 100) as u8)?;
1007+
self.trace_display(id, "invalidate", "brightness_action");
9921008
self.dirty.insert(id);
9931009
Ok(None)
9941010
}
@@ -1154,6 +1170,7 @@ impl Runtime {
11541170
state.targets = wanted;
11551171
state.audio = audio;
11561172
if keys_changed {
1173+
self.trace_display(status.id, "invalidate", "audio_state");
11571174
self.dirty.insert(status.id);
11581175
} else if status.model == decksmith_core::device_model::DeviceModel::Plus {
11591176
self.strip_dirty.insert(status.id);
@@ -1230,6 +1247,7 @@ impl Runtime {
12301247
result: Err(e),
12311248
});
12321249
} else {
1250+
self.trace_display(reply.scope.device.device, "frame_submitted", "full");
12331251
self.painted
12341252
.insert(reply.scope.device.device, reply.scope.device);
12351253
}
@@ -1244,6 +1262,8 @@ impl Runtime {
12441262
scope: reply.scope,
12451263
result: Err(e),
12461264
});
1265+
} else {
1266+
self.trace_display(reply.scope.device.device, "frame_submitted", "touch");
12471267
}
12481268
}
12491269
Err(e) => feedback.push(Feedback {
@@ -1280,6 +1300,7 @@ impl Runtime {
12801300
)
12811301
.is_ok()
12821302
{
1303+
self.trace_display(id, "render_requested", if full { "full" } else { "touch" });
12831304
self.render_pending.insert(id);
12841305
self.dirty.remove(&id);
12851306
self.strip_dirty.remove(&id);
@@ -1293,6 +1314,7 @@ impl Runtime {
12931314
.context(status.id, ControlAddress::Key(0))
12941315
&& self.painted.get(&status.id).is_some_and(|c| *c != context)
12951316
{
1317+
self.trace_display(status.id, "invalidate", "device_context_changed");
12961318
self.dirty.insert(status.id);
12971319
}
12981320
}
@@ -1389,6 +1411,104 @@ mod meter_tests {
13891411
}
13901412
}
13911413
#[test]
1414+
fn display_diagnostics_report_foreground_redraw_without_private_data() {
1415+
#[derive(Clone)]
1416+
struct Capture(Arc<std::sync::Mutex<Vec<u8>>>);
1417+
impl std::io::Write for Capture {
1418+
fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {
1419+
self.0.lock().unwrap().extend_from_slice(bytes);
1420+
Ok(bytes.len())
1421+
}
1422+
fn flush(&mut self) -> std::io::Result<()> {
1423+
Ok(())
1424+
}
1425+
}
1426+
let bytes = Arc::new(std::sync::Mutex::new(Vec::new()));
1427+
let writer = Capture(bytes.clone());
1428+
let subscriber = tracing_subscriber::fmt()
1429+
.without_time()
1430+
.with_writer(move || writer.clone())
1431+
.finish();
1432+
tracing::subscriber::with_default(subscriber, || {
1433+
let root = std::env::temp_dir().join(format!(
1434+
"decksmith-display-diag-{}",
1435+
random_device_id().unwrap()
1436+
));
1437+
let store = Store::create(&root).unwrap();
1438+
let ids = [random_device_id().unwrap(), random_device_id().unwrap()];
1439+
let models = [DeviceModel::Plus, DeviceModel::Mk2];
1440+
let discovery = Discovery::new(vec![
1441+
Candidate::new(0, models[0], Some("private-fixture-serial-0")),
1442+
Candidate::new(1, models[1], Some("private-fixture-serial-1")),
1443+
])
1444+
.unwrap();
1445+
for (slot, id) in ids.into_iter().enumerate() {
1446+
store
1447+
.enroll(
1448+
slot as u64,
1449+
&discovery,
1450+
slot as u8,
1451+
Enrollment::new(id, "private-fixture-name", 50, None),
1452+
)
1453+
.unwrap();
1454+
}
1455+
let mut runtime =
1456+
Runtime::start(store.load().unwrap(), vec![Box::new(NoEffects)], None).unwrap();
1457+
let revision = runtime
1458+
.discover(Discovery::new(discovery.candidates().to_vec()).unwrap())
1459+
.unwrap();
1460+
for (slot, model) in models.into_iter().enumerate() {
1461+
runtime
1462+
.attach(
1463+
revision,
1464+
&discovery,
1465+
slot as u8,
1466+
Box::new(VirtualDeck::new(model)),
1467+
)
1468+
.unwrap();
1469+
}
1470+
let end = Instant::now() + Duration::from_secs(5);
1471+
while runtime
1472+
.statuses()
1473+
.iter()
1474+
.any(|s| !s.input_ready || !s.display_ready)
1475+
{
1476+
assert!(Instant::now() < end);
1477+
runtime.tick();
1478+
std::thread::sleep(Duration::from_millis(2));
1479+
}
1480+
assert!(bytes.lock().unwrap().is_empty());
1481+
runtime.display_diagnostics = true;
1482+
runtime.foreground(2).unwrap();
1483+
while runtime
1484+
.statuses()
1485+
.iter()
1486+
.any(|s| !s.input_ready || !s.display_ready)
1487+
{
1488+
assert!(Instant::now() < end);
1489+
runtime.tick();
1490+
std::thread::sleep(Duration::from_millis(2));
1491+
}
1492+
runtime.stop();
1493+
drop(runtime);
1494+
let _ = std::fs::remove_dir_all(root);
1495+
});
1496+
let log = String::from_utf8(bytes.lock().unwrap().clone()).unwrap();
1497+
assert!(log.contains("foreground_change"), "{log}");
1498+
assert!(
1499+
log.contains("render_requested")
1500+
&& log.contains("frame_submitted")
1501+
&& log.contains("full"),
1502+
"{log}"
1503+
);
1504+
assert!(
1505+
log.contains("device_slot=0") && log.contains("device_slot=1"),
1506+
"{log}"
1507+
);
1508+
assert_eq!(log.matches("foreground_change").count(), 2, "{log}");
1509+
assert!(!log.contains("private-fixture"), "{log}");
1510+
}
1511+
#[test]
13921512
fn cached_system_and_plugin_feedback_follow_page_without_new_observer_sample() {
13931513
let root = std::env::temp_dir().join(format!(
13941514
"decksmith-provider-display-{}",

‎apps/decksmith-daemon/src/device_execution/coordinator_tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn idle_sync_keeps_actions_live_and_fences_reject_without_waiting_for_refresh()
165165
assert!(f.runtime.mirror.read().unwrap().accepts(&partner));
166166
// Complete the normal owner transition: raw manager fencing alone does
167167
// not request the replacement frame (the public Runtime paths do both).
168-
f.runtime.revoke(plus);
168+
f.runtime.revoke(plus, "test_fence");
169169
f.runtime.sync();
170170
f.ready();
171171
let before_page = scope(&f.runtime, plus);

‎docs/display-diagnostics.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Display redraw diagnostics
2+
3+
The multi-device runtime has an opt-in diagnostic for investigating unexpected
4+
redraws. Set `DECKSMITH_DISPLAY_DIAGNOSTICS=1` in an isolated diagnostic process
5+
before it starts; omit it for normal operation. The installed desktop service is
6+
not changed by this setting in a separate process.
7+
8+
The `decksmith::display_diagnostics` events contain a process-local anonymous
9+
`device_slot`, an `event` and a fixed `reason`. Slots can change between runs and
10+
must not be used as persistent device identities. The diagnostic does not log
11+
application names, wallpaper paths, device serials, layouts, image pixels or
12+
control assignments. Other logging in the process may have different privacy
13+
properties and should be reviewed separately before sharing.
14+
15+
`invalidate` events identify the trigger that requested a full redraw, such as
16+
`foreground_change`, `desktop_gate`, `device_attach`, `system_state`,
17+
`plugin_state`, `audio_state` or `profile_apply`. Multiple invalidations can be
18+
coalesced, and initial device setup can request a frame without an `invalidate`
19+
event. `render_requested` records whether a full or touch-only render was
20+
accepted by the renderer; `frame_submitted` means the rendered frame was queued
21+
for the device actor. Neither event proves the physical USB write or display
22+
completed. Timestamps and slots allow events to be correlated; a shared time is
23+
not by itself proof of causation.
24+
25+
Use temporary data and simulated devices for initial checks. A desktop session
26+
requires separate approval for any build installation, service restart or
27+
configuration change. Revert any approved diagnostic configuration afterward.
28+
29+
## Isolated verification — October 29, 2026
30+
31+
A private D-Bus session and simulated Plus and MK.2 devices exercised the
32+
hardware-enabled daemon build. The focused test verified diagnostics are quiet
33+
when disabled, reported a foreground invalidation for both anonymous slots,
34+
and recorded the requested and submitted full frames without exposing fixture
35+
device names or serials. Fourteen existing simulated-device execution and
36+
lifecycle tests and the active coordinator test passed with hardware support;
37+
one of the coordinator diagnostics was explicitly ignored. Formatting and diff
38+
checks passed. The earlier non-hardware execution tests also passed.
39+
40+
These checks establish the diagnostic behavior in isolation. They do not identify
41+
the cause of the wallpaper-associated redraw on the physical desktop, prove a
42+
physical USB write, or replace physical acceptance.

0 commit comments

Comments
 (0)