Repository navigation
Description
Summary
The JavaScript template, the JS thread-loop snippet, the JS scaffold output and the client-server skill all call await Delay(1000) inside setTick, but nothing defines Delay. The CFX JS runtime has no built-in Delay, so these resources throw ReferenceError: Delay is not defined on every tick.
Where
templates/javascript/client/main.js:1-2snippets/javascript/thread-loop.js:2-6mcp-server/tools/scaffold.py:187-191(_scaffold_js, generatedclient/main.js)skills/client-server-patterns/SKILL.md:89,skills/client-server-patterns/SKILL.md:168rules/cfx-javascript-conventions.mdc:15
Details
setTick(async () => {
await Delay(1000);
// Main client loop
});git grep "Delay\s*=" finds no definition anywhere in the repo. The FiveM JavaScript docs state that, unlike Lua and C#, there is no built-in Wait or Delay in JS and define their own helper: const Delay = (ms) => new Promise(res => setTimeout(res, ms));. In C#, Delay is a BaseScript method, so the C# templates and snippets are fine.
The JS rule tells agents to "Use setTick with await Delay(ms)", and the snippet comment says "Always await Delay() to yield", both treating it as built in.
Impact
Every resource created with scaffold_resource_tool(language="javascript") or copied from templates/javascript errors on every client tick, spamming the F8 console, and any code after the Delay call never runs. Agents following the rule keep generating the same broken pattern.
Steps to reproduce
- Scaffold
name=x, game=gta5, language=javascript, framework=standalone, or copytemplates/javascriptinto a server's resources. ensurethe resource and join.- The client console shows
ReferenceError: Delay is not definedrepeatedly.
Suggested fix
- Add
const Delay = (ms) => new Promise((res) => setTimeout(res, ms));at the top oftemplates/javascript/client/main.js,snippets/javascript/thread-loop.js, and the scaffoldedclient/main.jsstring inscaffold.py. - Update
rules/cfx-javascript-conventions.mdcandskills/client-server-patterns/SKILL.mdto say the helper must be defined, and show it in the examples.
Acceptance criteria
- No JS file, scaffold string, or JS example in skills/rules calls
Delaywithout defining it in the same file or snippet. - The JS rule and skill mention that
Delayis a user-defined helper in JS. - A scaffolded JS resource starts with no client console errors.
Getting started
- Relevant files:
templates/javascript/client/main.js,snippets/javascript/thread-loop.js,mcp-server/tools/scaffold.py,skills/client-server-patterns/SKILL.md,rules/cfx-javascript-conventions.mdc - How to run checks: there is no test suite yet; run the MCP server with
cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in.github/workflows/validate.yml - Related docs: FiveM JavaScript scripting docs on docs.fivem.net
Filed by repo-audit/full-audit at 701824d. Severity: high. Effort: S. audit-key: bug|templates/javascript/client/main.js|Delay
Activity
TMHSDigital commentedon Nov 21, 2026
Fixed in fd12569.
Defined
const Delay = (ms) => new Promise(...)in the JS template, the thread-loop snippet and the scaffolded client/main.js, and documented in the JS rule and skills that Delay must be defined.Verified: Ran the template, the snippet and a freshly scaffolded client/main.js under node with
setTickstubbed: each tick completed without a ReferenceError.