Skip to content

fix(backends): preserve archived Claude activity on restore - #4023

Merged
schlessera merged 3 commits into
mainfrom
fix/3790-restore-activity-time
Nov 15, 2026
Merged

schlessera merged 3 commits into
mainfrom
fix/3790-restore-activity-time

Conversation

@schlessera

Copy link
Copy Markdown
Owner

Closes #3790

What changed

Restoring archived Claude transcripts retains the manifest's original lastActiveAt on files and subordinate directories. History reads keep the original session-list position, a resumed CLI append advances activity normally, and a history-only restore remains eligible for the next daily archive sweep. Archive bytes, ownership checks and crash recovery remain intact.

Why this shape

The existing manifest already carries the activity timestamp, so no archive-format or public-contract change is needed. Directories also need their timestamps reset after file publication because the idle scan includes them.

Caller investigation: openScratchPins().refresh in packages/ui-server/src/cron/scratch-pins.ts enumerates every backend session and calls backend.getHistory before pruning, including archived sessions. startScratchPrune invokes this at boot and hourly. These reads need transcript content to preserve referenced scratch files, so suppressing them would compromise retention. Lists and labels do not restore by themselves; the archive sweep restores only entries already marked restoring after an interrupted restore. This identifies a source-backed background restore path; historical production traces are unavailable to prove which invocation produced each reported cluster.

Proof

  • Failing first: archive tests reported 15 pass / 3 fail; original activity expected 1781179200000, while restore stamped the current clock. RESTORE_RETAINS_ACTIVITY_TIME and RESTORE_DOES_NOT_RESET_IDLE_THRESHOLD failed at their intended assertions.
  • Restoring utimesSync(now) produced the same 3 failures; retaining fresh directory mtimes produced 2 archive-eligibility failures. Both mutations were restored.
  • Focused archive coverage: 18 pass / 0 fail, proving history read/list stability under an injected restore clock, real append activity, next-sweep eligibility, byte identity, ownership and crash recovery.
  • Complete backend suite: changed tree 809 pass / 8 skip / 51 fail / 1 error; base control 807 pass / 8 skip / 51 fail / 1 error, with exactly the same failing-test names. Local worker-host prerequisites refuse native fixtures; comparison evidence is recorded on test: offline runtime placement probe exits before producing its receipt #4005. The separate provider-history guard also stops at its native child exit assertion locally; it is not claimed passing. Hosted proof is authoritative.
  • One patch changeset names @schlessera/brain-backend-claude; pending changeset validation and the full lockstep release plan pass.
  • Provider-facing history, tools and prompts are unchanged. No guard or contract surface changes.
{"version":1,"kind":"brain-check-pr-receipt","head":"fbfb1dc8f23afb5ba4ae01d0252c3413020a83a1","base":"origin/main","mode":"focused","startedAt":"2026-11-15T15:50:07.711Z","finishedAt":"2026-11-15T15:50:49.661Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12372.169945},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":100.98609900000156},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":68.31482599999799},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":17.297013999999763},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":29375.814050999998}]}

Checklist

  • Focused behavioral and restored-mutation receipts pass; selected hosted proof is required by the integration command before merge.
  • Acceptance criteria are covered.
  • PR and issue target milestone 0.45.0.
  • Consumer-facing changeset included.
  • Leakage and integration-contract boundaries preserved.
  • Backend documentation and moved archive citations updated.
  • No fail-closed guard or provider-facing conversation changes.

Anything left open

No issue-scope work. Existing local native-runtime environment failures are reported separately from archive proof and require hosted verification.

@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: backends AgentBackend implementations and the seam they share. labels Nov 15, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Collision review for head fbfb1dc8f23afb5ba4ae01d0252c3413020a83a1 (bun scripts/collisions.ts --json --pr 4023):

The current report has no direct path collision. Related #4022 changes Claude title extraction; this PR changes restore timestamps. All other work stays outside this scope.

@schlessera

Copy link
Copy Markdown
Owner Author

Bounded caller reproduction: a temporary offline fixture connected real createScratchPins().refresh to real Claude createHistory, archived a fictional transcript with archiveIdleSessions, and ran pin refresh. It passed 1 test / 5 assertions: the transcript was cold before refresh, was restored by refresh, the archive entry was removed, and the ready pin snapshot retained .brain/scratch/voyage.md. No turn or history route was invoked. The fixture lives outside authored source and changes no product code. This proves the scratch-prune pin scan is a background restore caller and needs history content for artifact retention; it does not attribute individual historical restore clusters.

@schlessera

Copy link
Copy Markdown
Owner Author

