pnpm exec tsx examples/10-agents-over-a2a/host.ts --smoke
One AgentHost serves every agent under /agents/<id>/ on one Node HTTP server (createHttpHandler). Each agent is a DurableAgent with its own agents/<id>/agent.sqlite, opened when the first request for it arrives. The model is faux, so the lab runs offline.
| Check | What it shows |
|---|---|
lazy-open | Nothing is open and no data directory exists before the first request |
card-reachable | The agent card's endpoint is the address the request came in on |
a2a-answer | A2A 1.0 SendMessage to that endpoint completes with the agent's answer |
own-sqlite | The agent got its own agents/research/agent.sqlite |
open-once | Two simultaneous first requests to a new agent open its file once |
id-traversal-refused | An id like ..%2F..%2Fescaped gets 400 and creates nothing |
Revert the AgentHost fix in packages/agent/src/durable/durable-agent.ts and four checks fail.
Prompt
Build examples/10-agents-over-a2a/host.ts: one @umwelten/agent AgentHost serving many SQLite-backed DurableAgents as A2A 1.0 agents on one Node HTTP server via createHttpHandler, with a faux model so it runs offline. Check, printing PASS/FAIL per check and exiting 1 on any failure: nothing opens before the first request; each agent gets its own <dataDir>/<id>/agent.sqlite; the agent card's endpoint is reachable and SendMessage to it completes; two simultaneous first requests open the agent once; an id that decodes to a path outside dataDir is refused and creates nothing. Strict TypeScript, no any, clean up the temp dir in finally.
--live opt-in
What we learned
The answer
One AgentHost serves many agents from one process, each from its own SQLite file opened on demand. Going through the lab found three bugs in AgentHost.createHttpHandler, all fixed in the package with a regression test (durable-agent.test.ts, "serves only safe agent ids over HTTP…"):
- Path traversal through the agent id. The id from
/agents/<id>/was percent-decoded and joined ontodataDir, so/agents/..%2F..%2Fescaped/…opened (and created) an agent directory outside the data directory. Ids must now match^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$; anything else gets 400, andAgentHost.get()rejects it too. - Concurrent first requests opened the file twice. Two requests for a not-yet-open agent each ran
DurableAgent.openon the sameagent.sqlite, which breaks pi-durable's one-writer rule. First opens in flight are now shared. - The agent card advertised an unreachable endpoint. Without a
publicOrigin, the card saidhttp://127.0.0.1/agents/<id>/a2a, with no port, so a client following the card got connection refused. It now uses the request'sHost.
What going through it found about the lab
- The lab checked nothing. It printed the card name and the raw task JSON and always exited 0. It now has six PASS/FAIL checks and exits 1 on failure.
- The old README and prompt promised more than the code did (repo guards, probes,
ui://resources). Those are Labs 09, 07 and 13; this lab now tests only the host. - The existing host test never used
createHttpHandler. It wired one agent's A2A surface to a server by hand, which is why none of these bugs showed up.
Gotchas
- Behind a proxy, set
publicOrigin. TheHostfallback is right for direct access; a proxy that rewritesHostwould advertise its internal address. - No auth by default. Without a
bearerTokenfromconfigure, each agent allows unauthenticated loopback callers only.
Not tested
- Idle eviction and reopen through HTTP (Lab 08 covers eviction directly).
- Authenticated agents (
bearerToken), and many agents at once. - A live model.
Smoke run
PASS lazy-open: before any request: 0 open, data dir exists=false PASS card-reachable: card endpoint http://127.0.0.1:33607/agents/research/a2a PASS a2a-answer: TASK_STATE_COMPLETED "Answer 1 from a SQLite-backed agent." PASS own-sqlite: agents/research/agent.sqlite exists=true PASS open-once: statuses 200, 200; agent opened 1 time(s) PASS id-traversal-refused: HTTP 400; open: [research, support]; data dir: [research, support] 6/6 passed
Before the fix, 3/7: card-reachable, card-endpoint-answers, open-once and id-traversal-refused failed.