Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3174.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`bot_schedules` now lists a Bot's live scheduled tasks before the ones with no next run, so a paused task or a finished one-shot no longer sits at the top of the list ([#3174](https://github.com/ThinkFlowLab/FlyBot/issues/3174)).
6 changes: 5 additions & 1 deletion core/src/host/schedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,17 @@ export function install(rt) {
if (at?.botId !== botId) return
rows.push({
at: when ?? '',
live: status === 'active' && when !== undefined,
line: `- "${entry.title ?? 'untitled'}" (${entry.id}) — ${status === 'active' && when !== undefined ? `next ${when}` : 'no next run'}, ${status}, ${at.place}, session ${entry.sessionId}`,
})
}
for (const entry of await service.catalog()) add(entry, entry.status ?? 'active', entry.scheduledAt)
for (const entry of Object.values(paused())) add({ ...entry.record, id: entry.id, sessionId: entry.sessionId }, 'paused', undefined)
if (rows.length === 0) return `${head}\nnone — no scheduled task in any of its Sessions, so this is the whole list for the Bot.`
rows.sort((a, b) => a.at.localeCompare(b.at) || a.line.localeCompare(b.line))
// A live row comes first, then the rows with no next run (#3174): sorting on the instant
// alone put every dead row above the tasks still due, because a paused row has none and a
// finished one-shot keeps a past one (#2767). Each group keeps instant order inside itself.
rows.sort((a, b) => (a.live === b.live ? 0 : a.live ? -1 : 1) || a.at.localeCompare(b.at) || a.line.localeCompare(b.line))
return [head, ...rows.map(row => row.line)].join('\n')
},
}))
Expand Down
24 changes: 24 additions & 0 deletions core/test/schedules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,30 @@ test('#2767: an inactive task prints no next run, and an active one keeps its li
assert.ok(answer.includes('- "Live brief" (s-live) — next 2030-01-01T01:00:00.000Z, active, own chat, session w2'), answer)
})

// #3174: a row with no next run is not what the reader opens this list for. The sort key was the
// instant, and a dead row has none (paused) or keeps a past one (a finished one-shot, #2767), so
// both landed above every live task. A live row comes first; the dead ones keep their own order
// after it, because they are still the Bot's tasks and still have to be listed.
test('#3174: a row with no next run sorts after every live row', async (t) => {
const schedule = scheduleService()
const team = JSON.parse(JSON.stringify(TEAM))
team.pausedSchedules = { 's-paused': { id: 's-paused', sessionId: 'w2', record: { title: 'Paused brief', prompt: 'Sum up' }, pausedAt: 6 } }
const { ctx, home } = setup({ schedule }, team)
t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })
const task = (id, title, status, scheduledAt) => schedule.tasks.set(id, { sessionId: 'w2', status, record: { id, title, prompt: `${title} prompt`, scheduledAt } })
task('s-done', 'Finished one-shot', 'inactive', '2026-10-29T07:20:46.458Z')
task('s-live', 'Live brief', 'active', '2030-01-01T01:00:00.000Z')
const answer = await ctx.registeredTools.get('bot_schedules').execute({}, { agent: { id: 'w2' } })
const at = name => answer.indexOf(`- "${name}"`)
assert.ok(at('Live brief') >= 0 && at('Finished one-shot') >= 0 && at('Paused brief') >= 0, answer)
assert.ok(at('Live brief') < at('Finished one-shot'), `a live row comes before a finished one:\n${answer}`)
assert.ok(at('Live brief') < at('Paused brief'), `a live row comes before a paused one:\n${answer}`)
// The field each line carries is unchanged: only the order moves.
assert.ok(answer.includes('- "Live brief" (s-live) — next 2030-01-01T01:00:00.000Z, active, own chat, session w2'), answer)
assert.ok(answer.includes('- "Finished one-shot" (s-done) — no next run, inactive, own chat, session w2'), answer)
assert.ok(answer.includes('- "Paused brief" (s-paused) — no next run, paused, own chat, session w2'), answer)
})

