feat(threads): auto-archive settled threads #13657
main fromrefs/pull/13657/head·opened View on GitHubSettled threads pile up forever. Auto-settle clears finished work out of the active list, but the settled shelf keeps growing (hundreds of threads on a busy install) until someone archives them one by one.
This adds Auto-archive settled threads to Settings → General → Organization, under the auto-settle rows. It is off by default. Turning it on uses 30 days, and you can change the number. A thread archives once it has been settled for that many days. Archived threads stay in Settings → Archive and can be restored as usual.
How it works#
- Contracts: new
sidebarAutoArchiveAfterDaysserver setting (null= off, 1–90 days, same bounds as auto-settle). It is project-scoped like the auto-settle settings, so a project can override or disable it. There's also a newthreadAutoArchivecapability so clients hide the controls on older servers, which would silently ignore the key. - Server:
ThreadSettlementReactoralready runs a sweep every minute and on settlement-setting changes. After the settle pass, it archives threads that are still settled past their resolved threshold. It dispatches a new internalthread.auto-archivecommand that carries thesettledAtit observed. The decider rejects the command if the thread was un-settled or re-settled after the snapshot, so new activity can never race into an archive. It emits the existingthread.archivedevent, so projection and clients need no changes. - Restore: when an archived settled thread is restored,
thread.unarchivedgives it a freshsettledAt. The thread gets a new full window, and any auto-archive queued with the old value fails the guard. - Clients: web/desktop rows (toggle plus a days field, with reset, inheritance, restore-defaults, and settings search), mobile Thread behavior → Auto-archive section, and shared-settings sync that skips targets without the capability.
- Docs: one paragraph in
docs/user/thread-sidebar.md.
Providers are unaffected.
Screenshots (2880×1800)#
| Before | After (default, off) | After (on) |
|---|---|---|
![]() | ![]() | ![]() |
Testing#
- New decider tests for
thread.auto-archive: archives when still settled at the observed time; rejects un-settled, activity-cleared, re-settled, and already-archived threads. isAutoArchiveDuepolicy tests, plus a reactor test covering off-by-default, the threshold, and a project override that disables it.- Shared-settings test for capability gating.
- Checked end to end against a copy of a real database (225 settled threads): at 30 days nothing was due, so nothing archived. At 10 days, exactly the 71 threads settled longer than that were archived, the 154 newer ones stayed, and nothing was logged as a warning.
- Typecheck is clean for contracts, shared, client-runtime, server, web, and mobile. The
storage cleanupcases inThreadSettlementReactor.test.tsfail the same way on untouchedmainin my environment.
Model: Claude Opus 5.5 (1M context) · Harness: Claude Code in T3 Code
🤖 Generated with Claude Code
Summary by CodeRabbit#
- New Features
- Settled threads can now be automatically archived after a configurable number of days. Auto-archiving is off by default and can be configured in settings when supported by connected environments.
- Restoring a settled thread starts a fresh countdown before it can be automatically archived again.
- Documentation
- Updated the thread sidebar guide with auto-archive behavior and restoration details.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -455,3 +455,10 @@455455 };456456 }457457458+ case "thread.auto-archive": {459+ const thread = yield* requireThreadNotArchived({460+ readModel,461+ command,462+ threadId: command.threadId,463+ });464+ if (thread.settledOverride !== "settled" || thread.settledAt !== command.settledAt) {
🟡 Medium
orchestration/decider.ts:464A queued
thread.auto-archivecan archive a thread after the user restores it. The guard only comparessettledOverrideandsettledAt, whilethread.unarchivedleaves both values unchanged, so a snapshot taken before archive/restore still passes and re-archives the restored thread. Include an archive/lifecycle generation in the snapshot guard or invalidate the pending auto-archive on restore.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/orchestration/decider.ts around line 464: A queued `thread.auto-archive` can archive a thread after the user restores it. The guard only compares `settledOverride` and `settledAt`, while `thread.unarchived` leaves both values unchanged, so a snapshot taken before archive/restore still passes and re-archives the restored thread. Include an archive/lifecycle generation in the snapshot guard or invalidate the pending auto-archive on restore.Confirmed, and it was broader than the queued-command race:
thread.unarchivedleftsettledAtuntouched, so even without a race the next one-minute sweep would re-archive a restored thread immediately.Fixed in 84ec6da23. When the restored thread is settled,
thread.unarchivednow carries a freshsettledAt. The projector, projection, and client reducer apply it, so:- a restored thread gets a new full window before it can auto-archive again
- any
thread.auto-archivequeued before the archive/restore carries the oldsettledAtand is rejected by the existing guard
Restoring an active thread is unchanged. Covered by new decider and projector tests.
Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR introduces a substantial cross-layer capability that automatically archives user threads and adds a new 30-day enablement default. An unresolved lifecycle race can re-archive a restored thread, so the production behavior requires human review.
Not approved because:
- 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
62e8d3c6-a458-4236-9a96-26efb0b18338📥 Commits
Reviewing files that changed from the base of the PR and between e5a46d6c5d00b89afba5274a94d42428c8d79763 and 84ec6da237499fe08a6c94a565e3aee44c902ad0.
📒 Files selected for processing (24)
apps/mobile/src/features/settings/SettingsThreadsRouteScreen.tsxapps/mobile/src/features/settings/components/AutoSettleDaysField.android.tsxapps/mobile/src/features/settings/components/AutoSettleDaysField.ios.tsxapps/mobile/src/features/settings/components/AutoSettleDaysField.tsxapps/server/src/environment/ServerEnvironment.tsapps/server/src/orchestration/Layers/ProjectionPipeline.tsapps/server/src/orchestration/ThreadSettlementPolicy.test.tsapps/server/src/orchestration/ThreadSettlementPolicy.tsapps/server/src/orchestration/ThreadSettlementReactor.test.tsapps/server/src/orchestration/ThreadSettlementReactor.tsapps/server/src/orchestration/decider.autoArchive.test.tsapps/server/src/orchestration/decider.tsapps/server/src/orchestration/projector.test.tsapps/server/src/orchestration/projector.tsapps/web/src/components/settings/SettingInheritance.tsxapps/web/src/components/settings/SettingsPanels.tsxapps/web/src/components/settings/settingsSearch.tsdocs/user/thread-sidebar.mdpackages/client-runtime/src/state/sharedSettings.test.tspackages/client-runtime/src/state/sharedSettings.tspackages/client-runtime/src/state/threadReducer.tspackages/contracts/src/environment.tspackages/contracts/src/orchestration.tspackages/contracts/src/settings.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The change adds an off-by-default setting for automatically archiving settled threads after a configurable number of days. It adds capability-aware web and mobile controls, server-side eligibility checks and archive commands, and resets the settled-time clock when a settled thread is restored.
Changes#
Settled-thread auto-archive
Layer / File(s) Summary Settings, capability, and command contracts
packages/contracts/src/settings.ts,packages/contracts/src/environment.ts,packages/contracts/src/orchestration.ts,packages/client-runtime/src/state/sharedSettings.ts,packages/client-runtime/src/state/sharedSettings.test.tsAdds the nullable archive-delay setting and its 30-day default, the server capability and command schemas, and capability-aware shared-setting filtering. Archive eligibility and sweeps
apps/server/src/environment/ServerEnvironment.ts,apps/server/src/orchestration/ThreadSettlementPolicy.ts,apps/server/src/orchestration/ThreadSettlementPolicy.test.ts,apps/server/src/orchestration/ThreadSettlementReactor.ts,apps/server/src/orchestration/ThreadSettlementReactor.test.tsAdds due-thread checks and a sweep that uses project settings to dispatch archive commands. The sweep tests cover disabled, recently settled, active, and project-opt-out cases. Archive command and restoration lifecycle
apps/server/src/orchestration/decider.ts,apps/server/src/orchestration/decider.autoArchive.test.ts,apps/server/src/orchestration/Layers/ProjectionPipeline.ts,apps/server/src/orchestration/projector.ts,apps/server/src/orchestration/projector.test.ts,packages/client-runtime/src/state/threadReducer.tsValidates archive commands against current settled state and applies the refreshed settledAtvalue from unarchive events where provided.Web and mobile auto-archive settings
apps/web/src/components/settings/SettingsPanels.tsx,apps/web/src/components/settings/SettingInheritance.tsx,apps/web/src/components/settings/settingsSearch.ts,apps/mobile/src/features/settings/SettingsThreadsRouteScreen.tsx,apps/mobile/src/features/settings/components/AutoSettleDaysField*,docs/user/thread-sidebar.mdAdds capability-gated settings controls, day-count labels, search entries, and documentation for auto-archive behavior. Priority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature
Sequence Diagram(s)#
sequenceDiagram participant ThreadSettlementReactor participant isAutoArchiveDue participant Decider ThreadSettlementReactor->>isAutoArchiveDue: Check thread age against the resolved archive delay isAutoArchiveDue-->>ThreadSettlementReactor: Return eligibility ThreadSettlementReactor->>Decider: Dispatch thread.auto-archive with settledAt Decider-->>ThreadSettlementReactor: Accept or reject based on the current settled stateSuggested reviewers:
juliusmarminge,t3dotggMerge Risk: ⚪ Minimal · up to
84ec6The auto-archive setting can be merged after normal checks; no outstanding behavior issue was established.
Security Architecture Review#
Security architecture risk: 🟡 Moderate · up to
84ec6Auto-archive is off by default and archived threads can be restored. However, an archive already queued under an enabled setting can still complete after that setting is turned off or its delay is increased. The impact is limited to eligible settled threads, but the setting may not take effect immediately for work in flight.
Retained concerns
- Medium · reliability · inferred: An archive selected under an enabled project policy can commit after that policy is disabled or its delay is extended, because the command consumer rechecks settlement state but not current policy.
Security review details
Security Blast Radius
- inferred — When enabled globally, the sweep can select eligible threads across projects; explicit project overrides determine each thread’s effective delay. The visible outcome is archival, not deletion.
Trust Boundaries and Controls
- observed — The checked client command contract excludes the new internal command. For server-generated commands, the settlement timestamp guards against changed thread state, but is not a version of the settings policy.
Resilience and Maintainability Implications
- observed — Restore refreshes the settlement timestamp for settled threads, preventing a queued command bearing the old timestamp from archiving the restored thread.
Hardening Proposals
- proposed — If turning off or lengthening the policy must stop work already in flight, version the resolved policy or revalidate it at the archive commit boundary. Define explicitly whether commands selected under an earlier policy may complete.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 23 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly and concisely identifies the main change: adding automatic archival for settled threads. Description check ✅ Passed The description explains what changed, why it was needed, implementation details, UI changes with before-and-after screenshots, and testing results. It does not include the template's explicit Checkli… Full details: Docstring Coverage
Explanation
Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 23 files. (1 skipped: 1 unsupported.)
- Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
Comment `@coderabbitai help` to get the list of available commands.Note
This comment is posted by Julius' dot
This adds a new automatic archival workflow and changes restore behavior to restart the settled-thread clock. Although it is off by default and configurable, it goes beyond configuring an existing auto-archive capability. No prior maintainer approval is linked. Under prior approval, please agree the direction and scope with maintainers and link that approval before requesting reconsideration. The growing settled shelf is a useful problem report, and the screenshots and focused tests are helpful.
juliusmarminge closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed