Skip to content

ui-backend-claude: the transcript archive move and restore still fsync on the hosted event loop #2898

Closed

Description

@schlessera

Context

#2416's re-measurement on main 2d21e915f attributed a 856 ms hosted event-loop window, with an 842 ms /health probe, in the native Claude UID 0 cell under three dd … conv=fsync writers. Two synchronous fsyncs of 327 ms each caused it. One was the daily scan marker's directory fsync (atomic(marker, String(now)), packages/ui-backend-claude/src/transcript-archive.ts:195). Merged #2901 (1794e7200, ancestor of inspected main) moves that marker write and the native-observation saves off the event loop. The idle-session archive and restore paths below remain synchronous.

The rest of the archive work still runs synchronously on the hosted server's event loop. It runs whenever a session has been idle for at least 30 days, at most once a day per archive:

  • the per-session move: gzip, SHA-256 and atomic writes with file and directory fsync, then syncTree (export async function archiveIdleSessions, packages/ui-backend-claude/src/transcript-archive.ts:188-242, loop at lines 209-237; function atomic, lines 57-65; function syncTree, lines 40-46);
  • source removal, which hashes every live file and fsyncs each parent directory (function removeSource, lines 169-185);
  • the conflict set-aside and reindex (function setAside, lines 99-104);
  • the restore of an archived session, documented as synchronous on purpose ("no turn can start or archive between validation and publication", export function restoreArchivedSession, lines 117-146). It is called from history reads (packages/ui-backend-claude/src/history.ts:84) and the worker spawn (packages/ui-backend-claude/src/worker-spawn.ts:76).

The fixture has no 30-day idle sessions, so none of these ran in the measurement. That is why they are not part of the #2416 PR. Each one is the same pattern that the measurement showed taking 327 ms per fsync under write load, multiplied by the number of files in each archived session.

Line numbers above are on 2d21e915f; the #2416 PR shifts this file by about 27 lines.

Current source

Historical line numbers above refer to 2d21e915f. Current anchors: atomic (packages/ui-backend-claude/src/transcript-archive.ts:58-66), syncTree (same file:41-47), setAside (126-131), restoreArchivedSession (146-173), removeSource (196-212), and archiveIdleSessions (217-274; synchronous move at 253-267). The daily marker uses atomicAsync at 227, outside this follow-up. Restore callers remain history reads (packages/ui-backend-claude/src/history.ts:84) and worker-state reservation (packages/ui-backend-claude/src/worker-spawn.ts:76).

Scope

Attribute, then move off the event loop only the archive and restore operations that are shown to block. Each one waits on the file system asynchronously, with unchanged order, validation and durability: file and directory fsync, atomic replacement and verification before deletion. Restore's guarantee that no turn starts or archives between validation and publication must hold. Either keep it synchronous and record why, or replace it with an in-process exclusion that the turn start and the archive both honour.

Out of scope

Acceptance criteria

  • For each path moved asynchronously, a fixture with delayed file/directory sync demonstrates a live event-loop heartbeat and no synchronous fsync on that moved path, failing before the change. Archive and restore are reported separately. If restore must remain synchronous to preserve the proved exclusion, retain it explicitly as the scoped residual with a reason; do not claim an all-path nonblocking result.
  • Before the change, a test proves the restore's validation-to-publication exclusion against a concurrent turn start and a concurrent sweep. It still passes after the change, or the restore stays synchronous with the reason recorded here.
  • The existing packages/ui-backend-claude/tests/transcript-archive*.test.ts crash-interruption, conflict and recovery cases pass unchanged.

Verification

bun run test packages/ui-backend-claude, plus the #2416 timer-drift and fsync method on a fixture brain seeded with a session older than 30 days.

Contract impact

None.

2026-10-25 triage at main ab746a434c4ada11734ffea4e208d1d6211f1aca: Verified the marker-only #2901 delivery, added current archive/restore anchors and reconciled the acceptance contradiction: heartbeat/no-sync proof applies to moved paths, while synchronous restore is permitted only as an explicit justified residual. Correctness, durability and start/archive exclusion remain binding. The bounded attribution/guard-preserving repair brief is complete; no unmeasured idle-session stall is claimed.

Activity

  1. added
    type: fix
    area: backends
    priority: p2
    on Oct 25, 2026
  2. added this to the 0.45.0 milestone on Oct 25, 2026
  3. added
    agent-ready
    on Oct 25, 2026
  4. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    2026-10-25 triage at main ab746a434c4ada11734ffea4e208d1d6211f1aca: Verified the marker-only #2901 delivery, added current archive/restore anchors and reconciled the acceptance contradiction: heartbeat/no-sync proof applies to moved paths, while synchronous restore is permitted only as an explicit justified residual. Correctness, durability and start/archive exclusion remain binding. The bounded attribution/guard-preserving repair brief is complete; no unmeasured idle-session stall is claimed.

  5. self-assigned this
    on Nov 3, 2026
  6. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claiming (claim token wi-2898-d9f76fd3), branch fix/2898-archive-move-async from main adf371ffa. Collision report for the cited files: path overlap with #3484 (history.ts) and #3490 (worker-spawn.ts); this change stays inside transcript-archive.ts and its tests so it touches neither. Citation drift: anchors moved by #3229's retired-session fence; current atomic 69-77, syncTree 52-58, setAside 137-142, restoreArchivedSession 157-185, removeSource 208-224, archiveIdleSessions 229-286; the callers at history.ts:84 and worker-spawn.ts:77 are unchanged.

  7. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Draft PR #3495 (head dd9e06a39): the idle-session move, source removal, set-aside and reindex now await their fsyncs off the event loop. Restore stays synchronous as the scoped residual, with the reason recorded in the PR. Failing-first and six mutation receipts are in the PR. Remaining: hosted CI (including the namespace-dependent tests that can't run locally), then readiness and merge. The claim stays while the PR is live.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: backendspriority: p2type: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions