Contract at server dev 5044168: done is the end of a reply, the chat's name follows
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
The server now sends `done` as soon as the reply is saved and names a new chat afterwards: `done.chat.title_pending`, then one `title` frame before `close` (up to the naming's time limit). - The chat screen finishes the reply at `done` (the row replaced, nothing live, a queued prompt's reply followed at once) and keeps the stream only for the `title` frame, which renames the chat. It used to wait for `close`, which with this server would have left a first reply undrawn for the seconds the naming takes. - The assistant's sheet follows the stream to `done` only, so a spoken answer is read aloud without waiting for the name. - Fixtures: event_done (title_pending), event_done_title_pending, event_title. Tokens and strings are unchanged at this ref. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
10 files changed
+191
-25
No files matched your search
@@ -41,6 +41,10 @@ is in alpha and releases come off `main`.
|
||||
- The approval card offers the spec's four actions: *Allow once*, *Always allow*, *Deny*, and
|
||||
*Deny, and say why*. The plan card approves together with the mode to continue in --
|
||||
*Approve, continue in Edit* or *Approve, continue in Manual* -- and *Revise*.
|
||||
- **A reply ends when it is saved, and the chat's name follows** (with a server that sends `done`
|
||||
first: LLeMbas 2.0.0-beta.11). The app treats `done` as the end -- the transcript, a spoken
|
||||
answer and a queued prompt no longer wait for a model to name a new chat -- and takes the name
|
||||
from the `title` frame when it comes.
|
||||
- **Wake phrases the engine can hear.** "Hey Lembas" is gone: Lembas is not a word the engine's
|
||||
model was ever trained on, so it had to be repeated until it happened to land. The phrase is now
|
||||
a greeting and a name, each chosen in Settings › Wake word: **Hey**, **OK** or **Hello**, then
|
||||
|
||||
@@ -25,7 +25,11 @@ data class LiveReply(
|
||||
val tree: SubagentTree? = null,
|
||||
val metrics: Metrics? = null,
|
||||
val steered: Set<String> = emptySet(),
|
||||
/** Set by `done`: the finished row, which replaces this in the transcript. */
|
||||
/**
|
||||
* Set by `done`: the finished row, which replaces this in the transcript. `done` is the end
|
||||
* of the reply -- the stream may stay open after it for one `title` frame, which nobody
|
||||
* waits for.
|
||||
*/
|
||||
val finished: Message? = null,
|
||||
val title: String? = null,
|
||||
/** A queued prompt the server started when this reply ended: the next stream to follow. */
|
||||
@@ -79,6 +83,9 @@ data class LiveReply(
|
||||
)
|
||||
} ?: this
|
||||
|
||||
// After `done`, when a model has named the chat: the name, and nothing else changes.
|
||||
"title" -> decode(TitleFrame.serializer(), data)?.let { named -> copy(title = named.chat.title.ifEmpty { title }) } ?: this
|
||||
|
||||
"close" -> copy(closed = true)
|
||||
|
||||
else -> this
|
||||
|
||||
@@ -637,10 +637,19 @@ data class JobsFrame(val jobs: List<Job> = emptyList())
|
||||
|
||||
@Serializable
|
||||
data class DoneFrame(val message: Message, val chat: DoneChat = DoneChat(), val next: String? = null) {
|
||||
/**
|
||||
* [titlePending]: a model is still naming the chat, so [title] is the one made from the
|
||||
* prompt and a `title` frame may follow before `close`. `done` is the end of the reply all
|
||||
* the same.
|
||||
*/
|
||||
@Serializable
|
||||
data class DoneChat(val id: String = "", val title: String = "")
|
||||
data class DoneChat(val id: String = "", val title: String = "", @SerialName("title_pending") val titlePending: Boolean = false)
|
||||
}
|
||||
|
||||
/** The `title` frame: the name a model gave the chat, after `done`. */
|
||||
@Serializable
|
||||
data class TitleFrame(val chat: DoneFrame.DoneChat = DoneFrame.DoneChat())
|
||||
|
||||
/** The push payload the server sends (services/push.py), as the app reads it. */
|
||||
@Serializable
|
||||
data class PushPayload(
|
||||
|
||||
@@ -28,6 +28,7 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.transformWhile
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -432,7 +433,12 @@ class AssistController(private val context: Context, private val scope: Coroutin
|
||||
}
|
||||
}
|
||||
var live = LiveReply(replyId)
|
||||
StreamClient(api).follow(inChat, replyId).collect { frame ->
|
||||
// To `done`, which is the end of the reply: the stream may stay open after it for
|
||||
// the chat's name, and a spoken answer must not wait for that.
|
||||
StreamClient(api).follow(inChat, replyId).transformWhile { frame ->
|
||||
emit(frame)
|
||||
frame.event != "done"
|
||||
}.collect { frame ->
|
||||
live = live.apply(frame.event, frame.data)
|
||||
_state.update { s -> s.copy(turns = s.turns.dropLast(1) + turn.copy(reply = live), busy = live.finished == null) }
|
||||
}
|
||||
|
||||
@@ -279,17 +279,47 @@ class ChatViewModel(app: Application) :
|
||||
following?.cancel()
|
||||
following = viewModelScope.launch {
|
||||
_state.update { it.copy(live = LiveReply(messageId)) }
|
||||
// Set at `done`, which is the end of the reply: from then on the stream is followed
|
||||
// only for the name a model may still give the chat (the `title` frame).
|
||||
var ended: LiveReply? = null
|
||||
try {
|
||||
StreamClient(api()).follow(chat.id, messageId).collect { frame ->
|
||||
_state.update { s ->
|
||||
val live = (s.live ?: LiveReply(messageId)).apply(frame.event, frame.data)
|
||||
val before = ended
|
||||
if (before != null) {
|
||||
val named = before.apply(frame.event, frame.data)
|
||||
ended = named
|
||||
if (named.title != before.title) _state.update { s -> s.copy(chat = s.chat?.let { c -> named.title?.let { c.copy(title = it) } ?: c }) }
|
||||
return@collect
|
||||
}
|
||||
val live = (_state.value.live ?: LiveReply(messageId)).apply(frame.event, frame.data)
|
||||
val finished = live.finished
|
||||
if (finished == null) {
|
||||
// The tree outlives the reply: kept for the activity sheet once it ends.
|
||||
s.copy(live = live, tree = live.tree ?: s.tree)
|
||||
_state.update { s -> s.copy(live = live, tree = live.tree ?: s.tree) }
|
||||
return@collect
|
||||
}
|
||||
ended = live
|
||||
_state.update { s ->
|
||||
s.copy(
|
||||
live = null,
|
||||
tree = live.tree ?: s.tree,
|
||||
messages = s.messages.map { if (it.id == finished.id) finished else it },
|
||||
chat = s.chat?.let { c -> live.title?.let { c.copy(title = it) } ?: c },
|
||||
)
|
||||
}
|
||||
// The queue handed a waiting prompt to a fresh reply: the transcript has moved
|
||||
// on the server, so it is read again rather than patched -- and that reply is
|
||||
// followed instead of this stream's tail.
|
||||
live.next?.let { next ->
|
||||
refresh()
|
||||
follow(next)
|
||||
}
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
// After `done` only the name was still to come: nothing to say, nothing to redo.
|
||||
if (ended != null) return@launch
|
||||
fail(e)
|
||||
// The reply goes on on the server; what it has written so far is read back
|
||||
// rather than left half-drawn.
|
||||
@@ -297,21 +327,8 @@ class ChatViewModel(app: Application) :
|
||||
refresh()
|
||||
return@launch
|
||||
}
|
||||
val ended = _state.value.live
|
||||
_state.update { s ->
|
||||
val finished = ended?.finished
|
||||
s.copy(
|
||||
live = null,
|
||||
messages = if (finished != null) s.messages.map { if (it.id == finished.id) finished else it } else s.messages,
|
||||
chat = s.chat?.let { c -> ended?.title?.let { c.copy(title = it) } ?: c },
|
||||
)
|
||||
}
|
||||
// The queue handed a waiting prompt to a fresh reply: the transcript has moved on
|
||||
// the server, so it is read again rather than patched.
|
||||
ended?.next?.let { next ->
|
||||
refresh()
|
||||
follow(next)
|
||||
}
|
||||
// The stream closed without a `done` (an older reply already gone): nothing is live.
|
||||
if (ended == null) _state.update { it.copy(live = null) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import eu.llembas.android.api.SteeredFrame
|
||||
import eu.llembas.android.api.StepsFrame
|
||||
import eu.llembas.android.api.SubagentTranscript
|
||||
import eu.llembas.android.api.Tail
|
||||
import eu.llembas.android.api.TitleFrame
|
||||
import eu.llembas.android.api.ToolCall
|
||||
import eu.llembas.android.api.TreeFrame
|
||||
import eu.llembas.android.api.TreeView
|
||||
@@ -315,6 +316,26 @@ class ContractTest {
|
||||
assertEquals("Waybread", read("event_done", DoneFrame.serializer()).chat.title)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun doneIsTheEndAndTheChatsNameMayFollow() {
|
||||
// A new chat's first reply: saved and done at once, under the name made from the prompt.
|
||||
val pending = read("event_done_title_pending", DoneFrame.serializer())
|
||||
assertTrue(pending.chat.titlePending)
|
||||
assertEquals("How is lembas made?", pending.chat.title)
|
||||
assertFalse(read("event_done", DoneFrame.serializer()).chat.titlePending)
|
||||
var live = LiveReply("msg2").apply("done", text("event_done_title_pending"))
|
||||
assertNotNull(live.finished)
|
||||
assertEquals("How is lembas made?", live.title)
|
||||
assertFalse(live.closed)
|
||||
// Then, if a model names it before the stream closes, one `title` frame: only the name changes.
|
||||
val finished = live.finished
|
||||
live = live.apply("title", text("event_title"))
|
||||
assertEquals("Waybread", live.title)
|
||||
assertEquals(finished, live.finished)
|
||||
assertEquals("chat1", read("event_title", TitleFrame.serializer()).chat.id)
|
||||
assertTrue(live.apply("close", text("event_close")).closed)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aWholeStreamBuildsAReply() {
|
||||
var live = LiveReply("msg2")
|
||||
|
||||
@@ -88,7 +88,8 @@
|
||||
},
|
||||
"chat": {
|
||||
"id": "chat1",
|
||||
"title": "Waybread"
|
||||
"title": "Waybread",
|
||||
"title_pending": false
|
||||
},
|
||||
"next": null
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"message": {
|
||||
"id": "msg2",
|
||||
"role": "assistant",
|
||||
"created_at": "2026-01-02T03:04:05+00:00",
|
||||
"complete": true,
|
||||
"stopped": false,
|
||||
"error": null,
|
||||
"queued": false,
|
||||
"machine": false,
|
||||
"origin": "",
|
||||
"model": "qwen",
|
||||
"attachments": [],
|
||||
"steps": [
|
||||
{
|
||||
"index": 0,
|
||||
"kind": "thinking",
|
||||
"open": false,
|
||||
"text": "The reader wants a recipe.",
|
||||
"label": "for 1 second · 6 tokens"
|
||||
},
|
||||
{
|
||||
"index": 0,
|
||||
"kind": "text",
|
||||
"open": false,
|
||||
"markdown": "Here is how it is made:\n\n```sh\nbake --slow\n```\n"
|
||||
},
|
||||
{
|
||||
"index": 0,
|
||||
"kind": "tools",
|
||||
"open": false,
|
||||
"calls": [
|
||||
{
|
||||
"id": "call1",
|
||||
"name": "bash",
|
||||
"kind": "shell",
|
||||
"status": "ok",
|
||||
"args": {
|
||||
"command": "bake --slow"
|
||||
},
|
||||
"purpose": "Bake one loaf",
|
||||
"text": "baked\n",
|
||||
"exit": 0,
|
||||
"block": {
|
||||
"kind": "shell",
|
||||
"title": "bake --slow",
|
||||
"chips": [
|
||||
"exit 0"
|
||||
],
|
||||
"added": 0,
|
||||
"removed": 0
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"index": 0,
|
||||
"kind": "steer",
|
||||
"open": false,
|
||||
"messages": [
|
||||
{
|
||||
"id": "msg9",
|
||||
"text": "and add honey"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"index": 1,
|
||||
"kind": "text",
|
||||
"open": false,
|
||||
"markdown": "Done. *Wrap it in a leaf.*"
|
||||
}
|
||||
],
|
||||
"plan": null,
|
||||
"metrics": {
|
||||
"prompt_tokens": 120,
|
||||
"completion_tokens": 40,
|
||||
"total_tokens": 160,
|
||||
"context_tokens": 160,
|
||||
"context_limit": 8192,
|
||||
"estimated": false,
|
||||
"elapsed_ms": 4000,
|
||||
"rounds": 2,
|
||||
"thinking_ms": 1200,
|
||||
"percent": 2,
|
||||
"tok_s": 10.0
|
||||
}
|
||||
},
|
||||
"chat": {
|
||||
"id": "chat1",
|
||||
"title": "How is lembas made?",
|
||||
"title_pending": true
|
||||
},
|
||||
"next": null
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"chat": {
|
||||
"id": "chat1",
|
||||
"title": "Waybread"
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ref": "v2.0.0-beta.10",
|
||||
"commit": "6d1ab36371c8492ee2590fbe25d112d73513a9ae",
|
||||
"sha256": "d82cfc3a93ec70127c6bdff1a1b0f564d4276428ffc6ffb7a66cf13bfe746acd"
|
||||
"ref": "5044168b337309aa52cea6af5ab12b2744896bb5",
|
||||
"commit": "5044168b337309aa52cea6af5ab12b2744896bb5",
|
||||
"sha256": "c417d917e5801e2f6378ee7fbf1d75eb398a4e11ea6f5a03a28554bcbb61e80d"
|
||||
}
|
||||
Reference in new issue
Block a user