hand off the work, keep the conversation
kiro-remote is a control plane in my AWS account that lets another agent, over REST and MCP, drive Kiro Web — Kiro coding agent in a cloud sandbox. From a chat with Claude, I hand Kiro a prompt, and seconds or minutes later Kiro has an answer. The question this part of the series is about is who waits for that answer, and where.
Here is the same job twice, a “reply PONG” prompt. First as kiro-remote served it until 26 November:
→ tools/call kiro_send_prompt
{ sessionId, prompt: "Reply PONG", whenBusy: "queue" }
← { turn: { id: "01M8GQZW0JPD…", status: "queued" } }
→ tools/call kiro_wait_for_events { sessionId, after: 0 }
← { events: [ … ], nextCursor: 4, turnStatus: "running" }
→ tools/call kiro_wait_for_events { sessionId, after: 4 }
← { events: [ …, turn.completed ], nextCursor: 9,
turnStatus: "idle" }
→ tools/call kiro_get_transcript { sessionId }
← { turns: [ …, { turnId: "01M8GQZW0JPD…", text: "PONG" } ] }
And as it serves it now, to a client that declares the MCP Tasks extension:
→ tools/call kiro_send_prompt { sessionId, prompt: "Reply PONG" }
_meta: { "io.modelcontextprotocol/clientCapabilities":
{ extensions: { "io.modelcontextprotocol/tasks": {} } } }
← { resultType: "task", taskId: "WzEsIjAxTThHUU4zNVA3VDE5…", status: "working",
ttlMs: 86400000, pollIntervalMs: 5000 }
… the chat moves on; the client polls in the background …
→ tasks/get { taskId }
← { resultType: "complete", status: "working", … }
→ tasks/get { taskId }
← { resultType: "complete", status: "completed",
result: { content: [ { type: "text", text: "PONG" } ], … } }
The work is the same. Who waits for it is not. In the first transcript the model drives the loop, turn by turn, so the conversation is parked inside a tool call until the turn settles. In the second, the server hands back a handle in one round trip and the client follows it, outside the model’s turn. This post is about the difference, and about what a server with no memory between requests has to do to hand out handles at all.
what kiro-remote is
Kiro has no public API for cloud sessions, so kiro-remote wraps the engine bundled with kiro-cli, over the Agent Client Protocol, and puts a REST API and an MCP server in front of it. One CDK stack:
- The front door is an API Gateway HTTP API and a Lambda function serving
/v1(REST, with an OpenAPI 3.1 contract) and/mcp(Streamable HTTP, 19 tools), behind an OAuth 2.1 facade over a Cognito user pool, with passkeys. - The record is one DynamoDB table: sessions, turns, the prompt queue and an append-only, cursor-ordered event log.
- The bridge is three container-image Lambda functions from one image: an SQS consumer that launches sessions and drives turns over ACP, a durable catch-up function for turns that outlive one invocation, and a publisher for the engine’s capabilities.
- GitHub can wake a session: a pull request it opened merges, gets a review or fails its checks. The webhook arrives at the same API Gateway, at
/github/webhook, and its own Lambda functions record the event and queue a new turn.
The Lambda function behind /mcp keeps nothing between requests. Hold on to that; it decides everything below.
It started in the small hours of 7 November. 201 of its 289 commits are Kiro Agent’s, 40 Claude’s and 48 mine.
the loop
Before Tasks, following a turn was the model’s job. kiro_wait_for_events is a long poll tuned to be cheap: it waits at most 20 seconds and returns at most 30 events and 8,000 characters, with nextCursor and turnStatus, so the model knows when to stop. The skill kiro-remote ships teaches the stop condition: turnStatus is idle and a turn.completed or turn.failed has arrived.
It’s correct, and it works over any MCP client from any era. Its cost is where the waiting lives. Each long poll is a tool call inside the model’s turn, so the chat is busy for as long as Kiro is: about nine seconds for a follow-up on a warm session, minutes for a first turn. And when the model ends its turn, nothing follows the work any more. A chat client can’t receive a webhook, so “tell me when it’s done” had no one to tell.
the task
SEP-2663 moved tasks out of the core protocol into an extension, io.modelcontextprotocol/tasks, on the 2026-07-28 protocol revision. Three things about it matter here:
- It’s negotiated per request. There’s no session to remember capabilities in, so the client declares the extension in each request’s
_meta, and the server advertises it inserver/discover. - The server decides. The client doesn’t ask for a task; a tool call either answers with its result or with
resultType: "task", a handle with ataskId, a status, a TTL and a suggested poll interval. - It polls. The client reads the task with
tasks/getuntil it’scompleted,failedorcancelled, and a completed task carries the tool’s result as if the call had returned it.
In kiro-remote, the server’s side of that is a module, packages/mcp/src/tasks, wired in as a hook on tools/call (decision wacaw8qk). The tool runs exactly as before. Then, if the request declared the extension and the tool started long work, the hook swaps the result for a handle:
// tasks-extension.ts, abridged
async afterToolCall(call, outcome, ctx) {
const read = TASK_TOOLS.get(call.name);
if (!read || outcome.isError || !declaresTasksExtension(ctx))
return undefined;
// { sessionId, turnId }, or a delete or a wait
const started = read(call.args, outcome.structuredContent);
if (!started) return undefined;
try {
const handle = await this.create(ctx, { context: { ...started } });
return { content: [], ...handle };
} catch (err) {
// The prompt is already sent: answer without a task,
// never with an error.
return undefined;
}
}
undefined means “leave the result as it is”, which is what every older client, and every other tool, gets. The tools-list.json fixture holds that byte for byte.
a handle with no table behind it
tasks/get arrives as a separate HTTP request, most likely at a different Lambda instance. There’s no in-memory map from task id to work, and a second table of tasks would have to be kept in step with the turns. So the task id is the lookup: base64url of a JSON array that names the records to read.
// task-id.ts: a turn, the first kind
[1, sessionId, turnId, createdAtMs, ttlMs]
// other kinds, added on 29 November
[2, "delete", sessionId, createdAtMs, ttlMs]
[2, "wait", sessionId, "owner/repo#n", sinceMs, createdAtMs, ttlMs]
tasks/get decodes it strictly (anything that wouldn’t encode back to the same string is “Task not found”), checks the TTL, then reads the turn as the caller, with the caller’s scopes. Nothing in the id is a credential, and an unknown, expired and someone else’s task all get the same answer, so existence never leaks. Each kind has its own clock, in constants.ts:
| Kind | Follows | TTL | Poll every |
|---|---|---|---|
turn |
a prompt’s or a launch’s turn, to its final text | 24 hours | 5 s |
delete |
a session’s deletion | 1 hour | 5 s |
wait |
a wait for a pull request, to the wake turn it causes | 7 days | 60 s |
A running turn costs one DynamoDB read per poll; a settled one also reads the event log for its final text.
the record has to exist first
The catch is in “reads the turn”. A handle is only honest if tasks/get can read something the moment the call returns, and the first version, on 26 November, could only promise that for one path. A prompt sent with whenBusy: "queue" wrote its queue row before the call answered. A steer or reject prompt to an idle session was a command on its way to the bridge, with no row until the bridge wrote the turn. A launch didn’t even have a turn id yet. So only queue got a task, and the default, steer, silently didn’t.
I found it on 28 November, with a probe: one “reply PONG” prompt to a throwaway session, sent with queue. The handle came back, and a little later the result arrived in the chat with no kiro_wait_for_events call at all. Then I read why it worked: the queue. Decision wacaw8qk had already listed the other paths as known gaps.
On 29 November, from 20:41 to 23:51, I closed that gap as seven issues in 39 commits. The core of it is one decision, j1mv4n4a: every prompt the API accepts goes on the session’s prompt queue before its command is sent, and its turn runs under that row’s id. The queue row already had the life cycle a task needs: claimed once, started once, and failed with a reason (session_deleted, session_failed, not_sent, session_busy) on every path where the turn never starts. So a task never follows a turn that will never end.
I considered three other ways: a provisional turn row that the bridge moves on, reading a missing record as working for a grace period, and sending every prompt through the queue. The first needed a new write on every failure path, the second can’t tell a lost command from a slow one, and the third costs every prompt a second trip through SQS.
One consequence is visible from outside: a session is busy from the moment a prompt is accepted, not from when its turn starts. A second steer sent before the first one has started is now refused with steer_unsupported instead of racing it to the bridge.
every call that starts long work
With the record in place, the rest followed:
kiro_launch_sessionmints the first turn’s id, writes its queue row and answers with a task.tasks/getsaysworkingwhile the sandbox provisions, andfailedwithsession_failedif it never does.kiro_send_promptanswers with a task for everywhenBusy.kiro_delete_sessionanswers with adeletetask that completes when the session is gone.kiro_wait_for_pull_requestanswers with awaittask that completes when the pull request has merged or closed and the wake turn it caused has finished. Its result is the pull request’s final state and the wake turn’s text.
A GitHub wake is the only turn no tool call starts, so before, the only way to hear about it was to poll the change feed. Now an orchestrator can say “when this pull request merges, tell me what the other session did about it”, and the answer comes back up to a week later, into whatever conversation is going on by then.
what is still a loop
Tasks don’t push. The client polls tasks/get, and kiro-remote serves the 2026 era only: a 2025-era client still gets plain results and the long-poll loop, which keeps working. Cancelling is cooperative: tasks/cancel asks, and a cloud session refuses a cancel mid-turn. And a handle is only as good as its TTL: a turn’s is 24 hours, after which kiro_get_transcript still has the answer, but the task doesn’t.
This is the first part of a series about kiro-remote. Next: the kiro-remote-sessions skill the server ships over MCP, which teaches a connecting model the loop above, and when it can skip it.
The code is open source, tests and decisions included.
/niko