Skip to content

fix(agent): route gadget schedules through SCHEDULER binding - #26

Open
darjss wants to merge 1 commit into
fix/agent-callback-resolve-fastfrom
fix/agent-gadget-scheduler-docs
Open

fix(agent): route gadget schedules through SCHEDULER binding#26
darjss wants to merge 1 commit into
fix/agent-callback-resolve-fastfrom
fix/agent-gadget-scheduler-docs

Conversation

@darjss

@darjss darjss commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Why

The agent tried setAlarm inside a gadget facet DO, which Cloudflare rejects ("Facets currently cannot set alarms"). Daily reports only ran on app open.

Scope

  • packages/workshop-backend/src/agent.ts: document that gadget facets cannot use setAlarm; use ambient SCHEDULER with ctx.restore() hooks.
  • EXECUTE_CODE_TOOL_DESCRIPTION: repeat erxes GraphQL concurrency caps for executeCode paths.

Blast Radius

Agent prompt only. Guides future gadget code the agent writes.

Verification

Prompt string change only.

Summary by Sourcery

Update agent guidance so gadget schedules use the supported SCHEDULER binding and comply with executeCode concurrency limits.

Bug Fixes:

  • Guide agents to route gadget scheduled work through the ambient SCHEDULER binding instead of unsupported Durable Object alarms.

Enhancements:

  • Document the required ctx.restore() hooks and Connections schedule enablement for gadget facets.

Chores:

  • Clarify erxes GraphQL concurrency caps for executeCode paths in the agent guidance.

@sourcery-ai

sourcery-ai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the agent prompt to prevent unsupported alarms in gadget facets by routing schedules through the SCHEDULER binding, and adds erxes GraphQL concurrency and pagination safeguards for executeCode workflows.

Sequence diagram for gadget schedule registration through SCHEDULER

sequenceDiagram
    participant GadgetFacetDO
    participant SCHEDULER
    participant Connections
    participant ctx

    GadgetFacetDO->>SCHEDULER: calendarAt / every / runAt
    SCHEDULER-->>GadgetFacetDO: schedule handle
    GadgetFacetDO->>ctx: restore()
    ctx-->>GadgetFacetDO: restored hooks
    GadgetFacetDO->>Connections: enable schedule
Loading

Flow diagram for safe executeCode GraphQL pagination

flowchart LR
    Start["EXECUTOR erxes GraphQL request"] --> Count["Fetch totalCount on first page"]
    Count --> Page["Fetch pages sequentially"]
    Page --> Limit["At most 5 concurrent requests"]
    Limit --> Done["Complete table scan"]
Loading

File-Level Changes

Change Details Files
Redirect scheduled gadget work from unsupported facet alarms to the ambient scheduler workflow.
  • Document that gadget facet Durable Objects cannot use setAlarm APIs.
  • Instruct the agent to use SCHEDULER methods with ctx.restore() hooks and enable schedules through Connections.
packages/workshop-backend/src/agent.ts
Add execution guidance for safe erxes GraphQL request concurrency and pagination.
  • Limit EXECUTOR requests to five concurrent operations.
  • Require sequential pagination and an initial totalCount query for large tables.
packages/workshop-backend/src/agent.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 762c8ad3-ea78-4b3c-b5e8-7c824036f07c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the kernel label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/workshop-backend/src/agent.ts" line_range="576" />
<code_context>

 Both the client and server run inside a strictly isolated sandbox. They cannot make requests to the Internet, e.g. by calling \`fetch()\`. Instead, a Gadget communicates with the outside world strictly through its "bindings", that is, the Cloudflare Workers \`env\` API, which code in the Durable Object class can access as \`this.env\`.

+Gadget facet Durable Objects cannot call \`setAlarm\` or \`this.state.storage.setAlarm\`. Scheduled work must use the ambient \`SCHEDULER\` gatekeeper binding (\`calendarAt\`, \`every\`, \`runAt\`) with \`ctx.restore()\` hooks, then enable the schedule in Connections.
+
 Note that the iframe sandbox on the client side prohibits modal popup boxes like alert() and confirm(), so do not use those.
</code_context>
<issue_to_address>
**issue (bug_risk):** The prompt teaches the invalid Durable Objects API `this.state.storage.setAlarm`; Cloudflare Durable Objects expose storage as `this.ctx.storage`, so an agent following this example can still generate incorrect alarm code and fail at runtime or deployment. The instruction also does not explicitly name `this.ctx.storage.setAlarm`, the actual forbidden form.

**Triggers:** When the agent tries to replace a direct alarm call in a gadget facet.

**Suggested fix:** Replace `this.state.storage.setAlarm` with `this.ctx.storage.setAlarm` in the forbidden-call example, making clear that both `setAlarm()` and `this.ctx.storage.setAlarm()` are unsupported for gadget facets.

```suggestion
Gadget facet Durable Objects cannot call \`setAlarm\` or \`this.ctx.storage.setAlarm\`. Scheduled work must use the ambient \`SCHEDULER\` gatekeeper binding (\`calendarAt\`, \`every\`, \`runAt\`) with \`ctx.restore()\` hooks, then enable the schedule in Connections.
```
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: packages/workshop-backend/src/agent.ts:576


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread packages/workshop-backend/src/agent.ts
@darjss
darjss force-pushed the fix/agent-gadget-scheduler-docs branch from cd35af8 to bedb79f Compare September 1, 2026 08:14
@darjss
darjss force-pushed the fix/agent-callback-resolve-fast branch from 69720dc to 2d2db2c Compare September 1, 2026 08:14
@darjss
darjss force-pushed the fix/agent-gadget-scheduler-docs branch from bedb79f to d768abb Compare September 1, 2026 08:47
@darjss
darjss force-pushed the fix/agent-callback-resolve-fast branch from 2d2db2c to 93fba53 Compare September 1, 2026 08:47
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 1, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@sourcery-ai
sourcery-ai Bot dismissed their stale review September 1, 2026 08:48

Sourcery withdrew this approval because the latest commits introduced blocking findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant