Skip to content

perf(remote): opt-in gzip/ETag and progress resume cursor - #330

Merged
sambitcreate merged 4 commits into
mainfrom
perf/remote-server
Oct 4, 2026
Merged

sambitcreate merged 4 commits into
mainfrom
perf/remote-server

Conversation

@sambitcreate

Copy link
Copy Markdown
Owner

Summary

  • Compression (EXT-32): opt-in gzip plus ETag/304 revalidation for Remote JSON reads.
  • Resume cursor (EXT-33): the progress stream honours its after cursor.
  • Compatibility: no protocol revision bump, since both features are opt-in for clients. iOS and Android don't send If-None-Match or a nonzero after yet; that is the next step.

Test plan

  • The Remote server suites, including the progress-cursor test.
  • Type-check.

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

sambitcreate and others added 4 commits October 3, 2026 16:07
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>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.md and openapi.json still promises current snapshots on every connection regardless of after. Update those descriptions to distinguish recognized resume cursors from full-hydration fallback.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment on lines +433 to +437
const resumed = after > 0 ? this.cursors.get(after) : undefined;
const sent = new Map<string, number>(
resumed?.deviceId === deviceId && resumed.chatId === chatId
? resumed.sent
: [],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@sambitcreate
sambitcreate merged commit 003d97c into main Oct 4, 2026
22 checks passed
@sambitcreate
sambitcreate deleted the perf/remote-server branch October 4, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant