Skip to content

Killing a gptel buffer while it's typing blocks Emacs until the response is complete #1448

Description

@igmacs

Please update gptel first -- errors are often fixed by the time they're reported.

  • I have updated gptel to the latest commit and tested that the issue still exists

Bug Description

If you kill the gptel buffer while it's typing, you get constant errors for a while, and can't do anything with Emacs until the errors finish. I guess they occur while the model is still answering, and finish when the answer is complete.

The errors are the following, in a loop:

error in process filter: gptel-curl--stream-filter: Wrong type argument: stringp, nil
error in process filter: Wrong type argument: stringp, nil

I know the proper way to abort a gptel query is with gptel-abort, but if you do a prompt and see the model is hallucinating the answer or not giving you the result you expected, a natural reaction could be to just kill the buffer, or at least I did that.

Running the following in the gptel buffer fixes it: (add-hook 'kill-buffer-hook (lambda () (gptel-abort (current-buffer))) 0 t)

Backend

Other (please specify in Additional Context)

Steps to Reproduce

  1. M-x gptel
  2. Query something like this: Please output the numbers 1 to 500, each in a separate line
  3. As soon as it starts writing the output, do M-x kill-buffer

Additional Context

I doubt this is dependent of particular versions or backends, but my Emacs version is 30.2, my curl version 8.6.0, I'm using Copilot, and of course I pulled the latest gptel changes before trying to reproduce again.

Backtrace

If you toggle debug on error, the backtrace that can appear seems to be a little bit non-determistic, I provide here the two versions I got:


Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  gptel-curl--stream-insert-response("\n" (:uuid "af31290e5fb845593919dee23fb66d94" :transformer #f(compiled-function (str) #<bytecode 0x19399de8589fb138>) :callback gptel-curl--stream-insert-response :history (WAIT INIT) :data (:model "gpt-4.1" :messages [(:role "system" :content "You are a large language model living in Emacs and a helpful assistant. Respond concisely.") (:role "user" :content "* Please output the numbers 1 to 500, each in a separate line")] :stream t :stream_options (:include_usage t)) :buffer #<killed buffer> :position #<marker in no buffer> :transforms (gptel--transform-apply-preset gptel--transform-add-context) :stream t :backend #s(gptel--gh :name "Copilot" :host "api.githubcopilot.com" :header #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_57> :protocol "https" :stream t :endpoint "/chat/completions" :key nil :models (gpt-4.1 gpt-4o gpt-5-mini gpt-5.1 gpt-5.1-codex gpt-5.1-codex-max gpt-5.1-codex-mini gpt-5.2 gpt-5.2-codex gpt-5.3-codex gpt-5.4 gpt-5.4-mini gpt-5.5 claude-haiku-4.5 claude-opus-4.5 claude-opus-4.6 claude-opus-4.7 claude-sonnet-4 claude-sonnet-4.5 claude-sonnet-4.6 gemini-2.5-pro gemini-3-flash-preview gemini-3-pro-preview gemini-3.1-pro-preview gemini-3.5-flash grok-code-fast-1) :url #f(compiled-function (info) #<bytecode -0x1b1119c8277c3e5c>) :request-params nil :curl-args nil :coding-system nil :token (:agent_mode_auto_approval t :annotations_enabled t :azure_only :json-false :blackbird_clientside_indexing :json-false :blackbird_external_indexing t :chat_enabled t :chat_jetbrains_enabled t :code_quote_enabled t :code_review_enabled t :codesearch t :copilotignore_enabled :json-false :endpoints (:api "https://api.individual.githubcopilot.com" :origin-tracker "https://origin-tracker.individual.githubcopilot.com" :proxy "https://proxy.individual.githubcopilot.com" :telemetry "https://telemetry.individual.githubcopilot.com") :expires_at 1781084339 :iat 1781082539 :individual t :limited_user_quotas :null :limited_user_reset_date :null :public_suggestions "disabled" :refresh_in 1500 :sku "monthly_subscriber_quota" :telemetry "disabled" :token "tid=cc7391a1f6e380788be9f639b036af5b;exp=1781084339;iat=1781082539;sku=monthly_subscriber_quota;proxy-ep=proxy.individual.githubcopilot.com;st=dotcom;chat=1;cit=1;malfil=1;editor_preview_features=1;agent_mode=1;agent_mode_auto_approval=1;mcp=1;blackbird_external_indexing=1;client_byok=0;ccr=1;ip=139.47.35.71;asn=AS15704:b21669c2ec53403b6e031bfaf52ccb7d598ed98f712a22a973ef6868800545b2" :tracking_id "cc7391a1f6e380788be9f639b036af5b" :xcode t :xcode_chat :json-false) :github-token "ghu_kvqymHP5FsOJSnBYo72h0BFGX1ccKE41ZTTU" :sessionid nil :machineid "cdfe0dc3adc72d5d8d4a4d2871e66fbf16c9b33dbbfb821c377be240bef5aedbd" :responses-backend #s(gptel-openai-responses :name "Copilot" :host "api.githubcopilot.com" :header #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_57> :protocol "https" :stream t :endpoint "/v1/responses" :key nil :models nil :url #f(compiled-function (info) #<bytecode -0x1b1119c8277c3e5c>) :request-params nil :curl-args nil :coding-system nil)) :model gpt-4.1 :include-reasoning ignore :gh-initiator "agent" :http-status "200" :status "HTTP/2 200" :reasoning-block done :tracking-marker #<marker (moves after insertion) in no buffer>))
  gptel-curl--stream-filter(#<process gptel-curl> "data: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"\\n\"}}],\"created\":1781082541,\"id\":\"chatcmpl-Dp9DhCzSGDlOcQ7Us6Yv6HCF84D6P\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\n")



Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  gptel-curl--stream-insert-response("\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45" (:uuid "f4ee29272ae45ba5302e561cb70f9484" :transformer #f(compiled-function (str) #<bytecode 0x19730bd0b11fb138>) :callback gptel-curl--stream-insert-response :history (WAIT INIT) :data (:model "gpt-4.1" :messages [(:role "system" :content "You are a large language model living in Emacs and a helpful assistant. Respond concisely.") (:role "user" :content "* Please output the numbers 1 to 500, each in a separate line")] :stream t :stream_options (:include_usage t)) :buffer #<killed buffer> :position #<marker in no buffer> :transforms (gptel--transform-apply-preset gptel--transform-add-context) :stream t :backend #s(gptel--gh :name "Copilot" :host "api.githubcopilot.com" :header #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_57> :protocol "https" :stream t :endpoint "/chat/completions" :key nil :models (gpt-4.1 gpt-4o gpt-5-mini gpt-5.1 gpt-5.1-codex gpt-5.1-codex-max gpt-5.1-codex-mini gpt-5.2 gpt-5.2-codex gpt-5.3-codex gpt-5.4 gpt-5.4-mini gpt-5.5 claude-haiku-4.5 claude-opus-4.5 claude-opus-4.6 claude-opus-4.7 claude-sonnet-4 claude-sonnet-4.5 claude-sonnet-4.6 gemini-2.5-pro gemini-3-flash-preview gemini-3-pro-preview gemini-3.1-pro-preview gemini-3.5-flash grok-code-fast-1) :url #f(compiled-function (info) #<bytecode -0x1b1119c8277c3e5c>) :request-params nil :curl-args nil :coding-system nil :token (:agent_mode_auto_approval t :annotations_enabled t :azure_only :json-false :blackbird_clientside_indexing :json-false :blackbird_external_indexing t :chat_enabled t :chat_jetbrains_enabled t :code_quote_enabled t :code_review_enabled t :codesearch t :copilotignore_enabled :json-false :endpoints (:api "https://api.individual.githubcopilot.com" :origin-tracker "https://origin-tracker.individual.githubcopilot.com" :proxy "https://proxy.individual.githubcopilot.com" :telemetry "https://telemetry.individual.githubcopilot.com") :expires_at 1781084339 :iat 1781082539 :individual t :limited_user_quotas :null :limited_user_reset_date :null :public_suggestions "disabled" :refresh_in 1500 :sku "monthly_subscriber_quota" :telemetry "disabled" :token "tid=cc7391a1f6e380788be9f639b036af5b;exp=1781084339;iat=1781082539;sku=monthly_subscriber_quota;proxy-ep=proxy.individual.githubcopilot.com;st=dotcom;chat=1;cit=1;malfil=1;editor_preview_features=1;agent_mode=1;agent_mode_auto_approval=1;mcp=1;blackbird_external_indexing=1;client_byok=0;ccr=1;ip=139.47.35.71;asn=AS15704:b21669c2ec53403b6e031bfaf52ccb7d598ed98f712a22a973ef6868800545b2" :tracking_id "cc7391a1f6e380788be9f639b036af5b" :xcode t :xcode_chat :json-false) :github-token "ghu_kvqymHP5FsOJSnBYo72h0BFGX1ccKE41ZTTU" :sessionid nil :machineid "cdfe0dc3adc72d5d8d4a4d2871e66fbf16c9b33dbbfb821c377be240bef5aedbd" :responses-backend #s(gptel-openai-responses :name "Copilot" :host "api.githubcopilot.com" :header #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_57> :protocol "https" :stream t :endpoint "/v1/responses" :key nil :models nil :url #f(compiled-function (info) #<bytecode -0x1b1119c8277c3e5c>) :request-params nil :curl-args nil :coding-system nil)) :model gpt-4.1 :include-reasoning ignore :gh-initiator "agent" :http-status "200" :status "HTTP/2 200" :reasoning-block done :tracking-marker #<marker (moves after insertion) in no buffer>))
  gptel-curl--stream-filter(#<process gptel-curl<3>> "data: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"\\n\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"30\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"\\n\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"31\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"\\n\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"32\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"\\n\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"33\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}},\"delta\":{\"content\":\"\\n\"}}],\"created\":1781082765,\"id\":\"chatcmpl-Dp9HJm4KXjmUiQRRBUFYfWlfjLSeA\",\"model\":\"gpt-4.1-2025-04-14\",\"system_fingerprint\":\"fp_dc49d4fcba\"}\n\ndata: {\"choices\":[{\"index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"sev...")


Also, when getting them, I realized that Emacs it's not exactly blocked, but I guess something different. If debug on error is not enabled, for me it looks like it's blocked. But if it's enabled, the backtrace buffer is selected, and there I can move the point, although I can't switch buffers either, so the result is mostly the same.

Log Information

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions