Skip to content

Commit 8a7eacc

Browse files
jerryliang64claude
andauthored
fix(agent-runtime): set isResume based on thread message history (#419)
## Summary - 修复 `ensureThread` 中 `isResume` 的判断逻辑:当传入 `threadId` 但 thread 中没有历史消息时(如通过 `createThread` 刚创建的空 thread),`isResume` 应为 `false` - 通过 `store.getThread()` 检查 `thread.messages.length > 0` 来决定 `isResume` 的值 - 更新测试用例,覆盖空 thread 和有历史消息的 thread 两种场景 ## Test plan - [x] 原有测试 "should set isResume=false when no threadId provided" 通过 - [x] 修改测试 "should set isResume=false when threadId provided but thread has no messages" 通过 - [x] 新增测试 "should set isResume=true when threadId provided and thread has messages" 通过 - [x] 全部 104 个测试通过 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c760776 commit 8a7eacc

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

core/agent-runtime/src/AgentRuntime.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ export class AgentRuntime {
8080

8181
private async ensureThread(input: CreateRunInput): Promise<{ threadId: string; input: CreateRunInput }> {
8282
if (input.threadId) {
83-
return { threadId: input.threadId, input: { ...input, isResume: true } };
83+
const thread = await this.store.getThread(input.threadId);
84+
const isResume = thread.messages.length > 0;
85+
return { threadId: input.threadId, input: { ...input, isResume } };
8486
}
8587
const thread = await this.store.createThread();
8688
return { threadId: thread.id, input: { ...input, threadId: thread.id, isResume: false } };

core/agent-runtime/test/AgentRuntime.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe('test/AgentRuntime.test.ts', () => {
249249
assert.equal(capturedInput!.isResume, false);
250250
});
251251

252-
it('should set isResume=true when threadId provided', async () => {
252+
it('should set isResume=false when threadId provided but thread has no messages', async () => {
253253
let capturedInput: CreateRunInput | undefined;
254254
executor.execRun = async function* (input: CreateRunInput): AsyncGenerator<AgentStreamMessage> {
255255
capturedInput = input;
@@ -261,6 +261,26 @@ describe('test/AgentRuntime.test.ts', () => {
261261
threadId: thread.id,
262262
input: { messages: [{ role: 'user', content: 'Hi' }] },
263263
});
264+
assert.equal(capturedInput!.isResume, false);
265+
});
266+
267+
it('should set isResume=true when threadId provided and thread has messages', async () => {
268+
let capturedInput: CreateRunInput | undefined;
269+
executor.execRun = async function* (input: CreateRunInput): AsyncGenerator<AgentStreamMessage> {
270+
capturedInput = input;
271+
yield { message: { role: MessageRole.Assistant, content: [{ type: 'text', text: 'hi' }] } };
272+
};
273+
274+
// First run creates thread with messages
275+
const result = await runtime.syncRun({
276+
input: { messages: [{ role: 'user', content: 'Hi' }] },
277+
});
278+
279+
// Second run on the same thread — now it has history
280+
await runtime.syncRun({
281+
threadId: result.threadId,
282+
input: { messages: [{ role: 'user', content: 'Hello again' }] },
283+
});
264284
assert.equal(capturedInput!.isResume, true);
265285
});
266286

0 commit comments

Comments
 (0)