fix(jsonrpc): reject prompts for a session whose agent left the registry

After an agent-loop-only reload the server keeps its SessionRecord but the
record's agent is no longer registered. followup() no longer throws for a
detached agent, so a prompt would run against a zombie session and still report
accepted. Validate the record against the live registry before delivery, as the
ACP bridge does. Adds a regression that detaches the agent and asserts rejection.
This commit is contained in:
_Kerman
2026-07-27 02:00:12 +08:00
parent 71152bc4c0
commit 2a969ced21
2 changed files with 50 additions and 5 deletions
+6
View File
@@ -149,6 +149,12 @@ export class HarnessSdkServer {
async prompt(params: SessionPromptParams): Promise<SessionPromptResult> {
const rec = await this.getOrCreateSession(params.sessionId)
if (rec.activePrompt) throw new Error(`session already has an active prompt: ${params.sessionId}`)
// An agent-loop-only reload disposes the loop's agents while this record
// survives; a retained agent accepts followup() silently, so validate the
// record against the live registry before delivery (as the ACP bridge does).
if (this.ctx.agents.get(rec.handle.agent.id) !== rec.handle.agent) {
throw new Error(`session agent was disposed outside the server: ${params.sessionId}`)
}
rec.activePrompt = true
try {
rec.lastTurnEnd = undefined