Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

docs(brain): piece PRs leave translation.json to the nightly job (#16892)

Ibrahim Abuznaidd078d47750b5
diff --git a/brain/knowledge/pieces-engine/building-pieces.md b/brain/knowledge/pieces-engine/building-pieces.md
index 2a1490a8736..c024b60858e 100644
--- a/brain/knowledge/pieces-engine/building-pieces.md
+++ b/brain/knowledge/pieces-engine/building-pieces.md
@@ -46,7 +46,7 @@ Authentication, triggers (polling/webhook), properties + validation, flow contro
- **`formatPieceError` runs *inside* the engine's error handler, so anything it throws replaces a real user error with an engine crash.** Two inputs used to do exactly that, both verified: a **cyclic** error body blew `collectMessage`'s recursion with `RangeError: Maximum call stack size exceeded` (a cycle through any of `message`/`detail`/`description`/`reason`/`error`, or a self-referencing array — and a 100-wide cycle made it exponential), and a cyclic `responseBody`/`requestBody` survived extraction only to die at the `JSON.stringify(formatPieceError(...))` every call site wraps it in, with `TypeError: Converting circular structure to JSON`. The second needs no deep cycle at all — a `self` key the extractor never walks is enough. Where that lands is the nasty part: `operations/index.ts` is the outermost handler, so a throw there escapes with no response and the worker just sees an RPC timeout. Both are now bounded — `collectMessageFrom` and `rebuildSerializable` each carry a depth cap plus a visited `WeakSet`. **Sanitize by probing with `JSON.stringify`, never by hand-rolling a walk over every body.** The first attempt here deep-copied unconditionally and silently downgraded exactly the values `JSON.stringify` gets right: `Date` became `{}` instead of an ISO string, `Buffer` became `{"0":104}` instead of `{type,data}`, a custom `toJSON` was ignored, and an own `function` property was promoted to **its source text** where stringify had correctly dropped it. `toSerializable` now tries `JSON.stringify` first and returns the original reference **untouched** when it succeeds, so the common path is byte-identical and uncopied; only a value that actually throws gets the bounded rebuild (cycles become `[Circular]`), and that rebuild is itself wrapped in a `tryCatchSync` that falls back to `[Unserializable]`, because `Object.entries` runs getters and a body with a throwing getter would otherwise escape the guard entirely. Worth knowing that `formatPieceError` output shares references with the caller's error object, and that `ai-provider-health.ts` reads `responseBody` and stringifies it itself — so a copy there is not free. Two consequences to know: a **shared** (non-cyclic) reference is collected once rather than twice, which is free for `JSON.parse`-derived bodies since they never share refs but is a real fidelity loss for live SDK error objects; and the `isFriendlyPieceError` passthrough is *not* re-sanitized, on the contract that such a payload already came from a JSON string. Rule of thumb: this file may return a worse message, never throw.
- **A vendor placeholder written as `{{1}}` in any prop never reaches `run()`.** The builder's expression engine evaluates every `{{…}}` in step input first, so WhatsApp-style template variables arrive as empty strings and the vendor rejects the request for a reason that looks unrelated (a body/example mismatch). There is no escape a user can type. Accept an alternate marker (`[[1]]`) in the prop, convert it in `run()` (`whatsappClient.normalizeTemplateComponents`), and say so in the prop description.
-- **`src/i18n/translation.json` is generated, not edited.** After adding actions, triggers or descriptions run `TS_NODE_TRANSPILE_ONLY=true npm run cli -- pieces generate-translation-file <folder>` and commit the result. Without the env var ts-node crashes on a TS2339 inside the CLI itself. It rebuilds the piece's `dist` as a side effect.
+- **`src/i18n/translation.json` is generated by the nightly job, so leave it out of piece PRs.** `generate-translations.yml` regenerates it for every piece on `main` and auto-merges the result, and the runtime reads only `<locale>.json` (it is just the Crowdin source), so a PR that changes display strings loses nothing by not touching it. Committing it anyway conflicts with that sync: groq #16615 and discourse #16460 each stalled a nightly run, and #16773 put several open piece PRs into conflict on this file. The one exception is a piece whose test reads the file (today only `approval`'s `legacy-notice.test.ts`): regenerate it there. To preview it locally, run `TS_NODE_TRANSPILE_ONLY=true npm run cli -- pieces generate-translation-file <folder>`. Without the env var ts-node crashes on a TS2339 inside the CLI itself. It rebuilds the piece's `dist` as a side effect.
- **Bumping a dev piece's version breaks its existing connections until you re-pin `dist/package.json`.** The server resolves piece metadata by the version stored on the connection, and a dev piece serves only the single version in `dist`, so the old version vanishes and every step reports `connection … not found` with a valid connection. Either pin `dist/package.json` back to the stored version after each rebuild, or recreate the connection.
- **A provider-side webhook handshake only works against a published flow.** `GET /v1/webhooks/{flowId}` answers `404 {}` while the flow is a draft, and the `/draft` and `/test` variants answer `200 {}` without running `onHandshake`, so a provider that verifies the URL at registration time (Meta's `hub.challenge`) reports failure until the flow is published. Any trigger whose instructions show `{{webhookUrl}}` for manual registration must tell the user to publish first (confirmed 2026-09-16 on the WhatsApp triggers).
- **A piece's `build` compiles its `src/**/*.test.ts`, so a type error in a test breaks the piece build while `vitest` stays green.** `npm run build` is `tsc -p tsconfig.lib.json`, whose `include` is `src/**/*.ts` with no test exclusion, while vitest runs through esbuild and strips types without checking them. So a test that passes locally can still fail CI at `<piece>#build`, and it takes `validate-publishable-packages` down with it. Run the piece's own `npm run build`, not just its tests, after adding one. Two shapes that bite: `ServerContext` (`{apiUrl, publicUrl, token}`) and `AuthValidationServerContext` (the same minus `token`, plus `mintOidcToken`) are not interchangeable, and `StaticPropsValue` requires *every* prop key to be present, including optional ones — pass `sessionToken: undefined` rather than omitting it.