@devries-cameron20 / t3code Mirror · read-only / commits / dabab454ae
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 22, 08:15 UTC

perf(server): skip no-op settlement decisions (#27897)

Co-authored-by: Omar <76748259+omar9848492@users.noreply.github.com>

Omar committed Oct 31, 2026 at 22:43 UTC dabab454aeca0f6b58fee0f86f01da286843a901
2 files changed +56 -3
apps/server/src/orchestration-v2/ThreadSettlementService.test.ts
+36 -1
@@ -571,6 +571,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
571 const snapshotReads = yield* Queue.unbounded<number>();
572 const candidateReads = yield* Ref.make<ReadonlyArray<string | undefined>>([]);
573 const settings = yield* Ref.make(options.settings ?? DEFAULT_SERVER_SETTINGS);
574 + const settingsReadCount = yield* Ref.make(0);
575 const settingsChanges = yield* PubSub.unbounded<ContractServerSettings>();
576 const mergedPullRequests = yield* PubSub.unbounded<PullRequestService.PullRequestMergeEvent>();
577 const commands = yield* Ref.make<ReadonlyArray<AutoSettleCommand>>([]);
@@ -640,7 +641,9 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
641 const serverSettings = ServerSettings.ServerSettingsService.of({
642 start: Effect.void,
643 ready: Effect.void,
643 - getSettings: Ref.get(settings),
644 + getSettings: Ref.update(settingsReadCount, (count) => count + 1).pipe(
645 + Effect.andThen(Ref.get(settings)),
646 + ),
647 updateSettings,
648 updateProviderInstance: () => Effect.die("Unexpected provider mutation"),
649 withSettingsSnapshot: (use) => Ref.get(settings).pipe(Effect.flatMap(use)),
@@ -710,6 +713,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
713 activation,
714 snapshots,
715 snapshotReadCount,
716 + settingsReadCount,
717 snapshotReads,
718 candidateReads,
719 commands,
@@ -746,6 +750,37 @@ const startHarness = Effect.fn("startThreadSettlementHarness")(function* (
750 });
751
752 describe("ThreadSettlementServiceV2 worker", () => {
753 + it.effect("skips settings and PR decisions for recent branchless threads", () =>
754 + Effect.scoped(
755 + Effect.gen(function* () {
756 + yield* TestClock.setTime(Date.parse(NOW));
757 + const threads = Array.from({ length: 32 }, (_, index) =>
758 + makeThread(`recent-${index}`, {
759 + updatedAt: DateTime.makeUnsafe(NOW),
760 + latestUserMessageAt: DateTime.makeUnsafe(Date.parse(NOW) - 2 * DAY_MS),
761 + }),
762 + );
763 + const fixture = yield* makeHarness({
764 + snapshot: makeSnapshot(threads),
765 + settings: { ...DEFAULT_SERVER_SETTINGS, sidebarAutoSettleAfterDays: 3 },
766 + });
767 + yield* Effect.gen(function* () {
768 + const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
769 + yield* startHarness(service, fixture.activation, fixture.snapshotReads);
770 + assert.deepEqual(yield* Ref.get(fixture.commands), []);
771 + assert.deepEqual(yield* Ref.get(fixture.branchCalls), []);
772 + assert.equal(yield* Ref.get(fixture.settingsReadCount), 2);
773 + yield* fixture.updateSettings({ sidebarAutoSettleAfterDays: 1 });
774 + yield* Queue.take(fixture.snapshotReads);
775 + yield* service.drain;
776 + assert.deepEqual(
777 + new Set((yield* Ref.get(fixture.commands)).map((command) => command.threadId)),
778 + new Set(threads.map((thread) => thread.id)),
779 + );
780 + }).pipe(Effect.provide(fixture.layer));
781 + }),
782 + ),
783 + );
784 it.effect("settles a merged pull request stored only in the thread links", () =>
785 Effect.scoped(
786 Effect.gen(function* () {
apps/server/src/orchestration-v2/ThreadSettlementService.ts
+20 -2
@@ -364,11 +364,29 @@ export const make = Effect.gen(function* () {
364
365 const lookupCandidates = (yield* Effect.forEach(
366 candidates,
367 - (thread) => settleThread(thread, null),
367 + (thread) => {
368 + const projectSettings = resolveProjectSettings(settings, thread.projectId).settings;
369 + // Skip no-op decisions; actual settlement still reads fresh settings before dispatch.
370 + const settledAt = resolveAutoSettlementAt({
371 + thread,
372 + pullRequest: null,
373 + nowMs,
374 + autoSettleAfterDays: projectSettings.sidebarAutoSettleAfterDays,
375 + autoSettleOnMerge: projectSettings.sidebarAutoSettleOnMerge,
376 + autoSettleKeepPullRequests: projectSettings.sidebarAutoSettleKeepPullRequests,
377 + });
378 + return settledAt === null ? Effect.succeed(thread) : settleThread(thread, null);
379 + },
380 { concurrency: 8 },
381 ))
382 .filter((thread) => thread !== null)
371 - .filter((thread) => visibleThreadPullRequests(thread.pullRequests ?? []).length === 0);
383 + .filter((thread) => visibleThreadPullRequests(thread.pullRequests ?? []).length === 0)
384 + .filter(
385 + (thread) =>
386 + thread.branch !== null ||
387 + thread.linkedPullRequest != null ||
388 + thread.branchPullRequest != null,
389 + );
390 const lookupCwdByThreadId = new Map<string, string>();
391 yield* Effect.forEach(
392 lookupCandidates,