fix(agent): route gadget schedules through SCHEDULER binding - #26
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates 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 SCHEDULERsequenceDiagram
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
Flow diagram for safe executeCode GraphQL paginationflowchart 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"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
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. |
There was a problem hiding this comment.
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
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
cd35af8 to
bedb79f
Compare
69720dc to
2d2db2c
Compare
bedb79f to
d768abb
Compare
2d2db2c to
93fba53
Compare
Sourcery withdrew this approval because the latest commits introduced blocking findings.
Why
The agent tried
setAlarminside 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 usesetAlarm; use ambientSCHEDULERwithctx.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:
Enhancements:
Chores: