Skip to content

Give website examples durable Leaf guide replies - #343

Merged
max-sixty merged 7 commits into
mainfrom
codex/example-asks
Sep 6, 2026
Merged

max-sixty merged 7 commits into
mainfrom
codex/example-asks

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 6, 2026 •

Copy link
Copy Markdown
Owner

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-luna answers 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.

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread worker/src/index.ts Resolved

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread worker/src/index.ts Resolved
@max-sixty
max-sixty merged commit f5d4fac into main Sep 6, 2026
7 checks passed
@max-sixty
max-sixty deleted the codex/example-asks branch September 6, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants