Skip to content

backends: restoring an archived Claude transcript stamps it as active now, so month-old chats jump to the top of the list #3790

Closed

Description

@schlessera

Context

Restoring an archived Claude transcript stamps it with the restore time. Its lastActiveAt jumps to "now", and a month-old chat moves to the top of the session list.

  • archiveIdleSessions (packages/ui-backend-claude/src/transcript-archive.ts:262-322) moves a session whose newest file is older than 30 days (:292) into the archive.
  • restoreArchivedSession (transcript-archive.ts:180-207) writes the files back and then calls utimesSync(target, now, now) (:203).
  • listSessions takes lastActiveAt from the live file's lastModified (packages/ui-backend-claude/src/history.ts:71), and GET /api/sessions sorts on it (packages/ui-server/src/routes/sessions.ts:115).
  • Restores run on reads, not only on resumes. getHistory restores before it reads (history.ts:95), as does a resume (packages/ui-backend-claude/src/worker-spawn.ts:78). The archive sweep also completes interrupted restores (transcript-archive.ts:279-280).

Observed on a hosted 0.44.0 install. In GET /api/sessions, 13 sessions created between 2026-10-03 and 2026-10-08 report lastActiveAt values clustered within a second of each other: three at 2026-11-06T15:57, eight at 2026-11-07T15:57 and two at 2026-11-08T17:57. Each cluster falls about 30 days after those sessions were last used, at the same minute of the day (the archive sweep runs at most daily), and no turn ran in them. They now sort above chats the user really worked in that week. A restored chat nobody touches also waits another 30 days before it is archived again.

The utimesSync(now) restore is the only code path found that stamps a transcript with an arbitrary current time. What triggered the restores within the same second as the sweep was not identified: a history read right after the move, or the sweep's own restore branch. Finding it is part of this issue.

Scope

  • Restore a transcript with its original modification time. Use the manifest's lastActiveAt, or the newest original mtime if the PR records it, instead of now.
  • Keep a resumed turn's own writes as the real activity signal: the CLI's next append updates the mtime naturally.
  • Find what restores sessions right after a sweep archives them: a history read by the server (labelling, a list prefetch, recovery) or the sweep itself. Stop that restore if nothing needs it. The PR names the caller.

Out of scope

Acceptance criteria

  • Restoring an archived session through getHistory leaves its listed lastActiveAt equal to its pre-archive value. An archive test with an injected clock proves it and fails before the change.
  • A resumed turn that appends to a restored transcript makes lastActiveAt advance to that append.
  • A restored session that receives no new turn is archived again by the next sweep after the threshold. It does not wait another 30 days from the restore.

Verification

  • bun run test packages/ui-backend-claude/tests (transcript-archive cases). The existing idle sessions move to gzip with SDK metadata and round-trip byte-identically test (packages/ui-backend-claude/tests/transcript-archive.test.ts:37-56) currently pins the restore mtime to now; update that obsolete assertion alongside the new activity-time regression. Preserve its byte-identity, recovery and ownership checks.
  • Mutation: put the utimesSync(now) back, and the first criterion's test fails.

Contract impact

None. ChatSession.lastActiveAt keeps its meaning, the last real activity, which the restore currently violates.

Bounded reproduction — 2026-11-09

Inspected source: 9c7eb25825fdad5f4485db0df472188805edb450; Bun 1.4.4 (38afee6c8), frozen lockfile, isolated temporary checkout, repository test wrapper and offline preload. Command: bun run test ./tmp/triage/new-issues.test.ts. A temporary keyless fixture wrote a fictional transcript at a 31-day-old mtime, archived it with real archiveIdleSessions, then called real restoreArchivedSession with an injected 2026-07-12T12:00:00Z clock. Expected mtime 1781179200000; actual 1783857600000, exactly the restore clock. RESTORE_RETAINS_ACTIVITY_TIME failed at that comparison. This reproduces the timestamp defect; it does not identify the historical same-second restore caller. The fixture failed at the named behavioral assertion, after module loading succeeded. Temporary diagnostic fixtures are outside authored source; this triage changes no product code.

Triage 2026-11-09 at main 9c7eb25825fdad5f4485db0df472188805edb450: Recorded the bounded intended-assertion failure and clarified current source/verification. The existing p1 and 0.45.0 commitment are preserved. It remains standalone: the GitHub-tools epic does not own this backend correction, and no existing open epic owns its full deliverable.

Activity

  1. added
    type: fix
    area: backends
    priority: p1
    on Nov 9, 2026
  2. added this to the 0.45.0 milestone on Nov 9, 2026
  3. added
    agent-ready
    on Nov 9, 2026
  4. self-assigned this
    on Nov 15, 2026
  5. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Claimed for implementation. Claim token: claim-0e515a43. Branch: fix/3790-restore-activity-time.

    Related Claude title work #3789 is concurrent; archive timestamp scope is separate.

  6. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Collision review found direct overlap with #4022 for #3789 in history.ts, transcript-archive.ts and transcript-archive.test.ts, plus shared affected-test closures with other open work. This change preserves activity timestamps and archive eligibility; title extraction remains with #3789.

  7. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Completed in #4023, squash 4035f977e0cc471a5fbe795f447237c15890d3dd, verified present on main with the exact tested candidate tree. Restore preserves the original activity timestamp, a real append advances it, and an untouched restored session is eligible for the next daily sweep. A bounded scratch-pin refresh reproduction identifies the background restore caller and proves its artifact-retention purpose.

    Proof: 18 archive tests pass; the original timestamp mutation and directory-mtime mutation fail their intended regressions. Local check:pr and complete selected hosted candidate proof passed in run 43736220100. The automatic main run 43738678603 is complete: all runtime/native-host, browser, layout, captures, endurance, types and packaging categories passed; unit shards 1, 2 and 4 passed. Unit shard 3 hit the existing intermittent Apify leading-dash reference failure #3689, so aggregate main proof is failed, not green. Evidence is posted on that existing unscheduled issue; no job was rerun, gate weakened or unrelated fix attempted. Local native-host comparison evidence is on existing #4005. No new follow-up issue was needed.

    All candidate and main job checkout logs were checked against their actual candidate/squash identities. PR and issue retain milestone 0.45.0, this issue is closed, and no blocked dependants were found. Main-status had no open incident record at the final inspection; any automatic incident coordination remains with the repository coordinator. No #3790 work remains open.

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: p1type: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions