Skip to content

Document raw Containers API alongside Container class - #33093

Open
thomasgauvin wants to merge 13 commits into
productionfrom
codex/container-api-docs
Open

thomasgauvin wants to merge 13 commits into
productionfrom
codex/container-api-docs

Conversation

@thomasgauvin

@thomasgauvin thomasgauvin commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Focuses this PR on the Containers documentation information architecture:

Testing

  • pnpm run check (0 errors, 0 warnings)
  • pnpm exec tsm bin/validate-redirects.ts
  • Scoped Prettier check and git diff --check against the PR base
  • Local build rendered the changed routes, then failed on an unrelated missing GET /zones/{zone_identifier}/custom_pages/{identifier} APIRequest operation in the local OpenAPI schema. Review CI before merging.

@cloudflare-docs-bot

cloudflare-docs-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

AI Review

✅ Reviewed ef3f6b2 · 2 findings · incremental

👉 Fix in your agent 👈
Fix the following review findings in PR #33093 (https://github.com/cloudflare/cloudflare-docs/pull/33093).

Before making changes, review each finding and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification.
- If you disagree, explain why.
- If you need clarification before deciding, ask those questions.
- Then share your plan for which issues to tackle and in what order.

After triaging, follow this order:
1. Post a comment on this PR for any findings you are skipping, with the finding ID and your reasoning.
2. Then commit the fixes for the legitimate findings.

The comment must come before the commit because the next review reads PR comments.

## Style Guide
- S-1195645a | src/content/docs/containers/concepts/architecture.mdx:123 | Semicolon joins two independent clauses
  The sentence "The Durable Object becomes inactive when it stops receiving requests; the timeout can keep the container available while the Durable Object sleeps." joins two independent clauses with a semicolon. Per the writing-style rules, break it into two sentences.
- S-01025b58 | src/content/docs/containers/guides/migrate-to-durable-object-container-api.mdx:25 | Missing serial comma before final conjunction
  The three replacement options `ctx.container.start()`, `signal()`, and `destroy()` are joined by `and`/`or` without a comma before the final `or`. Per the serial comma rule, the comma must appear before the final top-level conjunction.

Style Guide

  • src/content/docs/containers/concepts/architecture.mdx:123 · Semicolon joins two independent clauses

    The sentence "The Durable Object becomes inactive when it stops receiving requests; the timeout can keep the container available while the Durable Object sleeps." joins two independent clauses with a semicolon. Per the writing-style rules, break it into two sentences.

  • src/content/docs/containers/guides/migrate-to-durable-object-container-api.mdx:25 · Missing serial comma before final conjunction

    The three replacement options ctx.container.start(), signal(), and destroy() are joined by and/or without a comma before the final or. Per the serial comma rule, the comma must appear before the final top-level conjunction.

Not reviewed (1)
  • src/content/docs/containers/reference/durable-object-methods.mdx — deleted file
Resolved (2) · Dismissed (0)
  • Resolved: Passive voice in API recommendation · Verified at head (api/index.mdx): line 43 now reads 'Inside a Durable Object, use ctx.container...'; the passive 'is recommended' sentence is gone, and lines 16 and 105 state the recommendation actively ('we recommend', 'use').
  • Resolved: Description omits new migration guide page · The current description bullet 2 states 'adds a Container class to direct API migration guide', which identifies the new migrate-to-durable-object-container-api.mdx page; the description no longer omits this core change.
Commands
  • /review Run a review now.
  • /full-review Review the entire PR diff.
  • /disable-auto-review Stop automatic reviews.
  • /rebase Rebase against production.

@github-actions github-actions Bot added product:workers Related to Workers product product:reference-architecture product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:changelog product:containers product:sandbox size/xl labels Aug 28, 2026
@cloudflare-docs-bot

cloudflare-docs-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Review coverage

✅ All 5 ownership areas are covered.

✅ 5 areas already covered
Area Approved by
workers
1 file changed
irvinebroque
Other
1 file changed
/public/__redirects
irvinebroque
containers
21 files changed
irvinebroque
durable-objects
1 file changed
irvinebroque
rules
1 file changed
irvinebroque
CODEOWNERS mappings for displayed areas (5)
Pattern Owners
/src/content/docs/workers/wrangler/ @irvinebroque, @MattieTK, @vy-ton, @cloudflare/wrangler, @cloudflare/product-owners
/public/__redirects @cloudflare/product-owners, @cloudflare/content-engineering
/src/content/docs/containers/ @mikenomitch, @th0m, @cloudflare/cloudchamber, @cloudflare/product-owners
/src/content/docs/durable-objects/ @danlapid, @iglesiasbrandon, @irvinebroque, @joshthoward, @lambrospetrou, @mikenomitch, @rita3ko, @vy-ton, @cloudflare/product-owners
/src/content/docs/rules/ @maurizioabba, @mbullock1986, @smarsh-cf, @cloudflare/appsec-reviewers, @cloudflare/product-owners

