Claude Opus 5.5

agents-0-24-0-5-b

Claude Code's read-only tools, web search on, ludion sync on

Question

My queued Agent callback can't see the request that queued it. Is that expected?

Answer key

A correct answer says
Callbacks queued with `this.queue()` run later from the alarm loop, so `getCurrentAgent()` inside them returns the agent but not the original `connection` or `request`.
The stale answer
Queued callbacks run in the same context and can read the enqueuing request's connection and request via getCurrentAgent().

The change's lesson

Answer

Yes, that's expected. `this.queue()` doesn't run your callback inside the request that queued it. It saves the callback's method name and a JSON-serializable payload to the Agent's SQLite storage, then runs it later from the queue loop. That can happen after the original request has finished, or even after the Durable Object has hibernated and woken up again. So inside the callback, `getCurrentAgent()` gives you the agent, but `request` (and usually `connection`) is `undefined`. A live `Request` object can't be saved to storage anyway.

The fix is to copy what you need from the request into the payload when you queue it, for example `this.queue("process", { userId, url: request.url, authHeader })`, and read it from the payload in the callback. Don't store secrets in the payload unless you're comfortable having them saved in the Agent's storage.

I answered from how the Agents SDK works, not from your code or the installed `agents` 0.27.0 source. If the callback can't see the agent itself either, that's a different problem and worth looking into.

Answering cost $0.10.

Grade

correct

The judge's reason: It says queued callbacks run later from the queue loop, with getCurrentAgent() returning the agent but not the original request/connection.

The judge's log

Session log

What the agent wrote, the tools it called, and what they returned, from docs/bench/2026-10-11-done3/runs/B-project-sync/agents-0-24-0-5-b.jsonl. Thinking and the session's settings are left out. The raw log

  1. Agent

    Yes, that's expected. `this.queue()` doesn't run your callback inside the request that queued it. It saves the callback's method name and a JSON-serializable payload to the Agent's SQLite storage, then runs it later from the queue loop. That can happen after the original request has finished, or even after the Durable Object has hibernated and woken up again. So inside the callback, `getCurrentAgent()` gives you the agent, but `request` (and usually `connection`) is `undefined`. A live `Request` object can't be saved to storage anyway.
    
    The fix is to copy what you need from the request into the payload when you queue it, for example `this.queue("process", { userId, url: request.url, authHeader })`, and read it from the payload in the callback. Don't store secrets in the payload unless you're comfortable having them saved in the Agent's storage.
    
    I answered from how the Agents SDK works, not from your code or the installed `agents` 0.27.0 source. If the callback can't see the agent itself either, that's a different problem and worth looking into.