Refreshed candidate head ac86f4388d49db9155bd5663c173202196fef125 merges main 7e36fdc89 after #4013. The base added only CI-reporting/coordinator files and their tests; none overlap this PR. The original local receipt remains evidence for head fbfb1dc8f23afb5ba4ae01d0252c3413020a83a1; fresh hosted confirmation will prove the combined candidate.

Refreshed collision scan: closure with #3056; closure with #3059; closure with #3069; closure with #3116; closure with #3437; closure with #3581; closure with #3622; closure with #3806; closure with #4002; closure with #4008; closure with #4012; textual with #4018; closure with #4021; closure with #4022.

@schlessera

Copy link
Copy Markdown
Owner Author

Refreshed candidate head db1a6bcfebf6c64ffc87429b5a2d249439917762 merges main 388feb483 after #4012. Main added native-observation instrumentation with no file overlap with this PR. The original local receipt retains its recorded head; fresh hosted confirmation will prove the combined tree. Main-status reports no open red-main record.

Current collision scan: closure with #3056; closure with #3059; closure with #3069; closure with #3116; closure with #3437; closure with #3581; closure with #3622; closure with #3806; closure with #4002; closure with #4008; textual with #4018; closure with #4021; closure with #4022.

@schlessera
schlessera marked this pull request as ready for review November 15, 2026 16:34
@schlessera

Copy link
Copy Markdown
Owner Author

Candidate checkout evidence for confirmation run 43736220100, attempt 1:

  • Passed metadata job 132879317883, verify job 132879701831, and pack job 132879701956 each log actual checkout 14e00ca85757a082f5a0aa44bca1796a4173498e.
  • Immutable API and fetched Git object agree on parents 388feb483751e8a7550f908de6f0a518eda03117 db1a6bcfebf6c64ffc87429b5a2d249439917762 and tree 89763d146e8386fd8bc9ee6030ab2c9d345a65e8. Metadata's BASE_SHA is that same base.
  • The four selected unit shards are still running at this inspection. Heavy-category skips are intentional for PR confirmation under the hybrid main-run policy. This is partial proof evidence, not a completed-candidate claim; the integration command retains the reservation and checks the complete candidate before squash.

@schlessera
schlessera merged commit 4035f97 into main Nov 15, 2026
39 of 50 checks passed
@schlessera

Copy link
Copy Markdown
Owner Author

Merged as 4035f977e0cc471a5fbe795f447237c15890d3dd after confirmation run 43736220100, attempt 1, passed every selected fast category. Unit jobs 132879701959 / 132879701861 / 132879701892 / 132879701865 all passed and their checkout logs each name 14e00ca85757a082f5a0aa44bca1796a4173498e.

Fetched squash identity: parent 388feb483751e8a7550f908de6f0a518eda03117, tree 89763d146e8386fd8bc9ee6030ab2c9d345a65e8. These equal the independently verified candidate base and tree. The squash is an ancestor of fetched main. Issue #3790 is closed, and both issue and PR retain milestone 0.45.0. No review findings remain.

Automatic main push run 43738678603 is now running on the squash; its heavy proof is pending and is not yet claimed passing.

@schlessera

Copy link
Copy Markdown
Owner Author

Observed again on #4023's automatic main run 43738678603, squash 4035f977e0cc471a5fbe795f447237c15890d3dd, unit shard 3 job 132887184373.

At 17:12:15 UTC, packages/ui-server/tests/apify-front-doors.test.ts:184 (the CLI keeps consent across invocations and refuses a run nobody can approve) reaches parseArgs in packages/core/src/cli/io.ts:115 and throws Unknown flag for a generated reference beginning with --. Source still uses randomBytes(32).toString("base64url") at packages/common/src/apify/consent.ts:412 and ledger.ts:390. The failure is the already-described leading-dash reference case; #4023 changes only Claude archive restore timestamps, their tests, a changeset and documentation, and none of these Apify files differ from its tested base. The complete selected candidate run 43736220100 passed before squash.

The shard records 1688 pass / 8 skip / 1 fail in that worker. A sibling worker is then interrupted (exit 143); its visual-dictation config probe reports a null child exit during that cancellation. That secondary diagnostic is retained here without claiming a separate root cause.

No failed job was rerun, no test or gate was changed, and no correction to this issue was attempted under #3790. This remains the existing unscheduled follow-up with no release milestone, under the run's maintainer ruling for intermittent failures.

@schlessera

Copy link
Copy Markdown
Owner Author

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

Labels

area: backends AgentBackend implementations and the seam they share. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant