Repository navigation
Give website examples durable Leaf guide replies - #343
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
The handoff is well chosen — keying the trigger on activity.obligations rather than a second rule about which events deserve a reply, deduplicating on a deterministic attempt under the append lock, and re-checking only_if_pending at append time all keep the container the single authority. One correctness finding inline, plus one question.
The public origin now spends the operator's OpenAI key with no bound on request volume. A reader can post comments in a loop — or mint fresh __Host-leaf-example cookies — and each accepted comment starts a workflow that calls the API. maxTokens: 400 caps one reply, not the rate, and nothing in worker/src/index.ts or wrangler.toml throttles. That is a deployment judgment rather than a code defect, so I've left it as a comment rather than holding on it, but it seemed worth naming before leaf.page carries a funded key.
# Conflicts: # tests/test_website_server.py
leaf-agent
left a comment
There was a problem hiding this comment.
The duplicate-admission fix reads well: swallowing the throw only when a handle for that id actually resolves is what keeps a genuine admission failure retryable while a duplicate stops withdrawing an append that already succeeded. The limiters answer the funded-key concern from the last pass with a visible reply rather than a dropped turn, and settling the over-limit turn through the same append path keeps the container the only authority on it. One finding inline, on the other half of startAgentWorkflow.
Website examples already run the canonical Leaf server in an isolated per-reader container, but their Asks appeared unattended and comments received no reply. This change completes that loop: accepted reader obligations start a durable Cloudflare Workflow,
gpt-5.6-lunaanswers through the OpenAI Agents SDK, and the result is appended through Leaf's ordinary reply path.The container remains the only authority for page and conversation state. It supplies a fresh canonical turn, deduplicates retry attempts, rejects stale replies atomically, and uses deterministic workflow identity without losing retry signals. Failed workflow instances can be resumed from the reader's existing outbox attempt.
Model execution stays in the Worker, where the OpenAI key is an explicit secret binding. The key is not sent to the browser or container, container internet access remains disabled, and Node compatibility is configured not to copy secrets into
process.env. Cloudflare-native per-reader and per-location rate limits bound ordinary public use; over-limit turns receive a visible Leaf reply without calling OpenAI.The browser now names the limited “Leaf guide” in the status banner while preserving the distinction from a real Leaf work claim. Worker tests cover workflow admission, recovery, private routes, key isolation, rate limiting, retries, and append behavior; the Python/browser suite covers canonical context, idempotency, stale suppression, and the rendered presentation.