Repository navigation
perf(remote): opt-in gzip/ETag and progress resume cursor - #330
Conversation
A reconnect that presents a cursor this process issued to the same device and chat now resumes without resending task and agent snapshots it already received. Unknown cursors keep the full-snapshot hydration, so current clients (which always reconnect at zero) see no change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Successful GET JSON responses now carry a weak ETag and Vary, answer a matching If-None-Match with a body-less 304, and stream gzip when the client accepts it and the body is at least 1 KiB. Both are opt-in: requests without those headers, or that pin identity (peer transport), get the unchanged identity body. Errors and non-GET responses are untouched. No protocol revision change; URLSession and OkHttp decode gzip transparently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…32, EXT-33) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Important
The opt-in resume path can mistake a pre-restart cursor for a new connection's cursor and suppress changed progress snapshots. This should be fixed before clients start using nonzero cursors.
Reviewed changes across the Remote JSON response writer, progress subscription service, their tests, and the implementation memory note.
- JSON transport: Successful GET responses gain weak ETags, conditional 304 responses, and negotiated streaming gzip above the size threshold while preserving identity responses and decoded-size limits.
- Progress resume: A bounded device/chat-scoped cursor cache restores previously sent revisions to avoid resending unchanged task and agent projections, with revocation and shutdown cleanup.
- Coverage and compatibility: New HTTP negotiation and progress reconnect tests exercise the opt-in paths; existing native gzip readers and identity-only peer transport were checked.
Validation: 85 focused server tests, 19 peer tests, 29 Android remote-client tests, and root TypeScript checking passed. iOS runtime tests were not run because this runner is Linux. The restart collision was reproduced against the real progress service.
ℹ️ Nitpicks
- The progress contract in
docs/aiden-remote-api-v1.mdandopenapi.jsonstill promises current snapshots on every connection regardless ofafter. Update those descriptions to distinguish recognized resume cursors from full-hydration fallback.
gpt-6.1-sol | 𝕏
| const resumed = after > 0 ? this.cursors.get(after) : undefined; | ||
| const sent = new Map<string, number>( | ||
| resumed?.deviceId === deviceId && resumed.chatId === chatId | ||
| ? resumed.sent | ||
| : [], |
There was a problem hiding this comment.
[P2] Distinguish resume cursors across host restarts
The lookup treats a numeric cursor as belonging to the current process whenever its device/chat match, but sequence starts at zero on every restart. I reproduced an old connection retaining cursor 2 with a pending task, a new connection for the same device/chat receiving cursor 2 with a completed task after restart, and the old connection then resuming to zero frames because it inherits the new connection's revisions. This leaves the resuming client with stale progress and no snapshot conveying the changed epoch, contrary to the stated restart fallback.
Technical details
# Restart-safe progress cursor identity
## Affected sites
- `main/services/aiden-remote-chat-progress.ts:433-438`: numeric cache hits are accepted using only device and chat identity.
- `main/services/aiden-remote-chat-progress.ts:73,457,468`: the event sequence restarts at zero and reused values populate the new cache.
- `main/services/aiden-remote-chat-progress.test.ts:427-465`: coverage exercises same-process resume but not a stale cursor colliding with a newly issued cursor after restart.
## Reproduction
1. Host A opens a stream with both grants for `device-1` / `chat-1`, sending a pending task and empty roster; the client retains cursor 2.
2. Restart into host B with the task now completed.
3. Another connection for the same device/chat opens with `after=0`, receives the new projections at sequences 1 and 2, then closes.
4. The old connection reconnects to B with `after=2` and receives no projections, although its previously received task and epoch differ.
Both service instances were exercised directly with real snapshot methods; the reproduced outcome was oldStatus=pending, restartedStatus=completed, epochsDiffer=true, reconnectFrames=0.
## Required outcome
- A cursor issued in a previous host epoch must never seed dedupe from an unrelated current-epoch connection, even when its numeric value, device, and chat match.
- Preserve safe full hydration when resume provenance cannot be established, and retain unchanged-snapshot suppression for valid same-epoch resumes.
- Extend the existing behavioral reconnect suite to exercise this restart collision, not just an unknown cursor against an empty cache.
Summary
aftercursor.If-None-Matchor a nonzeroafteryet; that is the next step.Test plan
Part of the October optimization pass. Finding IDs refer to
docs/performance/optimization-audit-2026-10-03.md(#320). The branch's.memory/note has per-finding rationale.🤖 Generated with Claude Code