@devries-cameron20 / t3code Mirror · read-only / commits / bf8ffe81a6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 13:00 UTC

feat(settings): inactivity auto-settle can keep threads with a PR (#14642)

Co-authored-by: maria-rcks <maria@kuuro.net>

Tristan Knight committed Oct 14, 2026 at 19:14 UTC bf8ffe81a63c82d3de5fbaa9991fd5f30034a452
7 files changed +80 -2
apps/server/src/environment/ServerEnvironment.ts
+1
@@ -232,6 +232,7 @@ export const make = Effect.gen(function* () {
232 otlpEndpointCheck: true,
233 projectWorktreeCleanup: true,
234 worktreesDirectory: true,
235 + threadAutoSettlementScope: true,
236 threadRestartContinuation: true,
237 projectSettingsOverrides: true,
238 projectProviderInstanceOverrides: true,
apps/server/src/orchestration-v2/ThreadSettlementService.test.ts
+32
@@ -251,6 +251,38 @@ describe("threadHasQueuedTurnStart", () => {
251 });
252
253 describe("resolveAutoSettlementAt", () => {
254 + it("keeps threads with a PR from inactivity settlement only when asked", () => {
255 + const input = {
256 + thread: shell({
257 + latestUserMessageAt: at(-4 * DAY_MS),
258 + linkedPullRequest: {
259 + projectId: ProjectId.make("project-1"),
260 + repository: "owner/repo",
261 + number: 1,
262 + url: "https://example.test/owner/repo/pull/1",
263 + },
264 + }),
265 + pullRequest: null,
266 + nowMs: NOW_MS,
267 + autoSettleAfterDays: 3,
268 + autoSettleOnMerge: true,
269 + autoSettleKeepPullRequests: true,
270 + };
271 + expect(ThreadSettlementService.resolveAutoSettlementAt(input)).toBeNull();
272 + expect(
273 + ThreadSettlementService.resolveAutoSettlementAt({
274 + ...input,
275 + autoSettleKeepPullRequests: false,
276 + }),
277 + ).toEqual(at(-4 * DAY_MS));
278 + expect(
279 + ThreadSettlementService.resolveAutoSettlementAt({
280 + ...input,
281 + pullRequest: { state: "merged", mergedAt: DateTime.formatIso(at(-1)) },
282 + }),
283 + ).toEqual(at(-4 * DAY_MS));
284 + });
285 +
286 it("uses the latest activity time when the inactivity window elapses", () => {
287 const idle = shell({
288 latestUserMessageAt: at(-4 * DAY_MS),
apps/server/src/orchestration-v2/ThreadSettlementService.ts
+10 -1
@@ -202,6 +202,7 @@ export function resolveAutoSettlementAt(input: {
202 readonly nowMs: number;
203 readonly autoSettleAfterDays: number | null;
204 readonly autoSettleOnMerge: boolean;
205 + readonly autoSettleKeepPullRequests?: boolean;
206 }): DateTime.Utc | null {
207 const { thread } = input;
208 let pullRequest = input.pullRequest;
@@ -236,6 +237,9 @@ export function resolveAutoSettlementAt(input: {
237 if (pullRequest !== null && pullRequestSettles(thread, pullRequest, input.autoSettleOnMerge)) {
238 return activityAtMs === null ? thread.createdAt : DateTime.makeUnsafe(activityAtMs);
239 }
240 + const hasPullRequest =
241 + pullRequest !== null || thread.linkedPullRequest != null || thread.branchPullRequest != null;
242 + if (input.autoSettleKeepPullRequests === true && hasPullRequest) return null;
243 if (input.autoSettleAfterDays === null || activityAtMs === null) return null;
244 // A passed wake timer restarts inactivity. An earlier wake can only delay settlement.
245 const snoozedUntilMs = toMillis(thread.snoozedUntil);
@@ -275,6 +279,7 @@ export function autoSettlementSettingsKey(
279 return JSON.stringify([
280 settings.sidebarAutoSettleOnMerge,
281 settings.sidebarAutoSettleAfterDays,
282 + settings.sidebarAutoSettleKeepPullRequests,
283 // Only entries that touch settlement, in a stable order, so a project
284 // override on an unrelated key does not queue a sweep. JSON drops
285 // undefined, so inherit (absent) and never (null) need distinct marks.
@@ -282,7 +287,8 @@ export function autoSettlementSettingsKey(
287 .filter(
288 ([, entry]) =>
289 entry.sidebarAutoSettleOnMerge !== undefined ||
285 - entry.sidebarAutoSettleAfterDays !== undefined,
290 + entry.sidebarAutoSettleAfterDays !== undefined ||
291 + entry.sidebarAutoSettleKeepPullRequests !== undefined,
292 )
293 .sort(([left], [right]) => left.localeCompare(right))
294 .map(([projectId, entry]) => [
@@ -291,6 +297,7 @@ export function autoSettlementSettingsKey(
297 entry.sidebarAutoSettleAfterDays === undefined
298 ? "inherit"
299 : entry.sidebarAutoSettleAfterDays,
300 + entry.sidebarAutoSettleKeepPullRequests ?? "inherit",
301 ]),
302 ]);
303 }
@@ -343,6 +350,7 @@ export const make = Effect.gen(function* () {
350 nowMs: DateTime.toEpochMillis(decisionNow),
351 autoSettleAfterDays: currentSettings.sidebarAutoSettleAfterDays,
352 autoSettleOnMerge: currentSettings.sidebarAutoSettleOnMerge,
353 + autoSettleKeepPullRequests: currentSettings.sidebarAutoSettleKeepPullRequests,
354 });
355 if (settledAt === null) return thread;
356 const uuid = yield* crypto.randomUUIDv4();
@@ -445,6 +453,7 @@ export const make = Effect.gen(function* () {
453 nowMs: DateTime.toEpochMillis(decisionNow),
454 autoSettleAfterDays: settings.sidebarAutoSettleAfterDays,
455 autoSettleOnMerge: settings.sidebarAutoSettleOnMerge,
456 + autoSettleKeepPullRequests: settings.sidebarAutoSettleKeepPullRequests,
457 }) !== null
458 );
459 });
apps/web/src/components/settings/SettingsPanels.tsx
+27
@@ -582,6 +582,10 @@ export function useSettingsRestore(onRestored?: () => void) {
582 DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays
583 ? ["Auto-settle inactive threads"]
584 : []),
585 + ...(settings.sidebarAutoSettleKeepPullRequests !==
586 + DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleKeepPullRequests
587 + ? ["Keep threads with a PR"]
588 + : []),
589 ...(settings.sidebarAutoSettleOnMerge !== DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge
590 ? ["Auto-settle merged threads"]
591 : []),
@@ -708,6 +712,7 @@ export function useSettingsRestore(onRestored?: () => void) {
712 settings.enableProviderUpdateChecks,
713 settings.continueThreadsAfterServerUpdate,
714 settings.sidebarAutoSettleAfterDays,
715 + settings.sidebarAutoSettleKeepPullRequests,
716 settings.sidebarAutoSettleOnMerge,
717 settings.autoResumeLimitedThreads,
718 settings.snoozeLimitedThreads,
@@ -815,6 +820,7 @@ export function useSettingsRestore(onRestored?: () => void) {
820 sidebarProjectSortOrder: DEFAULT_UNIFIED_SETTINGS.sidebarProjectSortOrder,
821 sidebarWorkingShelfEnabled: DEFAULT_UNIFIED_SETTINGS.sidebarWorkingShelfEnabled,
822 sidebarAutoSettleAfterDays: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays,
823 + sidebarAutoSettleKeepPullRequests: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleKeepPullRequests,
824 sidebarAutoSettleOnMerge: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge,
825 autoResumeLimitedThreads: DEFAULT_UNIFIED_SETTINGS.autoResumeLimitedThreads,
826 snoozeLimitedThreads: DEFAULT_UNIFIED_SETTINGS.snoozeLimitedThreads,
@@ -2203,6 +2209,9 @@ export function GeneralSettingsPanel() {
2209 connectedEnvironments.every(
2210 (target) => target.serverConfig?.environment.capabilities.threadAutoSettlement === true,
2211 );
2212 + const supportsAutoSettlementScope = connectedEnvironments.every(
2213 + (target) => target.serverConfig?.environment.capabilities.threadAutoSettlementScope === true,
2214 + );
2215 const supportsRestartContinuation =
2216 connectedEnvironments.length > 0 &&
2217 connectedEnvironments.every(
@@ -2483,6 +2492,24 @@ export function GeneralSettingsPanel() {
2492 }
2493 />
2494 ) : null}
2495 + {settings.sidebarAutoSettleAfterDays !== null && supportsAutoSettlementScope ? (
2496 + <SettingsRow
2497 + serverScoped
2498 + settingKeys={["sidebarAutoSettleKeepPullRequests"]}
2499 + title="Keep threads with a PR"
2500 + description="Inactivity does not settle threads with a pull request. Merge and close still do."
2501 + control={
2502 + <ScopedSwitch
2503 + settingKeys={["sidebarAutoSettleKeepPullRequests"]}
2504 + checked={settings.sidebarAutoSettleKeepPullRequests}
2505 + onCheckedChange={(checked) =>
2506 + updateSettings({ sidebarAutoSettleKeepPullRequests: checked })
2507 + }
2508 + aria-label="Keep threads with a PR"
2509 + />
2510 + }
2511 + />
2512 + ) : null}
2513 </>
2514 ) : null}
2515 </SettingsSection>
docs/user/thread-sidebar.md
+2 -1
@@ -150,7 +150,8 @@ By default, environments settle inactive threads after three days and settle
150 threads whose pull request merged. A closed pull request can also settle an idle
151 thread. Work in progress, pending questions or approvals, and live background work
152 prevent automatic settlement. An open pull request does not prevent inactivity
153 -settlement, but an old closed or merged pull request does not settle work you
153 +settlement unless you turn on **Keep threads with a PR** in **Settings → General**,
154 +but an old closed or merged pull request does not settle work you
155 resumed after it closed. Only your own messages count as resuming. A turn that
156 finished background work or a pull request watch starts on its own does not.
157
packages/contracts/src/environment.ts
+2
@@ -131,6 +131,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
131 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
132 /** Server honors the `worktreesDirectory` setting. */
133 worktreesDirectory: Schema.optionalKey(Schema.Boolean),
134 + /** Server can exclude PR-linked threads from inactivity settlement. */
135 + threadAutoSettlementScope: Schema.optionalKey(Schema.Boolean),
136 /** Server persists the opt-in for continuing interrupted threads after restarts. */
137 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
138 /** Server resolves `projectSettingsOverrides`; older servers ignore the key. */
packages/contracts/src/settings.ts
+6
@@ -984,6 +984,7 @@ export const PROJECT_SCOPED_SERVER_SETTING_KEYS = [
984 "pullRequestMergeMethod",
985 "sidebarAutoSettleOnMerge",
986 "sidebarAutoSettleAfterDays",
987 + "sidebarAutoSettleKeepPullRequests",
988 "continueThreadsAfterServerUpdate",
989 "responseStreamingMode",
990 ] as const;
@@ -1031,6 +1032,7 @@ export const ProjectSettingsOverrides = Schema.Struct({
1032 pullRequestMergeMethod: Schema.optionalKey(Schema.NullOr(PullRequestMergeMethod)),
1033 sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
1034 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
1035 + sidebarAutoSettleKeepPullRequests: Schema.optionalKey(Schema.Boolean),
1036 continueThreadsAfterServerUpdate: Schema.optionalKey(Schema.Boolean),
1037 responseStreamingMode: Schema.optionalKey(ResponseStreamingMode),
1038 providerInstances: Schema.optionalKey(
@@ -1198,6 +1200,9 @@ export const ServerSettings = Schema.Struct({
1200 ),
1201 snoozeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
1202 autoResumeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
1203 + sidebarAutoSettleKeepPullRequests: Schema.Boolean.pipe(
1204 + Schema.withDecodingDefault(Effect.succeed(false)),
1205 + ),
1206 sidebarAutoSettleOnMerge: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
1207 backgroundActivity: BackgroundActivitySettings,
1208 // Legacy flat fields retained for old settings files and old clients. New
@@ -1572,6 +1577,7 @@ export const ServerSettingsPatch = Schema.Struct({
1577 deviceOnboardingCompleted: Schema.optionalKey(Schema.Boolean),
1578 deviceHosts: Schema.optionalKey(SshDeviceHostConfigs),
1579 sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
1580 + sidebarAutoSettleKeepPullRequests: Schema.optionalKey(Schema.Boolean),
1581 sidebarAutoSettleOnMerge: Schema.optionalKey(Schema.Boolean),
1582 autoResumeLimitedThreads: Schema.optionalKey(Schema.Boolean),
1583 snoozeLimitedThreads: Schema.optionalKey(Schema.Boolean),