Repository navigation
Description
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
atomicwrites with file and directory fsync, thensyncTree(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
- The daily scan marker and native-observation storage (delivered under tests: attribute recurring one-second native hosted health timeouts #2416).
- App-connection SQLite writers (Epic: nothing on the hosted server's event loop waits for a ui.db fsync #2850) and Pi transcript or native-output writes (ui-server: native lease, pi transcript and native output writes block the hosted event loop under write load #2807).
- Changing the 30-day idle threshold, the daily cadence or any durability level.
- Raising
HOSTED_ADMISSION_HEALTH_WITHIN_1_SECOND.
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.tscrash-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
schlessera commentedon Oct 25, 2026
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.schlessera commentedon Nov 3, 2026
Claiming (claim token
wi-2898-d9f76fd3), branchfix/2898-archive-move-asyncfrom mainadf371ffa. Collision report for the cited files: path overlap with #3484 (history.ts) and #3490 (worker-spawn.ts); this change stays insidetranscript-archive.tsand its tests so it touches neither. Citation drift: anchors moved by #3229's retired-session fence; currentatomic69-77,syncTree52-58,setAside137-142,restoreArchivedSession157-185,removeSource208-224,archiveIdleSessions229-286; the callers athistory.ts:84andworker-spawn.ts:77are unchanged.schlessera commentedon Nov 3, 2026
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.fix(backend-claude): wait on the idle-session archive move's fsyncs o…