feat(logserver): replay log tail to clients on connect#7
Merged
Conversation
When a client connects to the TCP log server, it now receives the last IPA_LOG_REPLAY_BYTES (default 100 KB) of the sandbox log file before switching to the live stream. This avoids the race where logs written at process startup — including login-time crashes — are lost because no nc session was open yet. Implementation: - ls_replay_to(fd): opens the log file, seeks to max(0, size - 100KB), skips to the next newline to avoid a partial first line, then streams the remainder synchronously before the client is admitted to g_clients[]. - IPALogServerSetReplayPath(NSString *): dispatched onto g_queue so g_replayPath access stays single-threaded. - IPALoggingInit() calls IPALogServerSetReplayPath(g_logSandbox) once the path is finalised (after IPALogServerStart, before first IPALog). - Knob: -D IPA_LOG_REPLAY_BYTES=N to override at build time. - No change to FINAL_RELEASE builds (replay code compiled out with the rest of logserver). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a debug-only “replay-on-connect” feature to the TCP log server so new clients receive recent log history (tail of the sandbox log file) before switching to live streaming.
Changes:
- Implement log tail replay (default 100 KB, newline-aligned) for newly connected logserver clients.
- Add
IPALogServerSetReplayPath(NSString *)API and wire it fromIPALoggingInit()after the sandbox log path is finalized. - Introduce build-time knob
IPA_LOG_REPLAY_BYTESto control replay size.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| logserver.m | Adds replay-on-connect implementation and stores a replay file path used by new clients. |
| logserver.h | Exposes IPALogServerSetReplayPath() in the debug-only logserver API. |
| logging.m | Registers the sandbox log file path with the log server for replay in non-release builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+131
to
+136
| while (rem > 0) { | ||
| ssize_t sent = send(fd, p, rem, 0); | ||
| if (sent <= 0) { close(fileFd); return; } | ||
| p += sent; | ||
| rem -= (size_t)sent; | ||
| } |
Comment on lines
+152
to
155
| // Replay history before admitting to the live stream so the client sees | ||
| // events that happened before it connected. | ||
| ls_replay_to(fd); | ||
| g_clients[g_clientCount++] = fd; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When a client connects to the TCP log server (
nc <device-ip> 18082), it now receives the last 100 KB of the sandbox log file before the live stream begins.Why
Without this, any
ncsession started after launch misses all prior log output — including login-time crashes and boot-sequence messages. The race was especially painful on Chinlan where AirDrop was the only fallback.How
ls_replay_to(fd)— seeks tomax(0, fileSize - IPA_LOG_REPLAY_BYTES), skips to the next newline (no partial first line), then streams the rest synchronously before the fd is added tog_clients[]IPALogServerSetReplayPath(NSString *)— dispatched ontog_queuesog_replayPathis always touched on the serial queueIPALoggingInit()callsIPALogServerSetReplayPath(g_logSandbox)right after the path is finalised-D IPA_LOG_REPLAY_BYTES=N(default 102400)FINAL_RELEASEbuilds — replay code is inside#ifndef FINAL_RELEASETest plan
nc <device-ip> 18082immediately after launch → should see boot log linesnc <device-ip> 18082while the app is mid-session → should see ~100 KB of history then live outputFINAL_RELEASE=1build → logserver.m compiles to nothing (existing behaviour)🤖 Generated with Claude Code