Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix: name the attachment size limit when TeamHub refuses a file
Dongdong Chen7ef13606b38d
diff --git a/apps/teamhub/internal/app/handlers_message_attachment.go b/apps/teamhub/internal/app/handlers_message_attachment.goindex 60c30ce2..41d6744b 100644--- a/apps/teamhub/internal/app/handlers_message_attachment.go+++ b/apps/teamhub/internal/app/handlers_message_attachment.go@@ -11,6 +11,7 @@ import ("github.com/simplexai-labs/linger/apps/teamhub/internal/collaboration""github.com/simplexai-labs/linger/apps/teamhub/internal/idempotency""github.com/simplexai-labs/linger/apps/teamhub/internal/secretbox"+ httpapi "github.com/simplexai-labs/linger/contracts-go/teamhubpublic")func (a *App) uploadMessageAttachment(c *gin.Context) {@@ -21,7 +22,9 @@ func (a *App) uploadMessageAttachment(c *gin.Context) {upload, err := a.parseMessageAttachmentUpload(c)if err != nil {if errors.Is(err, artifactstore.ErrTooLarge) || isMaxBytesError(err) {- a.writeError(c, http.StatusRequestEntityTooLarge, "PAYLOAD_TOO_LARGE", "message attachment exceeds the configured limit")+ code, limit := "too_large", a.cfg.ArtifactMaxBytes+ a.writeErrorWithDetails(c, http.StatusRequestEntityTooLarge, "PAYLOAD_TOO_LARGE", "message attachment exceeds the configured limit",+ []httpapi.ErrorDetail{{Field: "content", Code: &code, Reason: "exceeds the attachment size limit", LimitBytes: &limit}})} else {a.writeError(c, http.StatusBadRequest, "INVALID_REQUEST", "message attachment upload is invalid")}diff --git a/apps/teamhub/internal/app/handlers_upload_too_large_test.go b/apps/teamhub/internal/app/handlers_upload_too_large_test.goindex 630ba246..094de7d3 100644--- a/apps/teamhub/internal/app/handlers_upload_too_large_test.go+++ b/apps/teamhub/internal/app/handlers_upload_too_large_test.go@@ -2,6 +2,7 @@ package appimport ("bytes"+ "encoding/json""mime/multipart""net/http""net/http/httptest"@@ -11,6 +12,7 @@ import ("github.com/gin-gonic/gin""github.com/simplexai-labs/linger/apps/teamhub/internal/config"+ httpapi "github.com/simplexai-labs/linger/contracts-go/teamhubpublic")// The multipart parser must surface *http.MaxBytesError so handlers map an@@ -56,3 +58,55 @@ func TestMultipartUploadsMapOversizedBodyToPayloadTooLarge(t *testing.T) {})}}++// A refused message attachment names the limit as a structured detail, so a+// client can tell the person how large a file may be.+func TestMessageAttachmentTooLargeNamesTheLimit(t *testing.T) {+ t.Parallel()+ const maxBytes = 16+ for name, size := range map[string]int{+ "file over the limit": maxBytes + 1,+ "body over the limit": maxBytes + (1 << 20) + 1,+ } {+ t.Run(name, func(t *testing.T) {+ var body bytes.Buffer+ writer := multipart.NewWriter(&body)+ if err := writer.WriteField("filename", "big.zip"); err != nil {+ t.Fatal(err)+ }+ part, err := writer.CreateFormFile("content", "big.zip")+ if err != nil {+ t.Fatal(err)+ }+ if _, err := part.Write(bytes.Repeat([]byte("x"), size)); err != nil {+ t.Fatal(err)+ }+ if err := writer.Close(); err != nil {+ t.Fatal(err)+ }+ recorder := httptest.NewRecorder()+ context, _ := gin.CreateTestContext(recorder)+ context.Set("request_id", "request-attachment-too-large")+ context.Request = httptest.NewRequest(http.MethodPost, "/upload", &body)+ context.Request.Header.Set("Content-Type", writer.FormDataContentType())+ context.Request.Header.Set("Idempotency-Key", "attachment-too-large-key")+ (&App{cfg: config.ForTest(func(c *config.Config) {+ c.ArtifactMaxBytes = maxBytes+ })}).uploadMessageAttachment(context)++ var response httpapi.ErrorResponse+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil {+ t.Fatal(err)+ }+ if recorder.Code != http.StatusRequestEntityTooLarge || response.Error.Code != "PAYLOAD_TOO_LARGE" ||+ response.Error.Details == nil || len(*response.Error.Details) != 1 {+ t.Fatalf("status=%d body=%s", recorder.Code, recorder.Body.String())+ }+ detail := (*response.Error.Details)[0]+ if detail.Field != "content" || detail.Code == nil || *detail.Code != "too_large" ||+ detail.LimitBytes == nil || *detail.LimitBytes != maxBytes {+ t.Fatalf("detail = %+v", detail)+ }+ })+ }+}diff --git a/apps/web/src/features/rooms/chat/message-composer.test.tsx b/apps/web/src/features/rooms/chat/message-composer.test.tsxindex bfc83ee4..804ba850 100644--- a/apps/web/src/features/rooms/chat/message-composer.test.tsx+++ b/apps/web/src/features/rooms/chat/message-composer.test.tsx@@ -17,6 +17,7 @@ import {formatSkillToken,} from "./message-composer-references";import { TEAMHUB_MESSAGE_MAX_LENGTH } from "./use-composer-draft";+import { TeamHubError } from "@/features/teamhub/teamhub-error";import { createTeamHubMessageContent } from "@/features/teamhub/teamhub-message-content";describe("MessageComposer", () => {@@ -461,6 +462,40 @@ describe("MessageComposer", () => {});});+ it("names the file's size and the attachment limit when TeamHub refuses a large file", async () => {+ const onStageAttachment = vi.fn().mockRejectedValue(+ new TeamHubError({+ code: "PAYLOAD_TOO_LARGE",+ details: [+ {+ code: "too_large",+ field: "content",+ limit_bytes: 50 * 1024 * 1024,+ reason: "exceeds the attachment size limit",+ },+ ],+ message: "message attachment exceeds the configured limit",+ status: 413,+ }),+ );+ const file = new File([], "big.zip");+ Object.defineProperty(file, "size", { value: 60 * 1024 * 1024 });+ render(+ <MessageComposer+ attachmentEnabled+ onSend={vi.fn()}+ onStageAttachment={onStageAttachment}+ />,+ );+ fireEvent.change(screen.getByLabelText("Choose message attachments"), {+ target: { files: [file] },+ });++ expect(await screen.findByRole("alert")).toHaveTextContent(+ "big.zip: Attachments can be up to 50 MB, and this file is 60 MB.",+ );+ });+it("keeps the compact attachment remove control visible and cancels its staged upload", async () => {const onCancelAttachment = vi.fn().mockResolvedValue(undefined);const onStageAttachment = vi.fn().mockResolvedValue(undefined);diff --git a/apps/web/src/features/rooms/chat/use-composer-attachments.ts b/apps/web/src/features/rooms/chat/use-composer-attachments.tsindex 6083ef8d..bacd8acb 100644--- a/apps/web/src/features/rooms/chat/use-composer-attachments.ts+++ b/apps/web/src/features/rooms/chat/use-composer-attachments.ts@@ -8,6 +8,8 @@ import {} from "react";import { createTeamHubIdempotencyKey } from "@/features/teamhub/teamhub-client";+import { TeamHubError } from "@/features/teamhub/teamhub-error";+import { formatBytes } from "@/lib/format-bytes";import {type ComposerAttachment,composerAttachmentStore,@@ -174,8 +176,7 @@ export function useComposerAttachments({candidate.clientId === attachment.clientId? {...candidate,- error:- error instanceof Error ? error.message : "Upload failed.",+ error: uploadFailureCopy(error, attachment.file),status: "failed",}: candidate,@@ -260,6 +261,18 @@ export function filesFromClipboard(clipboardData: DataTransfer): File[] {});}+/** Why one upload failed; TeamHub's limit refusal names both sizes. */+function uploadFailureCopy(error: unknown, file: File) {+ if (error instanceof TeamHubError && error.code === "PAYLOAD_TOO_LARGE") {+ const limit = error.details?.find(+ (detail) => detail.code === "too_large",+ )?.limit_bytes;+ if (limit !== undefined)+ return `Attachments can be up to ${formatBytes(limit)}, and this file is ${formatBytes(file.size)}.`;+ }+ return error instanceof Error ? error.message : "Upload failed.";+}+function validateMessageAttachments(files: File[]) {if (files.length > maximumAttachmentCount) {return {diff --git a/contracts/generated/go/nodeservicesinternal/openapi.gen.go b/contracts/generated/go/nodeservicesinternal/openapi.gen.goindex 243886b5..d49cea50 100644--- a/contracts/generated/go/nodeservicesinternal/openapi.gen.go+++ b/contracts/generated/go/nodeservicesinternal/openapi.gen.go@@ -1814,9 +1814,12 @@ type Error struct {// ErrorDetail defines model for ErrorDetail.type ErrorDetail struct {// Code Optional stable classification for this individual validation issue.- Code *string `json:"code,omitempty"`- Field string `json:"field"`- Reason string `json:"reason"`+ Code *string `json:"code,omitempty"`+ Field string `json:"field"`++ // LimitBytes With code too_large, the largest size the field accepts, in bytes.+ LimitBytes *int64 `json:"limit_bytes,omitempty"`+ Reason string `json:"reason"`}// ErrorResponse defines model for ErrorResponse.diff --git a/contracts/generated/go/teamhubinternal/openapi.gen.go b/contracts/generated/go/teamhubinternal/openapi.gen.goindex ced00238..8187a1e3 100644--- a/contracts/generated/go/teamhubinternal/openapi.gen.go+++ b/contracts/generated/go/teamhubinternal/openapi.gen.go@@ -3068,9 +3068,12 @@ type Error struct {// ErrorDetail defines model for ErrorDetail.type ErrorDetail struct {// Code Optional stable classification for this individual validation issue.- Code *string `json:"code,omitempty"`- Field string `json:"field"`- Reason string `json:"reason"`+ Code *string `json:"code,omitempty"`+ Field string `json:"field"`++ // LimitBytes With code too_large, the largest size the field accepts, in bytes.+ LimitBytes *int64 `json:"limit_bytes,omitempty"`+ Reason string `json:"reason"`}// ErrorResponse defines model for ErrorResponse.diff --git a/contracts/generated/go/teamhubpublic/openapi.gen.go b/contracts/generated/go/teamhubpublic/openapi.gen.goindex 7efa570e..2f222e10 100644--- a/contracts/generated/go/teamhubpublic/openapi.gen.go+++ b/contracts/generated/go/teamhubpublic/openapi.gen.go@@ -6084,9 +6084,12 @@ type Error struct {// ErrorDetail defines model for ErrorDetail.type ErrorDetail struct {// Code Optional stable classification for this individual validation issue.- Code *string `json:"code,omitempty"`- Field string `json:"field"`- Reason string `json:"reason"`+ Code *string `json:"code,omitempty"`+ Field string `json:"field"`++ // LimitBytes With code too_large, the largest size the field accepts, in bytes.+ LimitBytes *int64 `json:"limit_bytes,omitempty"`+ Reason string `json:"reason"`}// ErrorResponse defines model for ErrorResponse.diff --git a/contracts/generated/typescript/src/generated/node-services-internal/types.ts b/contracts/generated/typescript/src/generated/node-services-internal/types.tsindex 15046f4d..b963a3db 100644--- a/contracts/generated/typescript/src/generated/node-services-internal/types.ts+++ b/contracts/generated/typescript/src/generated/node-services-internal/types.ts@@ -1448,6 +1448,11 @@ export interface components {/** @description Optional stable classification for this individual validation issue. */code?: string;reason: string;+ /**+ * Format: int64+ * @description With code too_large, the largest size the field accepts, in bytes.+ */+ limit_bytes?: number;};Error: {/** @example ROOM_NOT_FOUND */diff --git a/contracts/generated/typescript/src/generated/teamhub-internal/types.ts b/contracts/generated/typescript/src/generated/teamhub-internal/types.tsindex e722f541..376d4350 100644--- a/contracts/generated/typescript/src/generated/teamhub-internal/types.ts+++ b/contracts/generated/typescript/src/generated/teamhub-internal/types.ts@@ -1604,6 +1604,11 @@ export interface components {/** @description Optional stable classification for this individual validation issue. */code?: string;reason: string;+ /**+ * Format: int64+ * @description With code too_large, the largest size the field accepts, in bytes.+ */+ limit_bytes?: number;};Error: {/** @example ROOM_NOT_FOUND */diff --git a/contracts/generated/typescript/src/generated/teamhub-public/types.ts b/contracts/generated/typescript/src/generated/teamhub-public/types.tsindex 73c0575d..e3793e03 100644--- a/contracts/generated/typescript/src/generated/teamhub-public/types.ts+++ b/contracts/generated/typescript/src/generated/teamhub-public/types.ts@@ -4194,6 +4194,11 @@ export interface components {/** @description Optional stable classification for this individual validation issue. */code?: string;reason: string;+ /**+ * Format: int64+ * @description With code too_large, the largest size the field accepts, in bytes.+ */+ limit_bytes?: number;};Error: {/** @example ROOM_NOT_FOUND */diff --git a/contracts/openapi/components/common.yaml b/contracts/openapi/components/common.yamlindex 16f74425..f2f0fb4b 100644--- a/contracts/openapi/components/common.yaml+++ b/contracts/openapi/components/common.yaml@@ -351,6 +351,11 @@ components:reason:type: stringminLength: 1+ limit_bytes:+ description: With code too_large, the largest size the field accepts, in bytes.+ type: integer+ format: int64+ minimum: 0Error:type: objectadditionalProperties: false