Skip to content

Commit 0406e66

Browse files
xialongleesteipete
andauthored
fix(ui): keep stable chat rows in insertion order and only sort live tool/stream items by timestamp (#113266)
* fix(ui): keep stable chat rows in insertion order and only sort live tool/stream items by timestamp * fix(ui): keep live rows within current turn * fix(ui): keep current work above queued turns * fix(ui): keep streamed replies above queued turns * fix(ui): preserve reconnecting run order * fix(ui): preserve causal terminal ordering * fix(ui): bound replay rows to owning turns * fix(ui): keep question summaries in owning turns * fix(ui): scope question run ownership to session * fix(ui): restore reconnecting chat run identity * fix(ui): remove unused chatItemTimestamp import in chat-thread-build.ts * fix(ui): correlate question summaries with agent runs Co-authored-by: Peter Lee <[email protected]> * chore(i18n): refresh native source baseline Co-authored-by: Peter Lee <[email protected]> * fix(ui): remove unused chatItemTimestamp export and split tool-stream test file --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent be50034 commit 0406e66

36 files changed

Lines changed: 1771 additions & 923 deletions

‎apps/.i18n/native-source.json‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40211,111 +40211,111 @@
4021140211
},
4021240212
{
4021340213
"kind": "ui-localized-call",
40214-
"line": 256,
40214+
"line": 261,
4021540215
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4021640216
"source": "Answered",
4021740217
"surface": "apple",
4021840218
"id": "native.apple.ce899320a84d4086"
4021940219
},
4022040220
{
4022140221
"kind": "ui-localized-call",
40222-
"line": 259,
40222+
"line": 264,
4022340223
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4022440224
"source": "Answered elsewhere",
4022540225
"surface": "apple",
4022640226
"id": "native.apple.f019b6a07d5a33d8"
4022740227
},
4022840228
{
4022940229
"kind": "ui-localized-call",
40230-
"line": 261,
40230+
"line": 266,
4023140231
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4023240232
"source": "Skipped",
4023340233
"surface": "apple",
4023440234
"id": "native.apple.ebdedeffad570c43"
4023540235
},
4023640236
{
4023740237
"kind": "ui-localized-call",
40238-
"line": 263,
40238+
"line": 268,
4023940239
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4024040240
"source": "Expired",
4024140241
"surface": "apple",
4024240242
"id": "native.apple.8dde2eaaf6b0dfa9"
4024340243
},
4024440244
{
4024540245
"kind": "ui-localized-call",
40246-
"line": 265,
40246+
"line": 270,
4024740247
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4024840248
"source": "Unavailable",
4024940249
"surface": "apple",
4025040250
"id": "native.apple.6dff9e9194347f3b"
4025140251
},
4025240252
{
4025340253
"kind": "ui-localized-call",
40254-
"line": 267,
40254+
"line": 272,
4025540255
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4025640256
"source": "Pending",
4025740257
"surface": "apple",
4025840258
"id": "native.apple.b34cd890366824f0"
4025940259
},
4026040260
{
4026140261
"kind": "ui-modifier",
40262-
"line": 361,
40262+
"line": 366,
4026340263
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4026440264
"source": "Question summary",
4026540265
"surface": "apple",
4026640266
"id": "native.apple.b97da55b7e16e60c"
4026740267
},
4026840268
{
4026940269
"kind": "ui-call",
40270-
"line": 375,
40270+
"line": 380,
4027140271
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4027240272
"source": "Other answer",
4027340273
"surface": "apple",
4027440274
"id": "native.apple.da4494f9e875169d"
4027540275
},
4027640276
{
4027740277
"kind": "conditional-branch",
40278-
"line": 433,
40278+
"line": 438,
4027940279
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4028040280
"source": "Not selected",
4028140281
"surface": "apple",
4028240282
"id": "native.apple.e9c3855562d8e4e9"
4028340283
},
4028440284
{
4028540285
"kind": "conditional-branch",
40286-
"line": 433,
40286+
"line": 438,
4028740287
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4028840288
"source": "Selected",
4028940289
"surface": "apple",
4029040290
"id": "native.apple.bd4335213464d4be"
4029140291
},
4029240292
{
4029340293
"kind": "ui-call",
40294-
"line": 450,
40294+
"line": 455,
4029540295
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4029640296
"source": "Skipping…",
4029740297
"surface": "apple",
4029840298
"id": "native.apple.1bbbbfd1ad3842ce"
4029940299
},
4030040300
{
4030140301
"kind": "ui-call",
40302-
"line": 453,
40302+
"line": 458,
4030340303
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4030440304
"source": "Skip",
4030540305
"surface": "apple",
4030640306
"id": "native.apple.14a4bf7b6b7d40dc"
4030740307
},
4030840308
{
4030940309
"kind": "ui-call",
40310-
"line": 464,
40310+
"line": 469,
4031140311
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4031240312
"source": "Submitting…",
4031340313
"surface": "apple",
4031440314
"id": "native.apple.6c1adc16e0a846e5"
4031540315
},
4031640316
{
4031740317
"kind": "ui-call",
40318-
"line": 467,
40318+
"line": 472,
4031940319
"path": "apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift",
4032040320
"source": "Submit",
4032140321
"surface": "apple",

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ data class QuestionRecord(
101101
val questions: List<Question>,
102102
val agentId: String? = null,
103103
val sessionKey: String? = null,
104+
val runId: String? = null,
104105
val createdAtMs: Long,
105106
val expiresAtMs: Long,
106107
val status: String,

‎apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatQuestionCard.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public final class OpenClawQuestionCardModel: Identifiable {
5757
questions: record.questions,
5858
agentid: record.agentid,
5959
sessionkey: record.sessionkey,
60+
runid: record.runid,
6061
createdatms: record.createdatms,
6162
expiresatms: record.expiresatms,
6263
status: record.status,
@@ -161,6 +162,7 @@ public final class OpenClawQuestionCardModel: Identifiable {
161162
questions: self.record.questions,
162163
agentid: self.record.agentid,
163164
sessionkey: self.record.sessionkey,
165+
runid: self.record.runid,
164166
createdatms: self.record.createdatms,
165167
expiresatms: self.record.expiresatms,
166168
status: .answered,
@@ -178,6 +180,7 @@ public final class OpenClawQuestionCardModel: Identifiable {
178180
questions: self.record.questions,
179181
agentid: self.record.agentid,
180182
sessionkey: self.record.sessionkey,
183+
runid: self.record.runid,
181184
createdatms: self.record.createdatms,
182185
expiresatms: self.record.expiresatms,
183186
status: .cancelled,
@@ -195,6 +198,7 @@ public final class OpenClawQuestionCardModel: Identifiable {
195198
questions: self.record.questions,
196199
agentid: self.record.agentid,
197200
sessionkey: self.record.sessionkey,
201+
runid: self.record.runid,
198202
createdatms: self.record.createdatms,
199203
expiresatms: self.record.expiresatms,
200204
status: .answered,
@@ -222,6 +226,7 @@ public final class OpenClawQuestionCardModel: Identifiable {
222226
questions: self.record.questions,
223227
agentid: self.record.agentid,
224228
sessionkey: self.record.sessionkey,
229+
runid: self.record.runid,
225230
createdatms: self.record.createdatms,
226231
expiresatms: self.record.expiresatms,
227232
status: resolved.status,

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15451,6 +15451,7 @@ public struct QuestionRecord: Codable, Sendable {
1545115451
public let questions: [Question]
1545215452
public let agentid: String?
1545315453
public let sessionkey: String?
15454+
public let runid: String?
1545415455
public let createdatms: Int
1545515456
public let expiresatms: Int
1545615457
public let status: QuestionStatus
@@ -15462,6 +15463,7 @@ public struct QuestionRecord: Codable, Sendable {
1546215463
questions: [Question],
1546315464
agentid: String? = nil,
1546415465
sessionkey: String? = nil,
15466+
runid: String? = nil,
1546515467
createdatms: Int,
1546615468
expiresatms: Int,
1546715469
status: QuestionStatus,
@@ -15472,6 +15474,7 @@ public struct QuestionRecord: Codable, Sendable {
1547215474
self.questions = questions
1547315475
self.agentid = agentid
1547415476
self.sessionkey = sessionkey
15477+
self.runid = runid
1547515478
self.createdatms = createdatms
1547615479
self.expiresatms = expiresatms
1547715480
self.status = status
@@ -15484,6 +15487,7 @@ public struct QuestionRecord: Codable, Sendable {
1548415487
case questions
1548515488
case agentid = "agentId"
1548615489
case sessionkey = "sessionKey"
15490+
case runid = "runId"
1548715491
case createdatms = "createdAtMs"
1548815492
case expiresatms = "expiresAtMs"
1548915493
case status
@@ -15497,19 +15501,22 @@ public struct QuestionRequestParams: Codable, Sendable {
1549715501
public let questions: [QuestionRequestQuestion]
1549815502
public let agentid: String?
1549915503
public let sessionkey: String?
15504+
public let runid: String?
1550015505
public let timeoutms: Int?
1550115506

1550215507
public init(
1550315508
id: String? = nil,
1550415509
questions: [QuestionRequestQuestion],
1550515510
agentid: String? = nil,
1550615511
sessionkey: String? = nil,
15512+
runid: String? = nil,
1550715513
timeoutms: Int? = nil)
1550815514
{
1550915515
self.id = id
1551015516
self.questions = questions
1551115517
self.agentid = agentid
1551215518
self.sessionkey = sessionkey
15519+
self.runid = runid
1551315520
self.timeoutms = timeoutms
1551415521
}
1551515522

@@ -15518,6 +15525,7 @@ public struct QuestionRequestParams: Codable, Sendable {
1551815525
case questions
1551915526
case agentid = "agentId"
1552015527
case sessionkey = "sessionKey"
15528+
case runid = "runId"
1552115529
case timeoutms = "timeoutMs"
1552215530
}
1552315531
}

‎apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatQuestionCardTests.swift‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ private func questionRecord(
1010
createdAtMs: Int = 1_000_000,
1111
expiresAtMs: Int = 4_000_000_000_000,
1212
status: QuestionStatus = .pending,
13-
answers: QuestionAnswers? = nil) -> QuestionRecord
13+
answers: QuestionAnswers? = nil,
14+
runId: String? = "run-question") -> QuestionRecord
1415
{
1516
QuestionRecord(
1617
id: "ask_123",
@@ -28,6 +29,7 @@ private func questionRecord(
2829
],
2930
agentid: "main",
3031
sessionkey: "agent:main:main",
32+
runid: runId,
3133
createdatms: createdAtMs,
3234
expiresatms: expiresAtMs,
3335
status: status,
@@ -126,6 +128,29 @@ private func questionRecord(
126128
#expect(model.terminalSummaryText(for: model.record.questions[0]) == "Pizza")
127129
}
128130

131+
@MainActor
132+
@Test func `question card preserves run identity across local terminal records`() {
133+
let answered = OpenClawQuestionCardModel(record: questionRecord())
134+
answered.markAnsweredLocally(answers: ["meal": ["Pizza"]])
135+
#expect(answered.record.runid == "run-question")
136+
137+
let skipped = OpenClawQuestionCardModel(record: questionRecord())
138+
skipped.markSkippedLocally()
139+
#expect(skipped.record.runid == "run-question")
140+
141+
let elsewhere = OpenClawQuestionCardModel(record: questionRecord())
142+
elsewhere.markAnsweredElsewhere()
143+
#expect(elsewhere.record.runid == "run-question")
144+
145+
let resolved = OpenClawQuestionCardModel(record: questionRecord())
146+
resolved.apply(resolved: .init(id: resolved.id, status: .answered))
147+
#expect(resolved.record.runid == "run-question")
148+
149+
let refreshed = OpenClawQuestionCardModel(record: questionRecord(answers: .init(answers: [:])))
150+
#expect(refreshed.apply(record: questionRecord(status: .answered, runId: "run-refresh")))
151+
#expect(refreshed.record.runid == "run-refresh")
152+
}
153+
129154
@MainActor
130155
@Test func `question card locally expired state remains terminal`() {
131156
let expiresAt = Date(timeIntervalSince1970: 1500)

‎docs/tools/ask-user.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ If the question expires or is cancelled before an answer arrives, the tool
5353
returns `status: "no_answer"`. The agent then continues with its best judgment.
5454
An aborted agent run cancels its pending Gateway question.
5555

56+
Gateway question records include the optional originating `runId`. Clients can
57+
use it to keep the prompt and its terminal answer summary with the correct agent
58+
turn, including after reconnecting and recovering the question with
59+
`question.list` or `question.get`.
60+
5661
## Tool schema
5762

5863
```ts

‎extensions/codex/src/app-server/user-input-bridge.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export function createCodexUserInputBridge(params: {
140140
questions: requestParams.questions,
141141
sessionKey: params.paramsForRun.sessionKey ?? params.paramsForRun.sessionId,
142142
agentId: params.paramsForRun.agentId,
143+
runId: params.paramsForRun.runId,
143144
timeoutMs:
144145
requestParams.autoResolutionMs ??
145146
params.paramsForRun.timeoutMs ??

‎extensions/copilot/src/user-input-bridge.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function createCopilotUserInputBridge(params: {
4444
questions: [question],
4545
sessionKey: params.paramsForRun.sessionKey ?? params.paramsForRun.sessionId,
4646
agentId: params.paramsForRun.agentId,
47+
runId: params.paramsForRun.runId,
4748
timeoutMs: params.paramsForRun.timeoutMs ?? DEFAULT_USER_INPUT_TIMEOUT_MS,
4849
gatewayCall,
4950
delivery: params.paramsForRun,

‎packages/gateway-protocol/src/questions-validators.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { Value } from "typebox/value";
12
import { describe, expect, it } from "vitest";
23
import {
4+
QuestionRecordSchema,
35
validateQuestionRequestParams,
46
validateQuestionResolveParams,
57
validateQuestionWaitAnswerParams,
@@ -21,13 +23,24 @@ describe("question protocol validators", () => {
2123
expect(
2224
validateQuestionRequestParams({
2325
id: "client-question-id",
26+
runId: "agent-run-id",
2427
questions: [question],
2528
timeoutMs: 100,
2629
}),
2730
).toBe(true);
2831
expect(validateQuestionWaitAnswerParams({ id: "question-uuid", timeoutMs: 50 })).toBe(true);
2932
expect(validateQuestionResolveParams({ id: "question-uuid", answers })).toBe(true);
3033
expect(validateQuestionResolveParams({ id: "question-uuid", cancel: true })).toBe(true);
34+
expect(
35+
Value.Check(QuestionRecordSchema, {
36+
id: "client-question-id",
37+
runId: "agent-run-id",
38+
questions: [question],
39+
createdAtMs: 1,
40+
expiresAtMs: 2,
41+
status: "pending",
42+
}),
43+
).toBe(true);
3144
});
3245

3346
it("enforces the shared question header cap", () => {

‎packages/gateway-protocol/src/schema/questions.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const QuestionRecordSchema = closedObject({
5656
questions: Type.Array(QuestionSchema, { minItems: 1, maxItems: 3 }),
5757
agentId: Type.Optional(NonEmptyString),
5858
sessionKey: Type.Optional(NonEmptyString),
59+
runId: Type.Optional(NonEmptyString),
5960
createdAtMs: Type.Integer({ minimum: 0 }),
6061
expiresAtMs: Type.Integer({ minimum: 0 }),
6162
status: QuestionStatusSchema,
@@ -68,6 +69,7 @@ export const QuestionRequestParamsSchema = closedObject({
6869
questions: Type.Array(QuestionRequestQuestionSchema, { minItems: 1, maxItems: 3 }),
6970
agentId: Type.Optional(NonEmptyString),
7071
sessionKey: Type.Optional(NonEmptyString),
72+
runId: Type.Optional(NonEmptyString),
7173
timeoutMs: Type.Optional(Type.Integer({ minimum: 1 })),
7274
});
7375

0 commit comments

Comments
 (0)