Q10: wake tasks no longer carry a truncated copy of the message

Manual re-runs of a chat wake answer the same thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-08 03:36:22 -04:00
1 parent abe9534350
commit 31ab919334
4 files changed
+53 -6

No files matched your search

@@ -665,10 +665,26 @@ export class TaskExecutionService {
providerIds: [provider.id],
scope: "task_run",
credentialAccess: "provider_runtime_only",
...this.chatWakeSource(orgId, task),
}),
};
}
/** A re-run of a chat wake answers the same thread. */
private chatWakeSource(orgId: string, task: TaskExecutionTaskRow): { sourceThreadId: string; sourceMessageId: string } | Record<string, never> {
if (task.origin !== "chat_wake") return {};
const row = this.db.prepare(`
select json_extract(secret_scope_json, '$.sourceThreadId') as thread_id,
json_extract(secret_scope_json, '$.sourceMessageId') as message_id
from task_runs
where task_id = ? and org_id = ? and json_extract(secret_scope_json, '$.sourceThreadId') is not null
order by created_at desc
limit 1
`).get(task.id, orgId) as { thread_id: string; message_id: string } | undefined;
if (!row) throw new Error(`Chat wake task ${task.id} has no recorded source thread.`);
return { sourceThreadId: row.thread_id, sourceMessageId: row.message_id };
}
private requireServiceIdentity(orgId: string, agentId: string): string {
const row = this.db.prepare("select id from service_identities where org_id = ? and agent_id = ?")
.get(orgId, agentId) as { id: string } | undefined;