perf(desktop): batch session telemetry checkpoints - #7916
Open
Nath-Vikky wants to merge 1 commit into
Open
Conversation
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.
Summary
Desktop session telemetry currently rewrites the complete
.telemetry.jsonsidecar after:TurnStartedUsageeventread_fileTurnDoneEach save serializes the full, growing snapshot with
json.MarshalIndent, writes a temporary file, and atomically replaces the sidecar. Read-heavy turns therefore perform many synchronous full-file rewrites inside the serialized frontend event path.This change replaces per-event persistence with bounded synchronous checkpoints:
TurnStartedupdates in-memory timing without writing the sidecar.Usageand successfulread_filemutations checkpoint every 16 events.Usageorread_filemutation arrives; no background timer is created.TurnDonealways forces a synchronous checkpoint.Usage/read_filemutation or forced boundary.The sidecar path, JSON v2 format, and existing
tmp + ReplaceFileatomic-write behavior are unchanged. No background writer or goroutine is introduced.Results
Representative workload: 9
Usageevents and 8 successfulread_fileevents per turn.The Windows comparison used the real
saveTelemetryfilesystem path, alternated execution order between runs, and verified that the final before/after snapshots were identical.This is an isolated persistence-path stress workload, not an end-to-end Agent speedup claim. The change substantially reduces in-turn write amplification, but
TurnDonestill writes the full snapshot, so lifetime persistence is not fully linearized.Durability and compatibility
With healthy filesystem I/O, completed turns and graceful shutdowns remain fully checkpointed.
An abrupt process kill may lose at most one checkpoint window—conservatively up to 16 intermediate
Usage/read_filemutations plus elapsed time since the last checkpoint. This affects only the private Desktop telemetry sidecar; the session transcript and tool results are persisted through their existing paths.Persistent filesystem failures still cannot provide a finite durability guarantee, matching the existing best-effort error behavior.
The change is Desktop-only and provider-independent. It does not affect CLI/serve, provider requests, prompts, tools, session JSONL, or user-visible telemetry fields.
Issues
N/A — independently identified while profiling the Desktop telemetry persistence path.
Verification
cd desktop && go test . -run 'Test(TelemetryCheckpoint|TabEventSinkTelemetryCheckpoint|Shutdown.*Telemetry)' -count=50recordUsageTelemetry/recordReadTelemetry/TurnDone→saveTelemetry→loadTelemetryround-tripgo test ./internal/control -count=1go test ./internal/event -count=1go test ./internal/boot -run TestBuildCoalescesAgentStreamDeltas -count=1cd desktop && go vet .go run ./tools/repolintgofmtandgit diff --checkThe full Desktop suite produced only two pre-existing Windows environment-dependent failures (
TestRemoteWindowRecoversAcrossRealSSHDropandTestTrySubagentProfileCancelAbortsRunAndIsSingleFlight); no telemetry or lifecycle test failed.Local
-racewas unavailable because the Windows Go environment has no CGO compiler. The repository Desktop CI runs the full race suite.Documentation impact
Documentation-impact: none - changes only the persistence cadence of a private Desktop telemetry sidecar; no command, setting, user-visible behavior, or file format changes.
Cache impact
Cache-impact: none - no provider request, prompt, tool schema, serialization, or cache-prefix behavior changes.
Cache-guard: N/A - Desktop sidecar persistence only; focused checkpoint and lifecycle tests cover the changed path.
System-prompt-review: N/A