@thomasgauvin

Copy link
Copy Markdown
Contributor Author

Review triage for findings on 285ad23:

  • CR-9183433ea624: Keep both the navigation stub and the 301 redirect. The stub supplies the Durable Objects sidebar link to the new Containers API page; the redirect handles direct requests to the old URL. The stub is not intended as a separate content destination.
  • SG-f074c72134c1 and SG-0e8254639803: These blocks are method signatures, not executable Worker examples. They now use txt fences instead of raw ts fences. TypeScriptExample generates JavaScript and its parser rejects standalone method signatures without bodies. Executable examples use TypeScriptExample.

The other findings are fixed and validated in the isolated local PR worktree. No commit or push has been made yet.

constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
ctx.blockConcurrencyWhile(() =>
ctx.container!.setInactivityTimeout(10 * 60 * 1000),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This example could use a container: Container; property that gets init in the constructor, and then users dont have to use ! operator when accessing ctx.container.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in #33093: the short API comparison snippet now checks for a configured container instead of using the non-null assertion.

### Container shutdown

The Container class sets [`sleepAfter`](/containers/reference/container-class/#sleepafter) to 10 minutes by default. Its default [`onActivityExpired()`](/containers/reference/container-class/#onactivityexpired) implementation signals the container to stop after that period without activity. You can change the duration or override the hook.
With the Durable Object Container API, call [`setInactivityTimeout()`](/containers/api/durable-object-container/#setinactivitytimeout) to let the runtime stop an inactive container. You can also stop a container with [`signal()`](/containers/api/durable-object-container/#signal) or [`destroy()`](/containers/api/durable-object-container/#destroy).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There will be questions around setinactivitytimeout. In general, we should explain that setInactivityTimeout triggers when the Durable Object goes to sleep, use it so the container can be kept around while the DO is inactive (which is when requests do not come in).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in #33093: the shutdown section now explains inactivity in terms of the Durable Object receiving no requests and the timeout keeping its container available while the Durable Object sleeps.


constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
ctx.blockConcurrencyWhile(() =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In these examples I do not think we shouldbe using blockConcurrencyWhile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the raw backend example to the stacked examples PR #33681 and removed blockConcurrencyWhile() and constructor setup there. #33093 now has no example-code changes.

private async startAndWaitForPort(): Promise<void> {
const container = this.ctx.container!;
if (!container.running) {
container.start();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have any examples with monitor()? We should add an incentive for LLMs to use monitor() to track when the container exits (and track if there is any errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the stacked examples PR #33681: the backend direct-API example now uses monitor() to log both container exit and errors. The status-hooks example also demonstrates monitor().

@gabivlj

gabivlj commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

We should add an example somewhere for LLMs to read that showcase how to keep the container "always running", and add an RPC in the DO that exposes a destroy() + destry alarm.

enableInternet: true,
env: {
ENV_VAR: env.ENV_VAR,
WORKER_SECRET: env.WORKER_SECRET,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blockConcurrencyWhile, I recommend just exposing a start() method on this DO as it does not seem to do anything.

In general, let's discourage starting in the constructor for LLMs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed about not starting in the constructor. The raw environment-variable variant was removed from #33093 and deferred from #33681 because its options overlap the separate start() work in #33531. The remaining direct-API examples in #33681 start from methods or requests without blockConcurrencyWhile().

ctx.blockConcurrencyWhile(async () => {
if (!ctx.container!.running) {
ctx.container!.start({
image: env.CONTAINER_IMAGE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ctx.container.images?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The runtime-image selection variant is out of scope for these two PRs and belongs with the separate start() work in #33531; this example was removed from #33093 and is not in #33681.

if (this.ctx.container!.running) {
throw new Error("Container is already running");
}
this.ctx.container!.start({ image, enableInternet: true, env });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a great example, let's add monitor() too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This raw environment-variable variant is deferred from both PRs because passing startup options would overlap the new start() documentation in #33531. The backend and status-hooks examples in #33681 demonstrate monitor() for exit and error tracking.

@github-actions github-actions Bot added the product:rules Related to rules label Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:containers product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:rules Related to rules product:workers Related to Workers product size/xl

Projects

None yet

Development

Successfully merging this pull request may close these issues.