Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

A request the API rejects (400/413) keeps its user message in history and breaks the chat

Open
#240 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
ai, backend

Research direction

Start in agent/agent.ts at Agent.send (around lines 124-127), where addUserMessage runs before run, and at retryDecision, which returns null for 400/413. The minimal first step is to drop the trailing user message when the first request of a run fails with a non-retryable 4xx. Done means a test using MockApiServer that mocks a 400 on the first send, then sends again, shows the second request has no image. The image sniffing, size cap and tool-result changes are separate pieces and can be split off.

Written by the indexing model from the issue text.

Description

bug priority: high severity: high

Found in the 2026-10-09 codebase audit.

Problem

Agent.send (agent/agent.ts:124-127) calls addUserMessage and then run; nothing removes the message when the request fails for good. retryDecision returns null for 400/413, but the message stays and every later request re-sends it. Compaction keeps the last ~40k characters, so it is never summarized away.

Confirmed with MockApiServer: after a 400 on a message with an image, the next send re-sent the image.

Triggers:

  • An image to a text-only custom OpenAI-compatible model (acceptsImages is true for every non-Claude model).
  • Several large images over the 32 MB request limit (413).
  • Tool-result images (browser screenshots, MCP image blocks) to a model that refuses them; acceptsImages is checked only for user attachments.
  • Possibly a media type that doesn't match the bytes (taken from the extension).

Fix

When the first request of a run fails with a non-retryable 4xx before any assistant turn is recorded, discard the trailing user message (a message the API never accepted is not part of history). Also sniff image magic bytes, cap the total image size per request, and replace tool-result images with text when the model doesn't accept images.

Test

Mock a 400 on the first send, send again; the second request has no image.

Dominant language
TypeScript
Stars
2
Forks
2
Avg merge
5h 28m
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PierrunoYT/patch

All issues in PierrunoYT/patch

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.