pnpm exec tsx examples/10-habitats-over-a2a/host.ts --smoke
One HabitatHost serves every habitat under /habitats/<id>/ on one Node HTTP server (createHttpHandler). Each habitat is a DurableHabitat with its own habitats/<id>/habitat.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 habitat's answer |
own-sqlite | The habitat got its own habitats/research/habitat.sqlite |
open-once | Two simultaneous first requests to a new habitat open its file once |
id-traversal-refused | An id like ..%2F..%2Fescaped gets 400 and creates nothing |
Revert the HabitatHost fix in packages/habitat/src/durable/durable-habitat.ts and four checks fail.
Prompt
Build examples/10-habitats-over-a2a/host.ts: one @umwelten/habitat HabitatHost serving many SQLite-backed DurableHabitats 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 habitat gets its own <dataDir>/<id>/habitat.sqlite; the agent card's endpoint is reachable and SendMessage to it completes; two simultaneous first requests open the habitat 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 HabitatHost serves many habitats from one process, each from its own SQLite file opened on demand. Going through the lab found three bugs in HabitatHost.createHttpHandler, all fixed in the package with a regression test (durable-habitat.test.ts, "serves only safe habitat ids over HTTP…"):
- Path traversal through the habitat id. The id from
/habitats/<id>/was percent-decoded and joined ontodataDir, so/habitats/..%2F..%2Fescaped/…opened (and created) a habitat directory outside the data directory. Ids must now match^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$; anything else gets 400, andHabitatHost.get()rejects it too. - Concurrent first requests opened the file twice. Two requests for a not-yet-open habitat each ran
DurableHabitat.openon the samehabitat.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/habitats/<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 habitat'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 habitat allows unauthenticated loopback callers only.
Not tested
- Idle eviction and reopen through HTTP (Lab 08 covers eviction directly).
- Authenticated habitats (
bearerToken), and many habitats 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/habitats/research/a2a PASS a2a-answer: TASK_STATE_COMPLETED "Answer 1 from a SQLite-backed habitat." PASS own-sqlite: habitats/research/habitat.sqlite exists=true PASS open-once: statuses 200, 200; habitat 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.