Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: truncate return to not choke temporal

Nevo Davidcc79e1297504
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
index 1ec735d66..f6e4af900 100644
--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts
+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
@@ -10,13 +10,34 @@ export type ValidityMedia = {
thumbnail?: string;
};
+// Temporal serializes the whole ApplicationFailure (message + details) into the
+// workflow history and ships it over gRPC, which has a hard frame limit (4MB by
+// default). Provider error messages/bodies can be huge (full HTML error pages,
+// base64 media echoed back, stack traces), so we cap every string that goes into
+// the failure to keep the history small and avoid "GRPC Message too large".
+const MAX_FAILURE_MESSAGE = 2_000;
+const MAX_FAILURE_FIELD = 4_000;
+
+export function truncateForTemporal(value: any, max: number): string {
+ if (value === null || value === undefined) {
+ return '';
+ }
+
+ const str = typeof value === 'string' ? value : safeStringify(value);
+ if (str.length <= max) {
+ return str;
+ }
+
+ return `${str.slice(0, max)}… [truncated ${str.length - max} chars]`;
+}
+
export class RefreshToken extends ApplicationFailure {
constructor(identifier: string, json: string, body: BodyInit, message = '') {
- super(message, 'refresh_token', true, [
+ super(truncateForTemporal(message, MAX_FAILURE_MESSAGE), 'refresh_token', true, [
{
identifier,
- json,
- body,
+ json: truncateForTemporal(json, MAX_FAILURE_FIELD),
+ body: truncateForTemporal(body, MAX_FAILURE_FIELD),
},
]);
}
@@ -24,11 +45,11 @@ export class RefreshToken extends ApplicationFailure {
export class BadBody extends ApplicationFailure {
constructor(identifier: string, json: string, body: BodyInit, message = '') {
- super(message, 'bad_body', true, [
+ super(truncateForTemporal(message, MAX_FAILURE_MESSAGE), 'bad_body', true, [
{
identifier,
- json,
- body,
+ json: truncateForTemporal(json, MAX_FAILURE_FIELD),
+ body: truncateForTemporal(body, MAX_FAILURE_FIELD),
},
]);
}