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
2 changes: 1 addition & 1 deletion ds-bot/src/host/prompt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions ds-bot/src/host/turns.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ export function install(rt) {
entry.carried = false
let claimedPending
let claimedPendingText
entry.card = state.questions[id]?.id
if (entry.pending !== undefined) {
claimedPending = entry.pending
claimedPendingText = entry.pendingText
Expand Down Expand Up @@ -1059,7 +1058,6 @@ export function install(rt) {
entry.carry = { info: entry.info, joined: entry.joined ?? [], later: entry.later ?? [], texts: entry.texts.slice(0, cut.texts), shown: entry.shown, answers: entry.answers, toolCount: entry.toolCount ?? 0, origin: entry.origin, originFrom: entry.originFrom, askText: entry.askText, originAt: entry.originAt }
}
const info = entry.info
const turn = entry.turn
const joined = entry.joined ?? []
// What the group already saw of the turn is not posted again.
const texts = entry.texts.slice(entry.shown)
Expand Down Expand Up @@ -1100,8 +1098,6 @@ export function install(rt) {
const later = entry.later ?? []
entry.later = []
if (steerCut || suppressedSubagent) break
const card = entry.card
entry.card = undefined
for (const result of later) {
void rt.deliver({
fromId: result.info.senderSessionId,
Expand Down Expand Up @@ -1166,16 +1162,6 @@ export function install(rt) {
void retryWrittenCall(id, info).catch(error => rt.warn('ds-bot: asking %s to run its written tool call failed: %s', id, error))
}
}
// A finished turn the user could see that asked nothing has moved on, so the card
// it left standing is stale. `card` is the card this turn opened on: a turn that
// asked has another id, or none here at all. A hidden Bot-to-Bot turn shows the user
// nothing, so its card still waits for them. A fresh part's handoff turn carries its
// card over; a failed or stopped turn said nothing about it.
const hidden = (state.exchangeTurns[id] ?? []).includes(turn)
if (card !== undefined && state.questions[id]?.id === card && reason?.kind === 'completed' && !retry && !hidden && info?.handoff !== true) {
delete state.questions[id]
void rt.save().catch(() => {})
}
const replyText = () => {
const reply = (wroteCall ? texts.map(stripWrittenCalls) : texts).join('\n\n').trim()
if (wroteCall && reply === '') return 'Tried to run a tool but wrote the call as text, so it did not run.'
Expand Down
18 changes: 13 additions & 5 deletions ds-bot/test/questions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ test('a card asked in a visible turn stays at its call', async (t) => {
assert.equal((await questions()).writer.callId, 'call-3')
})

// local: question-lifecycle. A card closes once the Bot finishes a later turn the user
// could see that asked nothing; a hidden Bot-to-Bot turn in between leaves it open.
test('a later visible turn that asks nothing closes the card; a hidden one leaves it', async (t) => {
// local: question-lifecycle. A card waits for the user: later turns of the Bot, hidden
// Bot-to-Bot ones and ones the user can see, leave it open; the user's own message closes it.
test('a card survives later Bot turns, hidden or visible, until the user writes', async (t) => {
const { emit, ask, questions, stop } = await start()
t.after(stop)
emit('writer', 'turn/start', { turn: 1 })
Expand All @@ -105,11 +105,19 @@ test('a later visible turn that asks nothing closes the card; a hidden one leave
emit('writer', 'turn/start', { turn: 2 })
emit('writer', 'user/message', { content: text('[Message from Chief]\nstatus? CARD-IT-YOURSELF'), source: { kind: 'bot', role: 'request', senderSessionId: 'chief', senderName: 'Chief', exchangeId: 'x9', hop: 0 } })
emit('writer', 'turn/end', { turn: 2, reason: { kind: 'completed' } })
assert.equal((await questions()).writer?.question, 'Which name?')
assert.equal((await questions()).writer?.question, 'Which name?', 'a hidden Bot-to-Bot turn leaves it open')

emit('writer', 'turn/start', { turn: 3 })
emit('writer', 'user/message', { content: text('never mind, call it Scout'), source: { kind: 'user' } })
emit('writer', 'user/message', { content: text('[Message from Chief · the user sees your reply here]\nReport in'), source: { kind: 'bot', role: 'request', audience: 'user', senderSessionId: 'chief', senderName: 'Chief', exchangeId: 'x10', hop: 0 } })
emit('writer', 'turn/end', { turn: 3, reason: { kind: 'completed' } })
emit('writer', 'turn/start', { turn: 4 })
emit('writer', 'turn/end', { turn: 4, reason: { kind: 'completed' } })
await new Promise(resolve => setTimeout(resolve, 50))
assert.equal((await questions()).writer?.question, 'Which name?', 'turns the user can see that ask nothing leave it open')

emit('writer', 'turn/start', { turn: 5 })
emit('writer', 'user/message', { content: text('never mind, call it Scout'), source: { kind: 'user' } })
emit('writer', 'turn/end', { turn: 5, reason: { kind: 'completed' } })
for (let count = 0; count < 50 && (await questions()).writer !== undefined; count += 1) await new Promise(resolve => setTimeout(resolve, 5))
assert.equal((await questions()).writer, undefined)
})
Expand Down
Loading