Repository navigation
feat: capture the phone's log to a file with iph syslog - #9
Conversation
|
Thanks for this PR and for the thorough real-device verification! The Before merging, we'd like to align on a few design points so 1. In-memory ring buffer + live
|
A dropped stream sends a FIN and forgets the connection. A peer that only writes never reads that FIN. It keeps sending into a port that no longer answers until it gives up, about 30 s later. The phone's log relay serves no new client in the meantime. `StreamHandle::reset_on_drop()` marks a stream so that dropping it sends a RST for its own connection instead, on whatever path the stream ends: a library that keeps the stream drops it on an error, a timeout or a normal end alike. The returned `Reset` can also send it earlier, with `now()`, for an owner that must not wait for that drop, and `sent()` resolves once it has gone out. Either way the connection gets one reset: whichever comes first sends it and the other sends nothing, so it never reaches a port that a later connection has reused. Unmarked streams still close with a FIN. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`iph syslog start|stop|status` streams the phone's os_trace log into a JSON Lines file while other commands keep running, so a test or an agent can check what an app logged after a tap. Until now the only way was `sudo log collect` on the Mac. The daemon holds one capture. `start` connects the relay under the session lock and hands the stream to a task of its own that never touches the session. `--process` (executable name, survives app restarts) and `--level` filter on this side, `--pid` on the phone. The file starts with a `start` line and ends with an `end` line that names the reason: stop, a dropped connection, or the daemon exiting. `--max-mb` moves the file to `<file>.1`. `stop --grep RE --max N` returns the latest matching entries. A capture ends by resetting its connection. Closed with a FIN, the relay kept writing into it and sent nothing to the next capture for about 30 s (measured on an iPhone 16 Pro, iOS 27.2.1). The stream is marked to reset on drop before idevice takes it, so a start that fails partway and a reader that stops on its own reset it too. A capture that is ended resets it at once, before `Session::reset` can close the tunnel under it, and `stop` waits until the reset is out. `start` opens the file only once the relay runs, so a start that fails leaves the previous capture's file as it was. The hint about a silent relay shows only while a capture without `--pid` runs. The same command is the MCP tool `iph_syslog` and the script function `syslog()`, which is not an input and cannot choose the file. Batch is left out: a capture spans requests, and a failing batch would leave it running. idevice 0.1.68 passes the device's microseconds where chrono expects nanoseconds; the entry's time puts them back as microseconds. Enables idevice's `syslog_relay` feature, which adds chrono (and its num-traits and autocfg) to Cargo.lock. Co-Authored-By: Claude Opus 5.5 <[email protected]>
README and README.ko get a "Phone log" section with the file format, filters, the measured volume over Wi-Fi and what ends a capture. The agent skill says when to wrap steps in a capture and how to find an app's executable name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of the capture file writer: - The file is wrapped in a BufWriter. A small task of its own flushes it every 250 ms, so a quiet capture's last lines still reach the file; it is not the reading task, which must never be interrupted between two reads of an entry. The `end` line is flushed when a capture ends. - A rotation flushes and drops the file handle, removes an existing `.1`, then renames, so it does not depend on how a platform treats an open file or an existing target. CI now runs the tests on Windows. The rotation test rolls over twice, which is the rename over an existing `.1`. If a step of the rotation fails, the file that holds the last entry stays open and the `end` line still goes after it, so the file does not read like one a killed daemon left. - `max_mb` takes 1 to 4096 and the byte size is computed with checked_mul; anything else is `invalid_argument`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of the capture design: a file is the wrong default, and the only
way to look at a running capture was to stop it.
The kept entries now go into a ring buffer in the resident process,
bounded by entry count and by bytes (100,000 and 64 MiB; `--buffer-entries`
and `--buffer-mb` change them). Unfiltered over Wi-Fi the phone sent about
4,800 entries/s at 290 B of JSON each, so the default holds about 20 s of
that worst case, and minutes of a filtered capture. Such an entry weighs
about 430 B in memory, so 100,000 of them take about 41 MiB; the byte
limit binds when messages run long. Each kept entry gets a `seq`, 1 for
the first, so the ring is a gap-free run of seqs and a seq finds its
entry by position.
`read [--after SEQ] [--grep RE] [--max N]` (CLI, MCP `iph_syslog`,
script `syslog("read", opts)`) returns the matching entries newer than
`after`, oldest first, without stopping the capture. The result has a
`cursor`: the last entry returned when `max` cut the page short, the
newest seq when the whole buffer was looked through, so a grep that
matches nothing still advances and a loop neither repeats nor skips an
entry still in the buffer. `more` says a further match is already
waiting, `dropped` how many entries newer than `after` were evicted
before the read. A cursor is only meaningful in the capture that issued
it: seqs start again at 1 with each capture, so after a new `start` a
read goes without `after`. One that runs ahead of the buffer's newest
seq is pulled back to it. A capture that ended can still be read until
it is stopped; until then a new `start` fails with `capture_ended`
rather than discard it.
`stop --grep/--max` returns the latest matches from the buffer, as
`entries` like `read` does; the file is no longer parsed back. `-o <file>`
now only adds a JSON Lines file with whole messages and `--max-mb`
rotation; without it nothing is written to disk, and `--max-mb` without
`-o` is `invalid_argument`. `status` reports the buffer under `buffer`.
`--human` prints counts, a page and a stop's matches.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
An app's executable name is not something a person or an agent knows
(Settings is `Preferences`), so `--process` meant a first capture just to
look it up. `--app <bundle id | name>` takes what `iph launch` takes: the
name is resolved with the same `resolve_bundle`, then looked up in the
phone's app list (refreshed once when the cached list lacks it) for the
bundle's path. An entry is kept when the path of the executable that
logged it, normalized as the app list's path is (`plain_path`: file URL,
percent escapes, trailing slash, `/private/var` against `/var`), lies
inside that bundle, so the app's extensions are included and the filter
survives a restart of the app. An unknown or ambiguous app, or one the
phone gave no path for, is a `not_sent` error before the capture slot,
the file or the relay is touched.
`--app` and `--process` each select: an entry is kept if it is from any
listed app or process, and `--level` applies on top; `--pid` is filtered
by the phone, so it narrows what either can match. The check runs on the
raw executable path before the entry is built, so the buffer keeps only
the file name.
CLI `--app` (repeatable), MCP `iph_syslog` `app`, script `syslog("start",
{app})`; `status` and the file's `start` line report the bundle ids.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the careful review. I agreed with all of it and kept iterating on this branch, rebased onto the latest 1. Memory buffer and 2. 3. Details.
About the RST. A review pass found that the relay could still be closed with a FIN: when a start failed after connecting, when a capture ended on its own, and when a tunnel reset dropped everything before the separate The new CI passes on macOS and Windows, including the rotation test that renames over an existing Separately, the slow taps I saw while measuring (about 8 to 10 s instead of about 3 s) each waited on one screen reading the phone never answered, which iph asks again after 6.5 s. That happens on I kept it as one PR, since the RST change has no caller without |
|
Thanks for the awesome follow-up! The ring buffer + Keeping it all in this single PR is totally fine by us, and yes, opening a separate issue with the trace for that 6.5 s AX timeout on Before we merge, we caught one practical edge case with
Once that's in, this is ready to merge! |
The daemon caches the phone's app list, and `--app` read both the name and the bundle path from that cache, refreshing only when a bundle id was missing from it. Two cases slipped through: - An app reinstalled while the daemon runs (a rebuild from Xcode) moves to a new `/var/containers/Bundle/Application/<UUID>/`. Its bundle id is still in the cached list, so the old path was used, the capture started, and every entry was dropped (`kept: 0`). - An app installed since, named by display name, was looked up in the cached list and failed with `app_not_found` before the refresh. A start with `--app` now fetches the list once and resolves every name and every bundle path from that one snapshot. The name lookup moved out of `resolve_bundle` into `bundle_id_in`, which takes the list, so both `launch` (still on the cached list) and `syslog` share it. A start without `--app` does not fetch the list at all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, good catch. Fixed in a new commit on top. A start with I'll open the issue for the 6.5 s AX timeout separately. |
HyunSeob
left a comment
There was a problem hiding this comment.
Clean fix — thanks again for the thoughtful iteration, thorough tests, and real-device verification! Looking forward to the 6.5 s AX timeout issue as well. Merging now!
Why
To check what an app logged after a tap, a real-device test needs the phone's log while the test keeps running. Today the only route is
log collect --device-udidon macOS, which requires root. The pinned idevice 0.1.68 reads the structured log through RSD (com.apple.os_trace_relay.shim.remote), so the daemon now captures it in the background.What changed
iph syslog start|read|status|stop, also as MCPiph_syslogand scriptsyslog(action, opts). The daemon's session holds one capture. A background task reads the stream without taking the session lock, so taps, reads and scripts keep working.read [--after SEQ] [--grep RE] [--max N]returns newer entries with acursor,moreanddropped, without stopping the capture.stop --grepreads the same buffer.-o <file>with--max-mbrotation is opt-in.--app <bundle id | name>(inside the app's bundle, survives restarts),--process NAME,--pid N(filtered on the phone) and--level.StreamHandle::reset_on_drop()insrc/tcpmakes a stream send exactly one RST, early or on drop, and never a FIN.Scope
stop.Blast Radius
Enabling idevice's
syslog_relayfeature addschrono,num-traitsandautocfgto Cargo.lock. Thesrc/tcpchange adds an opt-in reset on drop; other connections still close with a FIN. Nothing new runs unlesssyslogis used.Verification
cargo test --locked: 230 passed, including tests for the reset on drop (one RST, no FIN), the ring buffer cursor and eviction,--apppath matching (/private/varagainst/var), rotating twice over an existing.1, and--human. Clippy: no new warning.--app com.apple.Preferenceskept only Settings entries, and a secondread --after <cursor>returned only newer ones.--app com.naver.papagokept entries from two pids across a restart.--max 3returned the same 47 entries as one unbounded read, with no repeat and no gap.iph stopthen start, 3 times: entries arrived within 0.1 s each time. After a forced script timeout that drops the tunnel, the next capture recovered in 0.1 to 0.4 s (30 s with a FIN).-olines landed within one flush, theendline was present afterstopand afteriph stop, and--max-mb 1rotated 14 times with both files parsing.--pid, 13 taps). Unfiltered volume does slow screen reads over Wi-Fi (1.0 s to 2.3 s at about 9,000 entries/s), so the README recommends--pidthere.🤖 Generated with Claude Code