Skip to content

Open source CapCut alternative.

TypeScript

fix(app): don't fold new turns into stale conversations

David Led4e06e0dce93
diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift
index 45e79908..29042c77 100644
--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift
+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayModel.swift
@@ -1419,8 +1419,8 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {
}
private func followUpCandidates() -> [UserQueryFollowUpCandidate] {
- taskStore
- .loadRecentTasks(limit: Self.followUpCandidateLimit)
+ let recent = taskStore.loadRecentTasks(limit: Self.followUpCandidateLimit)
+ return Self.activeFollowUpCandidates(from: recent, now: Date())
.map { task in
let recentEvents = taskStore
.loadEvents(conversationID: task.id)
@@ -1534,6 +1534,24 @@ final class UserQueryOverlayModel: ObservableObject, UserQueryIntentSink {
/// work the user likely moved on from (and spending credits while they're away) is the wrong default.
private static let autoResumeStalenessWindow: TimeInterval = 30 * 60
+ /// How recently a conversation must have been active to stay eligible as a follow-up target. Implicit
+ /// follow-up routing runs through the typed resolver, but only over conversations touched within this
+ /// window: one left idle longer is treated as closed, so an unrelated later turn starts a fresh
+ /// conversation instead of folding into stale work (observed live: "hi" folding into a day-old
+ /// video-clip task that had never reached a terminal state). This gates eligibility, not selection —
+ /// among eligible candidates the resolver still decides by content, never by recency. An explicit
+ /// Reply or spawn selection bypasses this entirely; the user can always continue an old thread on purpose.
+ private static let followUpStalenessWindow: TimeInterval = 30 * 60
+
+ /// Conversations recent enough to continue with a new turn. Sorted-by-recency input is filtered to the
+ /// staleness window; everything older is considered closed and dropped from the follow-up pool.
+ static func activeFollowUpCandidates(
+ from tasks: [UserQueryConversation],
+ now: Date
+ ) -> [UserQueryConversation] {
+ tasks.filter { now.timeIntervalSince($0.updatedAt) <= followUpStalenessWindow }
+ }
+
/// Maps persisted tasks into their post-relaunch state and collects the IDs to auto-resume. A relaunch
/// tears down every live loop, so an in-flight task can't simply keep running — but one that was
/// actively working moments ago resumes on its own, while staler or user-blocked work comes back as a
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/TaskFollowUpInjectionTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/TaskFollowUpInjectionTests.swift
index 1c40366c..f42d79eb 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/TaskFollowUpInjectionTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/TaskFollowUpInjectionTests.swift
@@ -293,4 +293,36 @@ struct TaskFollowUpInjectionTests {
// The persisted updatedAt is preserved so elapsed-time stays the real run duration.
#expect(result.tasks.first { $0.id == "stale" }?.updatedAt == staleRunning.updatedAt)
}
+
+ @MainActor
+ @Test
+ func activeFollowUpCandidatesDropStaleConversations() {
+ let now = Date()
+ func task(_ id: String, _ status: UserQueryConversationStatus, ageMinutes: Double) -> UserQueryConversation {
+ UserQueryConversation(
+ id: id,
+ title: id,
+ detail: "d",
+ status: status,
+ accentIndex: 0,
+ updatedAt: now.addingTimeInterval(-ageMinutes * 60)
+ )
+ }
+
+ let recentRunning = task("recent-running", .running, ageMinutes: 10)
+ let recentCompleted = task("recent-done", .completed, ageMinutes: 10)
+ let staleRunning = task("stale-running", .running, ageMinutes: 16 * 60)
+ let staleCompleted = task("stale-done", .completed, ageMinutes: 16 * 60)
+
+ let eligible = UserQueryOverlayModel.activeFollowUpCandidates(
+ from: [recentRunning, recentCompleted, staleRunning, staleCompleted],
+ now: now
+ ).map(\.id)
+
+ // Recent conversations stay eligible regardless of terminal state — a just-finished task is a
+ // natural follow-up target. Anything idle past the window is treated as closed and dropped, so an
+ // unrelated later turn starts a fresh conversation instead of folding into stale work (the
+ // day-old never-terminated clip task that swallowed a bare "hi").
+ #expect(eligible == ["recent-running", "recent-done"])
+ }
}
diff --git a/docs/guides/harness-deep-dive.md b/docs/guides/harness-deep-dive.md
index 943aa5c7..40ad183b 100644
--- a/docs/guides/harness-deep-dive.md
+++ b/docs/guides/harness-deep-dive.md
@@ -25,7 +25,9 @@ agent keeps going with one more instruction, the way a queued message works in a
chat. This is deliberately the opposite of changing course, which would replace
the goal and re-plan; a follow-up only ever reaches a stopped task that way.
Whether a request is a follow-up to a specific task is decided by the typed
-follow-up boundary, never by matching the text itself.
+follow-up boundary, never by matching the text itself. Only recently active
+conversations are eligible: one left idle long enough counts as closed, so an
+unrelated later turn opens a fresh task instead of folding into stale work.
**Concurrency.** Each task runs its own loop, and a loop releases control on every
await it makes for the model or a tool, so several tasks advance together. Two