{"record":{"id":"2ef786da76c75e52","repo":"Tencent/WeKnora","slug":"sandbox-write-session-input-s-w","errorCode":null,"errorMessage":"sandbox: write session input %s: %w","messagePattern":"sandbox: write session input (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/session_manager.go","lineNumber":524,"sourceCode":"\tif err := m.requireRemoteBackend(); err != nil {\n\t\treturn err\n\t}\n\tif strings.TrimSpace(sessionID) == \"\" {\n\t\treturn errors.New(\"sandbox: session ID required for input staging\")\n\t}\n\tclean, err := cleanSessionInputPath(filePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\thandle, err := m.resolveSession(ctx, sessionID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := ignoreExistingDir(m.client.MakeDir(ctx, handle, path.Dir(clean))); err != nil {\n\t\treturn fmt.Errorf(\"sandbox: create input directory: %w\", err)\n\t}\n\tif err := m.client.WriteFile(ctx, handle, clean, content); err != nil {\n\t\treturn fmt.Errorf(\"sandbox: write session input %s: %w\", clean, err)\n\t}\n\treturn nil\n}\n\n// WriteSessionWorkspaceFile writes a model-authored file into the session's\n// remote sandbox, provisioning the sandbox on first call. Paths must sit\n// under /workspace and must not land in /workspace/input.\nfunc (m *SessionBoundManager) WriteSessionWorkspaceFile(\n\tctx context.Context, sessionID, filePath string, content []byte,\n) error {\n\tif err := m.requireRemoteBackend(); err != nil {\n\t\treturn err\n\t}\n\tif strings.TrimSpace(sessionID) == \"\" {\n\t\treturn errors.New(\"sandbox: session ID required for workspace write\")\n\t}\n\tclean, err := cleanSessionWorkspaceWritePath(filePath)\n\tif err != nil {","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/session_manager.go#L506-L542","documentation":"After successfully creating the parent directory, WriteSessionInputFile writes the attachment bytes via m.client.WriteFile; failure is wrapped as \"sandbox: write session input <path>\". This is the actual upload of the file content into the remote sandbox failing.","triggerScenarios":"Calling WriteSessionInputFile when client.WriteFile fails — provider API error, network interruption mid-upload, sandbox terminated during write, path rejected, or content exceeding size limits.","commonSituations":"Large attachment uploads timing out on slow networks, sandbox auto-reclaimed during a long transfer, provider 4xx/5xx responses, or writing to a read-only location.","solutions":["Read the wrapped error for the provider-level cause (timeout, 4xx, 5xx).","Retry the write; if the sandbox expired, let resolveSession provision a fresh one.","Reduce attachment size or increase the HTTP timeout in config for large uploads.","Confirm the target path is writable in the sandbox image."],"exampleFix":"// before\nerr := mgr.WriteSessionInputFile(ctx, sessionID, p, hugeBlob) // times out\n// after\ncfg.HTTPTimeout = 120 * time.Second // raise upload timeout\nerr := mgr.WriteSessionInputFile(ctx, sessionID, p, hugeBlob)","handlingStrategy":"retry","validationCode":"// pre-check size and path before upload\nif len(content) > maxUploadBytes {\n    return fmt.Errorf(\"attachment %s exceeds %d bytes\", name, maxUploadBytes)\n}\nif !path.IsAbs(path.Clean(target)) {\n    return fmt.Errorf(\"attachment path must be absolute\")\n}","typeGuard":null,"tryCatchPattern":"err := mgr.WriteSessionInputFile(ctx, sessionID, p, content)\nif err != nil && strings.Contains(err.Error(), \"write session input\") {\n    // transient upload failure: retry with backoff\n    backoff := time.Second\n    for i := 0; i < 3 && err != nil; i++ {\n        time.Sleep(backoff)\n        backoff *= 2\n        err = mgr.WriteSessionInputFile(ctx, sessionID, p, content)\n    }\n}","preventionTips":["Raise cfg HTTPTimeout for large attachment uploads.","Upload promptly after staging decisions — long gaps let sandboxes expire.","Chunk very large files instead of one huge WriteFile.","Handle provider 429/5xx with exponential backoff."],"tags":["go","sandbox","file-upload","network"],"backgroundTag":"remote-file-write-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}