refactor(server): settled state is now server-authored, ending client drift #5462
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromt3code/server-side-settled-logicopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/orchestration/Services/ThreadAutoSettleReactor.ts lines 19 to 35OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +15,21 @@15+16+/**17+ * ThreadAutoSettleReactorShape - Service API for the auto-settle sweep.18+ */19+export interface ThreadAutoSettleReactorShape {20+ /**21+ * Start the periodic auto-settle sweep within the provided scope.22+ */23+ readonly start: () => Effect.Effect<void, never, Scope.Scope>;24+25+ /**26+ * Run one sweep immediately. Intended for tests, which must never wait on27+ * the timer schedule.28+ */29+ readonly sweepOnce: Effect.Effect<void>;30+}31+32+export class ThreadAutoSettleReactor extends Context.Service<33+ ThreadAutoSettleReactor,34+ ThreadAutoSettleReactorShape35+>()("t3/orchestration/Services/ThreadAutoSettleReactor") {}apps/server/src/orchestration/Layers/ThreadAutoSettleReactor.ts lines 214 to 217OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +197,21 @@197+ ),198+ );199+200+ const start: ThreadAutoSettleReactorShape["start"] = () =>201+ Effect.gen(function* () {202+ yield* forkParked(203+ sweepOnce.pipe(Effect.repeat(Schedule.spaced(Duration.millis(sweepIntervalMs)))),204+ );205+ yield* Effect.logInfo("thread.auto-settle.started", { sweepIntervalMs });206+ });207+208+ return {209+ start,210+ sweepOnce,211+ } satisfies ThreadAutoSettleReactorShape;212+ });213+214+export const makeThreadAutoSettleReactorLive = (options?: ThreadAutoSettleReactorLiveOptions) =>215+ Layer.effect(ThreadAutoSettleReactor, makeThreadAutoSettleReactor(options));216+217+export const ThreadAutoSettleReactorLive = makeThreadAutoSettleReactorLive();
- apps/server/src/orchestration/ThreadAutoSettleReactor.ts line 227Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +154,21 @@154+ const [snapshot, afterDays, now] = yield* Effect.all([155+ projectionSnapshotQuery.getShellSnapshot(),156+ autoSettleAfterDays,157+ Effect.map(DateTime.now, DateTime.formatIso),158+ ]);159+ const workspaceRootByProjectId = new Map(160+ snapshot.projects.map((project) => [project.id, project.workspaceRoot]),161+ );162+ const mayVerifyPr = yield* backgroundPolicy.shouldRunOpportunisticWork;163+ let verifyBudget = PR_VERIFY_MAX_PER_SWEEP;164+165+ for (const thread of snapshot.threads) {166+ const cwd = thread.worktreePath ?? workspaceRootByProjectId.get(thread.projectId);167+ if (cwd === undefined) continue;168+ const target = { branch: thread.branch, cwd };169+ const verdict = resolveAutoSettleVerdict(thread, {170+ now,171+ autoSettleAfterDays: afterDays,172+ changeRequestState: yield* peekChangeRequestState(target),173+ });174+ if (verdict.kind === "skip") continue;apps/server/src/orchestration/decider.ts line 502OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -497,4 +497,6 @@497497 type: "thread.settled" as const,498498 payload: {499499 threadId: command.threadId,500- settledAt: alreadySettled ? thread.settledAt : occurredAt,500+ // Auto-settle passes the thread's last-activity time so the settled501+ // shelf orders by when work ended, not when the sweep ran.502+ settledAt: alreadySettled ? thread.settledAt : (command.settledAt ?? occurredAt),apps/server/src/orchestration/ThreadAutoSettleReactor.ts line 234Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +160,21 @@160+ snapshot.projects.map((project) => [project.id, project.workspaceRoot]),161+ );162+ const mayVerifyPr = yield* backgroundPolicy.shouldRunOpportunisticWork;163+ let verifyBudget = PR_VERIFY_MAX_PER_SWEEP;164+165+ for (const thread of snapshot.threads) {166+ const cwd = thread.worktreePath ?? workspaceRootByProjectId.get(thread.projectId);167+ if (cwd === undefined) continue;168+ const target = { branch: thread.branch, cwd };169+ const verdict = resolveAutoSettleVerdict(thread, {170+ now,171+ autoSettleAfterDays: afterDays,172+ changeRequestState: yield* peekChangeRequestState(target),173+ });174+ if (verdict.kind === "skip") continue;175+ if (verdict.kind === "settle") {176+ yield* settleThread({ threadId: thread.id, settledAt: verdict.settledAt });177+ continue;178+ }179+ // verify-pr: quiet past the window but PR state undetermined.180+ if (!mayVerifyPr || verifyBudget <= 0) continue;apps/web/src/components/settings/BetaSettingsPanel.tsx line 92OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -87,2 +91,2 @@8791 <>8892 <SettingsRowpackages/client-runtime/src/state/threadSettled.ts line 222Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -218,13 +194,11 @@218194 /**219- * Settled resolution over the server-backed settled lifecycle. Activity220- * blockers (pending approval/user-input, a live session, an unadjudicated221- * queued turn) are checked first and hold a thread active regardless of any222- * override. Past the blockers, the explicit user override (thread.settle /223- * thread.unsettle commands, projected into settledOverride + settledAt)224- * wins in both directions; without one, a thread auto-settles on a225- * merged/closed PR immediately or on inactivity past the window — except226- * that an open PR blocks the inactivity path entirely. The server227- * un-settles on real activity (user message, session start, approval/228- * user-input request), so an override never goes stale silently.195+ * Settled resolution: the server is the single author of settled state.196+ * The override IS the classification — the server settles (user command or197+ * the auto-settle sweep: inactivity window, merged/closed PR) and un-settles198+ * on real activity (user message, session start, approval/user-input199+ * request), so clients never re-derive it. The one client-side guard:200+ * blocked-on-you work stays visible even under a stale "settled" override,201+ * covering the beat between a request landing and the server's auto-unsettle202+ * event arriving.229203 */230204 export function effectiveSettled(
- apps/server/src/orchestration/autoSettle.ts line 157OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +137,21 @@137+ return { kind: "skip" };138+ }139+ if (hasQueuedTurnStart(thread, nowMs)) return { kind: "skip" };140+141+ const lastActivityAt = threadLastActivityAt(thread, nowMs);142+143+ if (changeRequestState === "merged" || changeRequestState === "closed") {144+ return { kind: "settle", settledAt: lastActivityAt ?? options.now };145+ }146+ // An open PR is unfinished business no matter how long the thread has been147+ // quiet: review can take days, and hiding the thread would bury the work148+ // waiting on it.149+ if (changeRequestState === "open") return { kind: "skip" };150+ if (autoSettleAfterDays === null) return { kind: "skip" };151+ if (lastActivityAt === null) return { kind: "skip" };152+ if (Date.parse(lastActivityAt) >= nowMs - autoSettleAfterDays * DAY_MS) {153+ return { kind: "skip" };154+ }155+ // Quiet past the window, but PR state undetermined: verify before hiding —156+ // the branch may have an open PR nobody has looked at from this server yet.157+ if (changeRequestState === "unknown") return { kind: "verify-pr" };apps/web/src/components/settings/BetaSettingsPanel.tsx line 114OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -95,16 +99,16 @@95- updateSettings({96- sidebarAutoSettleAfterDays: checked ? AUTO_SETTLE_DEFAULT_DAYS : null,99+ updateServerSettings({100+ threadAutoSettleAfterDays: checked ? AUTO_SETTLE_DEFAULT_DAYS : null,97101 })98102 }99103 aria-label="Auto-settle inactive threads"100104 />101105 }102106 />103- {sidebarAutoSettleAfterDays !== null ? (107+ {threadAutoSettleAfterDays !== null ? (104108 <SettingsRow105109 title="Days of inactivity before auto-settle"106110 description="Any new activity un-settles a thread automatically."107111 control={108112 <AutoSettleDaysInput109- value={sidebarAutoSettleAfterDays}110- onCommit={(days) => updateSettings({ sidebarAutoSettleAfterDays: days })}113+ value={threadAutoSettleAfterDays}114+ onCommit={(days) => updateServerSettings({ threadAutoSettleAfterDays: days })}
- apps/server/src/orchestration/Layers/ThreadAutoSettleReactor.ts lines 169 to 185OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +165,21 @@165+ for (const thread of snapshot.threads) {166+ const cwd = thread.worktreePath ?? workspaceRootByProjectId.get(thread.projectId);167+ if (cwd === undefined) continue;168+ const target = { branch: thread.branch, cwd };169+ const verdict = resolveAutoSettleVerdict(thread, {170+ now,171+ autoSettleAfterDays: afterDays,172+ changeRequestState: yield* peekChangeRequestState(target),173+ });174+ if (verdict.kind === "skip") continue;175+ if (verdict.kind === "settle") {176+ yield* settleThread({ threadId: thread.id, settledAt: verdict.settledAt });177+ continue;178+ }179+ // verify-pr: quiet past the window but PR state undetermined.180+ if (!mayVerifyPr || verifyBudget <= 0) continue;181+ verifyBudget -= 1;182+ const verified = resolveAutoSettleVerdict(thread, {183+ now,184+ autoSettleAfterDays: afterDays,185+ changeRequestState: yield* verifyChangeRequestState(target),apps/server/src/orchestration/Services/ThreadAutoSettleReactor.ts lines 19 to 35OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +15,21 @@15+16+/**17+ * ThreadAutoSettleReactorShape - Service API for the auto-settle sweep.18+ */19+export interface ThreadAutoSettleReactorShape {20+ /**21+ * Start the periodic auto-settle sweep within the provided scope.22+ */23+ readonly start: () => Effect.Effect<void, never, Scope.Scope>;24+25+ /**26+ * Run one sweep immediately. Intended for tests, which must never wait on27+ * the timer schedule.28+ */29+ readonly sweepOnce: Effect.Effect<void>;30+}31+32+export class ThreadAutoSettleReactor extends Context.Service<33+ ThreadAutoSettleReactor,34+ ThreadAutoSettleReactorShape35+>()("t3/orchestration/Services/ThreadAutoSettleReactor") {}apps/web/src/components/settings/BetaSettingsPanel.tsx lines 112 to 114OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -95,16 +99,16 @@95- updateSettings({96- sidebarAutoSettleAfterDays: checked ? AUTO_SETTLE_DEFAULT_DAYS : null,99+ updateServerSettings({100+ threadAutoSettleAfterDays: checked ? AUTO_SETTLE_DEFAULT_DAYS : null,97101 })98102 }99103 aria-label="Auto-settle inactive threads"100104 />101105 }102106 />103- {sidebarAutoSettleAfterDays !== null ? (107+ {threadAutoSettleAfterDays !== null ? (104108 <SettingsRow105109 title="Days of inactivity before auto-settle"106110 description="Any new activity un-settles a thread automatically."107111 control={108112 <AutoSettleDaysInput109- value={sidebarAutoSettleAfterDays}110- onCommit={(days) => updateSettings({ sidebarAutoSettleAfterDays: days })}113+ value={threadAutoSettleAfterDays}114+ onCommit={(days) => updateServerSettings({ threadAutoSettleAfterDays: days })}packages/contracts/src/orchestration.ts lines 596 to 600OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -600,3 +593,8 @@600593 type: Schema.Literal("thread.settle"),601594 commandId: CommandId,602595 threadId: ThreadId,596+ // Server auto-settle stamps the thread's last-activity time here so the597+ // settled shelf orders by when work actually ended, not by when the sweep598+ // happened to run. Absent (user-initiated settles) the event stamps the599+ // command time.600+ settledAt: Schema.optionalKey(IsoDateTime),packages/contracts/src/settings.ts lines 544 to 549Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -536,3 +533,9 @@536533537534 export const ServerSettings = Schema.Struct({538535 enableAssistantStreaming: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),536+ // Days of inactivity before the server auto-settles a thread; null disables537+ // auto-settle. Server-side (not a client setting) so every client sees the538+ // same settled shelf — the server derives settled state, clients only read it.539+ threadAutoSettleAfterDays: Schema.NullOr(ThreadAutoSettleAfterDays).pipe(540+ Schema.withDecodingDefault(Effect.succeed(DEFAULT_THREAD_AUTO_SETTLE_AFTER_DAYS)),541+ ),
- packages/contracts/src/settings.ts line 547Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -536,3 +533,7 @@536533537534 export const ServerSettings = Schema.Struct({538535 enableAssistantStreaming: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),536+ // Days of inactivity before the server auto-settles a thread; null disables537+ // auto-settle. Server-side (not a client setting) so every client sees the538+ // same settled shelf — the server derives settled state, clients only read it.539+ threadAutoSettleAfterDays: Schema.NullOr(ThreadAutoSettleAfterDays).pipe(
- apps/server/src/orchestration/decider.ts lines 192 to 199Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -144,0 +148,21 @@148+// later must not float the thread to the top of the shelf. Threads with no149+// recorded activity fall back to the command time.150+function threadLastActivityAt(151+ thread: {152+ readonly messages: ReadonlyArray<{ readonly role: string; readonly createdAt: string }>;153+ readonly latestTurn: {154+ readonly requestedAt: string;155+ readonly startedAt: string | null;156+ readonly completedAt: string | null;157+ } | null;158+ },159+ fallback: string,160+): string {161+ let latest: string | null = null;162+ let latestMs = Number.NEGATIVE_INFINITY;163+ const candidates = [164+ ...thread.messages.filter((message) => message.role === "user").map((m) => m.createdAt),165+ thread.latestTurn?.requestedAt,166+ thread.latestTurn?.startedAt,167+ thread.latestTurn?.completedAt,168+ ];
- apps/server/src/orchestration/decider.ts line 209Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -144,0 +158,21 @@158+ },159+ fallback: string,160+): string {161+ let latest: string | null = null;162+ let latestMs = Number.NEGATIVE_INFINITY;163+ const candidates = [164+ ...thread.messages.filter((message) => message.role === "user").map((m) => m.createdAt),165+ thread.latestTurn?.requestedAt,166+ thread.latestTurn?.startedAt,167+ thread.latestTurn?.completedAt,168+ ];169+ for (const candidate of candidates) {170+ if (candidate == null) continue;171+ const parsed = Date.parse(candidate);172+ if (!Number.isNaN(parsed) && parsed > latestMs) {173+ latest = candidate;174+ latestMs = parsed;175+ }176+ }177+ return latest ?? fallback;178+}
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/orchestration/decider.ts lines 123 to 130Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -104,3 +104,21 @@104104 * as long as the skew lasts, extending the block far past the intended two105105 * minutes.106106 */107+// The newest user-message time visible to the decider. Reads the projected108+// latestUserMessageAt stamp first — the engine's command read model boots109+// threads with an EMPTY messages array (bodies are never rehydrated), so a110+// messages-only scan silently loses all pre-restart activity — and still111+// scans the in-memory messages as a floor for mid-session freshness.112+function threadLatestUserMessageAtMs(thread: {113+ readonly latestUserMessageAt?: string | null | undefined;114+ readonly messages: ReadonlyArray<{ readonly role: string; readonly createdAt: string }>;115+}): number {116+ const stampedMs =117+ thread.latestUserMessageAt == null118+ ? Number.NEGATIVE_INFINITY119+ : Date.parse(thread.latestUserMessageAt);120+ return thread.messages.reduce(121+ (latest, message) =>122+ message.role === "user" ? Math.max(latest, Date.parse(message.createdAt)) : latest,123+ Number.isNaN(stampedMs) ? Number.NEGATIVE_INFINITY : stampedMs,124+ );
- apps/server/src/orchestration/projector.ts line 559Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -516,7 +517,19 @@516517 : [...thread.messages, message];517518 const cappedMessages = messages.slice(-MAX_THREAD_MESSAGES);518519520+ // Maintained separately from the capped messages array so the stamp521+ // survives message eviction AND the unhydrated command read model522+ // (which boots with messages: []) — the decider's settle logic keys523+ // on it.524+ const latestUserMessageAt =525+ message.role === "user" &&526+ (thread.latestUserMessageAt == null ||527+ Date.parse(message.createdAt) > Date.parse(thread.latestUserMessageAt))528+ ? message.createdAt529+ : thread.latestUserMessageAt;530+519531 return {520532 ...nextBase,521533 threads: updateThread(nextBase.threads, payload.threadId, {522534 messages: cappedMessages,535+ latestUserMessageAt,
- apps/server/src/orchestration/ThreadAutoSettleReactor.ts line 128Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +90,21 @@90+91+ // The cached PR state for a thread's checkout, mapped exactly like the92+ // clients' old resolveThreadPr: a status only counts when its refName is93+ // the thread's branch (a workspace checked out elsewhere can never94+ // determine this thread's PR state, so it gates nothing). A cached95+ // "open" maps to "open-cached": it may have merged since polling96+ // stopped, so it never permanently blocks the inactivity path — the97+ // verdict asks for a cooldown-limited live verification instead.98+ const peekChangeRequestState = Effect.fn("ThreadAutoSettleReactor.peekChangeRequestState")(99+ function* (thread: {100+ readonly branch: string | null;101+ readonly cwd: string;102+ }): Effect.fn.Return<AutoSettleChangeRequestState> {103+ if (thread.branch === null) return "none";104+ const status = yield* vcsStatusBroadcaster.peekStatus({ cwd: thread.cwd });105+ if (status === null) return "unknown";106+ if (status.refName !== thread.branch) return "none";107+ const prState = status.pr?.state ?? null;108+ if (prState === null) return "none";109+ return prState === "open" ? "open-cached" : prState;110+ },apps/server/src/orchestration/ThreadAutoSettleReactor.ts line 95Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +69,21 @@69+ const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;70+ const vcsStatusBroadcaster = yield* VcsStatusBroadcaster;71+ const serverSettings = yield* ServerSettingsService;72+ const backgroundPolicy = yield* BackgroundPolicy.BackgroundPolicy;73+ const crypto = yield* Crypto.Crypto;74+75+ const sweepIntervalMs = Math.max(1, options?.sweepIntervalMs ?? DEFAULT_SWEEP_INTERVAL_MS);76+ const prVerifyCooldownMs = Math.max(77+ 1,78+ options?.prVerifyCooldownMs ?? DEFAULT_PR_VERIFY_COOLDOWN_MS,79+ );80+ const lastPrVerifyAtByCwd = yield* Ref.make(new Map<string, number>());81+82+ const serverCommandId = crypto.randomUUIDv4.pipe(83+ Effect.map((uuid) => CommandId.make(`server:auto-settle:${uuid}`)),84+ );85+86+ const autoSettleAfterDays = serverSettings.getSettings.pipe(87+ Effect.map((settings) => settings.threadAutoSettleAfterDays),88+ Effect.orElseSucceed(() => DEFAULT_THREAD_AUTO_SETTLE_AFTER_DAYS),89+ );
- apps/server/src/orchestration/ThreadAutoSettleReactor.ts line 112OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +92,21 @@92+ // clients' old resolveThreadPr: a status only counts when its refName is93+ // the thread's branch (a workspace checked out elsewhere can never94+ // determine this thread's PR state, so it gates nothing). A cached95+ // "open" maps to "open-cached": it may have merged since polling96+ // stopped, so it never permanently blocks the inactivity path — the97+ // verdict asks for a cooldown-limited live verification instead.98+ const peekChangeRequestState = Effect.fn("ThreadAutoSettleReactor.peekChangeRequestState")(99+ function* (thread: {100+ readonly branch: string | null;101+ readonly cwd: string;102+ }): Effect.fn.Return<AutoSettleChangeRequestState> {103+ if (thread.branch === null) return "none";104+ const status = yield* vcsStatusBroadcaster.peekStatus({ cwd: thread.cwd });105+ if (status === null) return "unknown";106+ // A live lookup cannot change the checkout, so a refName mismatch is107+ // final; but a cached no-PR result may simply predate the PR being108+ // opened — only a live lookup may conclude "none" for the branch.109+ if (status.refName !== thread.branch) return "none";110+ const prState = status.pr?.state ?? null;111+ if (prState === null) return "unknown";112+ return prState === "open" ? "open-cached" : prState;
- apps/server/src/orchestration/autoSettle.ts line 105Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +76,21 @@76+ thread.snoozedUntil != null && Date.parse(thread.snoozedUntil) <= nowMs77+ ? thread.snoozedUntil78+ : null;79+ const candidates = [80+ thread.latestUserMessageAt,81+ thread.latestTurn?.requestedAt,82+ thread.latestTurn?.startedAt,83+ thread.latestTurn?.completedAt,84+ snoozeWakePassed,85+ ];86+ let latest: string | null = null;87+ let latestTimestamp = Number.NEGATIVE_INFINITY;88+ for (const candidate of candidates) {89+ if (candidate == null) continue;90+ const timestamp = Date.parse(candidate);91+ if (timestamp > latestTimestamp) {92+ latest = candidate;93+ latestTimestamp = timestamp;94+ }95+ }96+ return latest;
- @@ -339,3 +343,4 @@339343 return yield* updateCachedStatus(cwd, local, remote);340344 });341345346+ const peekStatus: VcsStatusBroadcaster["Service"]["peekStatus"] = Effect.fn(
- apps/server/src/orchestration/ThreadAutoSettleReactor.test.ts lines 77 to 79OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +59,21 @@59+ archivedAt: null,60+ settledOverride: input.settledOverride ?? null,61+ settledAt: null,62+ snoozedUntil: null,63+ snoozedAt: null,64+ pinnedAt: null,65+ session: null,66+ latestUserMessageAt: input.activityAt,67+ hasPendingApprovals: false,68+ hasPendingUserInput: false,69+ hasActionableProposedPlan: false,70+ };71+}72+73+function makeHarness(input: {74+ readonly threads: ReadonlyArray<OrchestrationThreadShell>;75+ readonly settingsOverrides?: Parameters<typeof ServerSettingsService.layerTest>[0];76+ /** Cached VCS status handed to peekStatus; null = nothing cached. */77+ readonly peekStatus?: Parameters<(typeof VcsStatusBroadcaster)["of"]>[0]["peekStatus"];78+ /** Live refreshStatus result; unset = the sweep must not go live. */79+ readonly refreshStatus?: Parameters<(typeof VcsStatusBroadcaster)["of"]>[0]["refreshStatus"];
- apps/server/src/orchestration/projector.ts line 777Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -748,3 +761,9 @@748761 assistantMessageId: latestCheckpoint.assistantMessageId,749762 };750763764+ // Recompute the stamp from the retained messages: a revert that765+ // removes the newest user message must not leave the decider766+ // seeing it as still queued (blocking settle/snooze) or backdate767+ // settledAt to reverted-away work.768+ let latestUserMessageAt: string | null = null;769+ for (const message of messages) {
- packages/contracts/src/settings.ts line 180Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -176,4 +176,3 @@176176 // old keys, so everyone, including prior beta opt-outs, resets to the new177177 // default sidebar.178178 legacySidebarEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),179- sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
- apps/server/src/orchestration/ThreadAutoSettleReactor.ts line 160OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +140,21 @@140+ const mayVerify = yield* Ref.modify(lastPrVerifyAtByCwd, (byCwd) => {141+ const lastAt = byCwd.get(thread.cwd);142+ if (lastAt !== undefined && now - lastAt < prVerifyCooldownMs) {143+ return [false, byCwd] as const;144+ }145+ const next = new Map(byCwd);146+ next.set(thread.cwd, now);147+ return [true, next] as const;148+ });149+ if (!mayVerify) return { state: "unknown", verified: false };150+ const status = yield* vcsStatusBroadcaster.refreshStatus(thread.cwd).pipe(151+ Effect.catch((error) =>152+ Effect.logDebug("thread.auto-settle.pr-verify-failed", {153+ cwd: thread.cwd,154+ error,155+ }).pipe(Effect.as(null)),156+ ),157+ );158+ if (status === null) return { state: "unknown", verified: true };159+ if (status.refName !== thread.branch) return { state: "none", verified: true };160+ return { state: status.pr?.state ?? "none", verified: true };
- @@ -397,3 +397,8 @@397397 pinOrderKey: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),398398 // Pending-only state. Optional so older servers remain compatible.399399 titleRegeneration: Schema.optional(Schema.NullOr(ThreadTitleRegeneration)),400+ // Newest user-message time, survives the capped/unhydrated `messages`401+ // array: the engine's command read model boots threads with no message402+ // bodies, and the decider needs this stamp for settle invariants and the403+ // settledAt derivation. Optional for pre-existing payloads.404+ latestUserMessageAt: Schema.optional(Schema.NullOr(IsoDateTime)),
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share