Reduce asg_client UART file-transfer ACK latency - #3501
Conversation
Cut Mentra-owned turnaround on the BES file-transfer hot path by replacing the sleep-based UART poll with Os.poll, restoring a real cs_flts fast path, offloading window refill from RecvThread, and gating per-packet logging. Add ack_to_send/RTT instrumentation, CI microbenchmarks, and an on-device logcat harness comparable to K900Server. Co-authored-by: Nicolo Micheletti <michelettinik@gmail.com>
📋 PR Review Helper📱 Mobile App Build✅ Ready to test! (commit 🕶️ ASG Client Build✅ Ready to test! (commit 🔀 Test Locallygh pr checkout 3501 |
PR Agent Orchestrator State{
"cycle": 14,
"fixRound": 2,
"totalReviewerRuns": 14,
"consecutiveNoNewReviews": 6,
"openFindings": [],
"resolvedFindings": [],
"nitFindings": [
{
"id": "8f4aff",
"fingerprint": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/k900bluetoothmanager.java:b9f06b9d113b",
"source": "standards",
"severity": "nit",
"file": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/K900BluetoothManager.java",
"line": 81,
"message": "New member field 'fileTransferLatencyStats' omits the AGENTS.md-documented mCamelCase 'm' prefix; consistent with the file's pre-existing style (not a regression), so nit only.",
"status": "open",
"introducedCycle": 3,
"lastSeenCycle": 3
},
{
"id": "7d3a2d",
"fingerprint": ".git:f19ca6c99a2b",
"source": "standards",
"severity": "nit",
"file": ".git",
"line": 0,
"message": "PR commits are authored by 'Cursor Agent <cursoragent@cursor.com>'. No prohibited AI Co-Authored-By trailer or 'Generated with' line is present (co-author is a human), but per AGENTS.md commits should reflect the human author; prefer human as primary author.",
"status": "open",
"introducedCycle": 3,
"lastSeenCycle": 3
},
{
"id": "102fe4",
"fingerprint": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/k900bluetoothmanager.java:b9ccd802bf75",
"source": "depth",
"severity": "nit",
"file": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/K900BluetoothManager.java",
"line": 81,
"message": "currentFileTransfer and fileTransferLatencyStats are non-volatile but are now read/written across RecvThread (handleFileTransferAck/onAckSeen) and fileTransferExecutor (sendNextFilePacket/sendFilePacketAt). Worst case is a swallowed NPE in the pump during an already-aborting transfer or a dropped stats sample; consider marking currentFileTransfer volatile now that the pump runs off RecvThread.",
"status": "open",
"introducedCycle": 4,
"lastSeenCycle": 4
},
{
"id": "047551",
"fingerprint": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/mentralive/internal/serialreceivewait.java:b7c651c0eb15",
"source": "depth",
"severity": "nit",
"file": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/mentralive/internal/SerialReceiveWait.java",
"line": 47,
"message": "PollWait relies on closeSerial() to wake a blocked Os.poll (interrupt may not); prompt RecvThread shutdown/reopen depends on the fd being closed, otherwise it can linger up to POLL_TIMEOUT_MS (1000ms) and briefly share mReadBuf with a newly started RecvThread. Safe with current stop()/reopen() but worth documenting.",
"status": "open",
"introducedCycle": 4,
"lastSeenCycle": 4
},
{
"id": "bd4980",
"fingerprint": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/k900bluetoothmanager.java:1f477e8266e6",
"source": "standards",
"severity": "nit",
"file": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/K900BluetoothManager.java",
"line": 81,
"message": "fileTransferLatencyStats is accessed from RecvThread and the file-transfer executor but is not volatile; consider marking the field reference volatile for cross-thread visibility (matches existing non-volatile currentFileTransfer pattern, so not a regression).",
"status": "open",
"introducedCycle": 7,
"lastSeenCycle": 7
},
{
"id": "d2df71",
"fingerprint": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/mentralive/internal/filetransferlatencystats.java:448f06719e59",
"source": "standards",
"severity": "nit",
"file": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/mentralive/internal/FileTransferLatencyStats.java",
"line": 16,
"message": "Internal tunable MAX_SAMPLES (and POLL_TIMEOUT_MS in SerialReceiveWait) are private static final in-class; asg_client/AGENTS.md prefers tunables in AsgConstants.java. Low priority since these are internal implementation details.",
"status": "open",
"introducedCycle": 7,
"lastSeenCycle": 7
},
{
"id": "02bd19",
"fingerprint": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/k900bluetoothmanager.java:94b7d7438e69",
"source": "standards",
"severity": "nit",
"file": "asg_client/app/src/main/java/com/mentra/asg_client/io/bluetooth/managers/K900BluetoothManager.java",
"line": 81,
"message": "AGENTS.md prescribes mCamelCase member vars; fileTransferLatencyStats omits the m prefix, but matches the file's established non-prefixed convention so not actionable in isolation.",
"status": "open",
"introducedCycle": 7,
"lastSeenCycle": 7
}
],
"frozenPair": [
"bugbot",
"standards"
],
"phase": "convergence",
"status": "budget_exhausted",
"lastPair": [],
"stagnationFixRounds": 0,
"lastOpenCount": 0,
"fingerprintReopenCounts": {},
"mutedFingerprints": []
} |
|
bugbot run |
🤖 PR Agent Review — cycle 14✅ No blocking findings · 0 blocking · 7 nits No model reviews ran this cycle. Updated automatically by the PR Agent Orchestrator each review cycle. Nits do not block merge. |
Expand the CI slow path to include the AsgClientService preview and json.toString() logging costs that Mentra used to pay on every cs_flts, so the 2x fast-path assertion stays meaningful under Robolectric. Co-authored-by: Nicolo Micheletti <michelettinik@gmail.com>
This comment has been minimized.
This comment has been minimized.
|
bugbot run |
Fold ack→send / packet RTT / packets-per-sec into the existing PAYLOAD / TRANSFER section (and PIPELINE FINISHED one-liner) so the K900Server comparison metrics ship with the rest of the photo timing report.
|
bugbot run |
PR Agent HandoffExit reason: Clean handoff — CI green, no blocking findings, models have no further reviews.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
PR Agent HandoffExit reason: Clean handoff — CI green, no blocking findings, models have no further reviews.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
Dev stopgap so BLE/miniapp captures persist the sensor JPEG on-glasses even when the request sends save=false, for quality comparison pulls.
PR Agent HandoffExit reason: Budget exhausted — fix or review cycle cap reached.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
PR Agent HandoffExit reason: Budget exhausted — fix or review cycle cap reached.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
Flatten IMG_*/base.jpg captures from the glasses camera package dir into mobile/Camera_comparison/new_focus for local quality comparison.
Delete IMG_/VID_/BUFFER_ capture dirs and related ASG media folders via adb so local quality-comparison pulls can start from a clean gallery.
Replace mapfile with portable listing and a single remote wipe command so bun wipe:glasses-photos works on stock macOS /bin/bash.
PR Agent HandoffExit reason: Budget exhausted — fix or review cycle cap reached.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
PR Agent HandoffExit reason: Budget exhausted — fix or review cycle cap reached.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
PR Agent HandoffExit reason: Budget exhausted — fix or review cycle cap reached.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
PR Agent HandoffExit reason: Budget exhausted — fix or review cycle cap reached.
CI status
Remaining blocking findingsNone Nits (informational)
Humans merge when ready. Agents do not auto-merge. Label |
Summary
Addresses Mentra Live UART/BLE file-transfer turnaround lag vs the OEM K900Server benchmark (~1ms ACK→send / ~11ms RTT vs Mentra’s ~5ms / ~15ms).
Changes
Thread.sleep(5/50)poll withOs.poll(SerialReceiveWait) so inbound ACKs are noticed immediatelycs_fltsinonSerialReadduring an active transfer and callhandleFileTransferAckdirectly (removes deadmessage[0] == CMD_TYPE_PHOTOcheck that never matched##frames)sendNextFilePacketonfileTransferExecutorso UART TX drain does not block RXlog.tag.K900BluetoothManager=VERBOSEFileTransferLatencyStatsemitsFileTransferLatencySUMMARY withack_to_send/packet_rttp50/p95 and packets/sasg_client/scripts/bench-file-transfer-latency.shHow to verify
Notes
Full
packet_rttstill includes BES firmware wait (esp. 8-packet batched ACK). Mentra-owned improvement is measured byack_to_send_*.