// #1321: two owners on one host. `copyFrom` and `schedule-update` resolve a source Session the
// way the page does, and the host knowing that Session is not the caller being allowed to read
// its task: a copy or an edit may only touch a task of the caller's own user.
Expand Down
4 changes: 2 additions & 2 deletions docs/subsystems/core-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ DSH 0.2 offers the schedule service only through its optional bundle `@deepseek-

DSH's own `schedule_list` answers for the Session the call runs in, and its `[]` is indistinguishable from "this Bot has nothing scheduled": a task the owner sees in the UI is invisible from another Session of the same Bot. On 2026-10-21 that produced a written claim that a live schedule had never existed, and it came close to a Bot "cleaning up" a timer it could not see.

- **`bot_schedules`** (no arguments) answers for the calling Bot. It reads the host-wide `catalog()` and keeps the Sessions that speak for it: its own chat (`chatOwners`), the archived parts of it (`pastOwners` with no `roomId`), its group Sessions, live and archived (`groupOwners` / `pastOwners` with a `roomId`, named by the group chat), and a **group chat's own Session** — the group's tasks live on the room's Session id, kept when the calling Bot is in `room.members`, so every member (the admin too) sees them and a Bot outside the group does not. Its paused tasks come from `state.pausedSchedules`, including those on the group's own Session. Each line carries the id, the title, the next run, the state and the owning Session; the answer says in so many words that it is Bot-wide and that `schedule_list` is per Session, so an empty answer cannot be read as a claim about another Session. Only an `active` row has a next run: a row with any other status prints `no next run` even though DSH keeps the instant it was once due there, because a finished one-shot otherwise advertised a moment that had already passed while the settings page on the same data said `Finished` (#2767); the kept instant still sorts the row, so the order does not move.
- **`bot_schedules`** (no arguments) answers for the calling Bot. It reads the host-wide `catalog()` and keeps the Sessions that speak for it: its own chat (`chatOwners`), the archived parts of it (`pastOwners` with no `roomId`), its group Sessions, live and archived (`groupOwners` / `pastOwners` with a `roomId`, named by the group chat), and a **group chat's own Session** — the group's tasks live on the room's Session id, kept when the calling Bot is in `room.members`, so every member (the admin too) sees them and a Bot outside the group does not. Its paused tasks come from `state.pausedSchedules`, including those on the group's own Session. Each line carries the id, the title, the next run, the state and the owning Session; the answer says in so many words that it is Bot-wide and that `schedule_list` is per Session, so an empty answer cannot be read as a claim about another Session. Only an `active` row has a next run: a row with any other status prints `no next run` even though DSH keeps the instant it was once due there, because a finished one-shot otherwise advertised a moment that had already passed while the settings page on the same data said `Finished` (#2767). A live row sorts first and a row with no next run comes after every live one, so a paused task or a finished one-shot cannot sit above the tasks still due; inside each group the stored instants order the rows.
- **Read-only, and it changes nothing about the scoping of the rest.** `schedule_create` / `schedule_update` / `schedule_delete` and DSH's own tools keep their session rule; the tool adds a way to *see* the Bot's tasks, not a way to edit them without knowing the Session.
- Tests: `core/test/schedules.test.js` (`#628: bot_schedules answers for the Bot…`, the group-chat-own-Session cases, the service-off and empty-list cases, and the inactive-versus-active next-run case of #2767).
- Tests: `core/test/schedules.test.js` (`#628: bot_schedules answers for the Bot…`, the group-chat-own-Session cases, the service-off and empty-list cases, the inactive-versus-active next-run case of #2767, and the live-rows-first ordering case).

### Scheduled tasks: edit, pause, missed runs (#354)

Expand Down
34 changes: 31 additions & 3 deletions patches/ds-bot/0001-core-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8309,7 +8309,7 @@ diff --git a/src/host/schedules.js b/src/host/schedules.js
}
if (typeof ctx.inject === 'function') ctx.inject(['schedule'], attach)
else if (ctx.get?.('schedule') !== undefined) attach({ schedule: ctx.get('schedule'), effect: (execute, label) => ctx.effect(execute, label) })
@@ -89,63 +89,630 @@ export function install(rt) {
@@ -89,63 +89,634 @@ export function install(rt) {
return rt.groupOwners.get(sessionId) ?? rt.pastOwners.get(sessionId)
}
const known = owner => owner !== undefined && (owner.botId === undefined ? state.rooms[owner.roomId] !== undefined : state.bots[owner.botId] !== undefined)
Expand Down Expand Up @@ -8835,13 +8835,17 @@ diff --git a/src/host/schedules.js b/src/host/schedules.js
+ if (at?.botId !== botId) return
+ rows.push({
+ at: when ?? '',
+ live: status === 'active' && when !== undefined,
+ line: `- "${entry.title ?? 'untitled'}" (${entry.id}) — ${status === 'active' && when !== undefined ? `next ${when}` : 'no next run'}, ${status}, ${at.place}, session ${entry.sessionId}`,
+ })
+ }
+ for (const entry of await service.catalog()) add(entry, entry.status ?? 'active', entry.scheduledAt)
+ for (const entry of Object.values(paused())) add({ ...entry.record, id: entry.id, sessionId: entry.sessionId }, 'paused', undefined)
+ if (rows.length === 0) return `${head}\nnone — no scheduled task in any of its Sessions, so this is the whole list for the Bot.`
+ rows.sort((a, b) => a.at.localeCompare(b.at) || a.line.localeCompare(b.line))
+ // A live row comes first, then the rows with no next run (#3174): sorting on the instant
+ // alone put every dead row above the tasks still due, because a paused row has none and a
+ // finished one-shot keeps a past one (#2767). Each group keeps instant order inside itself.
+ rows.sort((a, b) => (a.live === b.live ? 0 : a.live ? -1 : 1) || a.at.localeCompare(b.at) || a.line.localeCompare(b.line))
+ return [head, ...rows.map(row => row.line)].join('\n')
+ },
+ }))
Expand Down Expand Up @@ -15841,7 +15845,7 @@ diff --git a/test/schedules.test.js b/test/schedules.test.js
test('a group chat task lives on the group Session and lists under the group', async (t) => {
const schedule = scheduleService()
const { ctx, home, call } = setup({ schedule })
@@ -121,3 +121,961 @@ test('a due reminder reaches a group as its prompts', () => {
@@ -121,3 +121,985 @@ test('a due reminder reaches a group as its prompts', () => {
assert.equal(reminderText(batch), '[Scheduled task] One\n[Scheduled task] Two')
assert.equal(reminderText('plain text'), 'plain text')
})
Expand Down Expand Up @@ -16449,6 +16453,30 @@ diff --git a/test/schedules.test.js b/test/schedules.test.js
+ assert.ok(answer.includes('- "Live brief" (s-live) — next 2030-01-01T01:00:00.000Z, active, own chat, session w2'), answer)
+})
+
+// #3174: a row with no next run is not what the reader opens this list for. The sort key was the
+// instant, and a dead row has none (paused) or keeps a past one (a finished one-shot, #2767), so
+// both landed above every live task. A live row comes first; the dead ones keep their own order
+// after it, because they are still the Bot's tasks and still have to be listed.
+test('#3174: a row with no next run sorts after every live row', async (t) => {
+ const schedule = scheduleService()
+ const team = JSON.parse(JSON.stringify(TEAM))
+ team.pausedSchedules = { 's-paused': { id: 's-paused', sessionId: 'w2', record: { title: 'Paused brief', prompt: 'Sum up' }, pausedAt: 6 } }
+ const { ctx, home } = setup({ schedule }, team)
+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })
+ const task = (id, title, status, scheduledAt) => schedule.tasks.set(id, { sessionId: 'w2', status, record: { id, title, prompt: `${title} prompt`, scheduledAt } })
+ task('s-done', 'Finished one-shot', 'inactive', '2026-10-29T07:20:46.458Z')
+ task('s-live', 'Live brief', 'active', '2030-01-01T01:00:00.000Z')
+ const answer = await ctx.registeredTools.get('bot_schedules').execute({}, { agent: { id: 'w2' } })
+ const at = name => answer.indexOf(`- "${name}"`)
+ assert.ok(at('Live brief') >= 0 && at('Finished one-shot') >= 0 && at('Paused brief') >= 0, answer)
+ assert.ok(at('Live brief') < at('Finished one-shot'), `a live row comes before a finished one:\n${answer}`)
+ assert.ok(at('Live brief') < at('Paused brief'), `a live row comes before a paused one:\n${answer}`)
+ // The field each line carries is unchanged: only the order moves.
+ assert.ok(answer.includes('- "Live brief" (s-live) — next 2030-01-01T01:00:00.000Z, active, own chat, session w2'), answer)
+ assert.ok(answer.includes('- "Finished one-shot" (s-done) — no next run, inactive, own chat, session w2'), answer)
+ assert.ok(answer.includes('- "Paused brief" (s-paused) — no next run, paused, own chat, session w2'), answer)
+})
+
+// #1321: two owners on one host. `copyFrom` and `schedule-update` resolve a source Session the
+// way the page does, and the host knowing that Session is not the caller being allowed to read
+// its task: a copy or an edit may only touch a task of the caller's own user.
Expand Down
Loading