Skip to content

fix(ai-chat): preserve image uploads with compaction - #288

Merged
olliethedev merged 2 commits into
mainfrom
fix/compaction-images
Oct 2, 2026
Merged

olliethedev merged 2 commits into
mainfrom
fix/compaction-images

Conversation

@olliethedev

@olliethedev olliethedev commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Enabling chat compaction rejects image attachments in both public and database-persisted chats. Removing that rejection alone would leave the text summarizer unable to see older images and count inline image bytes as text tokens.

Solution

Keep recent image attachments in the model context. When older turns are compacted, summarize their text and then pass each image as vision input to incorporate its contents into the summary. Preserve original messages and attachments, and only advance the checkpoint after the entire summary succeeds.

Estimate images separately from encoded bytes, with a default allowance of 4096 tokens per image and an optional imageTokenEstimate for models with higher image costs. Existing attachment validation and authorization still apply. Non-image files remain unsupported with compaction. Document the behavior and prepare Stack/Codegen 4.5.1.

Public browser composers now use an explicitly configured upload handler, matching the public API. Saved-chat attachment permission checks and upload-endpoint authentication remain intact. The generated demos cover selecting and sending an inline image with compaction enabled.

Follow-up to #287 based on consumer verification and the requested image-support parity.

Verification

  • Full unit suite: 1,359 passed (1,163 Stack + 196 Codegen).
  • pnpm typecheck, pnpm lint, pnpm build, registry regeneration, and documentation production build passed.
  • Regression coverage: inline/remote image budgeting, image-shaped tool results remaining text, actual vision inputs, both chat modes across compaction, recent-image retention, saved attachment preservation, and checkpoint reuse after reload.
  • Real GPT-4o check: uploaded a screenshot, acknowledged it without repeating the version shown, forced compaction, then recovered the version from the older image in both modes. Saved-chat reload recovered it again without another compaction.
  • Local Next.js public-chat browser suite: 9 passed, including image selection, preview, request payload, and actual model response with compaction enabled.
  • Both independent review axes are clear. The two initial bot findings are fixed, answered, and resolved. All hosted checks, three framework browser suites, and Vercel deployments passed on f38a969. Final bot review completed with no findings on that commit.

Public chat receives an uploaded screenshot and reads its version with compaction enabled

@vercel

vercel Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
better-stack-docs Ready Ready Preview Oct 2, 2026 6:00pm UTC
better-stack-playground Ready Ready Preview Oct 2, 2026 6:00pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T18:04:33.327156Z f38a969 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@olliethedev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5927787c72

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/cli/package.json Resolved
@olliethedev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: f38a969374

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@olliethedev
olliethedev merged commit 53cced7 into main Oct 2, 2026
14 checks passed

This branch was successfully deployed

2 active deployments
Preview – better-stack-docs — f38a9693 Deployed Oct 2, 2026 by vercel[bot]
Preview – better-stack-playground — f38a9693 Deployed Oct 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant