Skip to content

fix(agent): bypass chat budget for image routes#1636

Merged
zerob13 merged 2 commits into
devfrom
fix/image-context-length
May 18, 2026
Merged

fix(agent): bypass chat budget for image routes#1636
zerob13 merged 2 commits into
devfrom
fix/image-context-length

Conversation

@zerob13
Copy link
Copy Markdown
Collaborator

@zerob13 zerob13 commented May 18, 2026

Summary

  • skip DeepChat chat context-budget preflight for explicit non-chat model routes such as image generation and TTS
  • keep ACP bypass and legacy chat-default behavior intact
  • add SDD docs and regression coverage for image endpoint requests with oversized chat-style payloads

Tests

  • pnpm exec vitest run test/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.ts test/main/presenter/agentRuntimePresenter/contextBudget.test.ts
  • pnpm run format
  • pnpm run i18n
  • pnpm run lint

Summary by CodeRabbit

  • Documentation

    • Added comprehensive spec, plan, and task docs for image-generation context budget bypass behavior and rollout.
  • Bug Fixes

    • Image generation and TTS requests now bypass chat context budget checks so non-chat endpoints are delivered without unintended token reductions; chat-model behavior is unchanged.
  • Tests

    • Added regression test ensuring image endpoint requests skip chat preflight/compaction and avoid false “request not sent” failures.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 729eb511-d0a4-4110-8715-9493ba155481

📥 Commits

Reviewing files that changed from the base of the PR and between 5eddb55 and 7018298.

📒 Files selected for processing (1)
  • src/main/presenter/agentRuntimePresenter/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/presenter/agentRuntimePresenter/index.ts

📝 Walkthrough

Walkthrough

This PR implements model-aware context budget bypass logic in AgentRuntimePresenter. DeepChat's chat context budget preflight is now skipped for image-generation, TTS, and non-chat endpoints while preserving existing behavior for chat models and ACP-bypassed providers. The change flows through message processing, manual compaction, streaming requests, and resume handling, with a regression test validating image endpoint bypass.

Changes

Image Generation Context Budget Bypass

Layer / File(s) Summary
Design and specification
docs/issues/image-generation-context-budget-bypass/plan.md, docs/issues/image-generation-context-budget-bypass/spec.md, docs/issues/image-generation-context-budget-bypass/tasks.md
Plan, spec, and task checklist describing the bypass behavior, runtime integration points, acceptance criteria, and test strategy for skipping chat context budget preflight on image/TTS/non-chat endpoints.
Core bypass decision logic and types
src/main/presenter/agentRuntimePresenter/index.ts
Import ApiEndpointType and ModelType, and introduce shouldUseDeepChatContextBudget / shouldBypassDeepChatContextBudget helpers that decide bypass behavior based on provider, model type, and endpoint configuration.
User message processing integration
src/main/presenter/agentRuntimePresenter/index.ts
Update processMessage to fetch model config and derive model-aware context budget decision, then select compaction intent accordingly.
Manual compaction flow
src/main/presenter/agentRuntimePresenter/index.ts
Update compactSession to pass model config into bypass logic so manual compaction respects the model-aware bypass decision.
Streaming request integration
src/main/presenter/agentRuntimePresenter/index.ts
Update runStreamForMessage to compute base model config, bind a bypass predicate, and conditionally set injected context length and gate context-pressure recovery based on per-request bypass decision.
Resume message handling
src/main/presenter/agentRuntimePresenter/index.ts
Update resumeAssistantMessage to fetch model config and compute model-aware context budget decision for resume-time budget selection and conditional compaction behavior.
Image endpoint regression test
test/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.ts
Add test for image-generation endpoint to verify preflight/compaction is bypassed and large tool payloads do not trigger "Request was not sent" errors.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • ThinkInAIXYZ/deepchat#1605: Both PRs modify context-budget/preflight handling in agentRuntimePresenter, overlapping at bypass rules, overflow recovery, and error diagnostics paths.

Poem

🐰 I hopped through configs, swift and spry,
Where images leap past the chat's sky,
Bypassing preflight, I cheer on the stream,
Tools stay large while the chat keeps its seam—
A soft thump for models, all things aligned.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(agent): bypass chat budget for image routes' directly and concisely describes the main change: adding logic to bypass DeepChat's chat context budget for image generation routes while preserving existing ACP bypass behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/image-context-length

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zerob13 zerob13 merged commit af39081 into dev May 18, 2026
3 checks passed
zhangmo8 added a commit that referenced this pull request May 18, 2026
* fix(agent): bypass chat budget for image routes (#1636)

* Initial plan

* merge(gen-video): resolve agent runtime conflict

Agent-Logs-Url: https://github.com/ThinkInAIXYZ/deepchat/sessions/7c9b17d6-272d-44a2-ab2d-57a554c773ab

Co-authored-by: zhangmo8 <43628500+zhangmo8@users.noreply.github.com>

---------

Co-authored-by: duskzhen <zerob13@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
zerob13 added a commit that referenced this pull request May 18, 2026
…ngs (#1637)

* feat: implement OpenAI-compatible video generation features and settings

* Copilot/fix review feedback pr 1637 (#1639)

* fix(agent): bypass chat budget for image routes (#1636)

* Initial plan

* merge(gen-video): resolve agent runtime conflict

Agent-Logs-Url: https://github.com/ThinkInAIXYZ/deepchat/sessions/7c9b17d6-272d-44a2-ab2d-57a554c773ab

Co-authored-by: zhangmo8 <43628500+zhangmo8@users.noreply.github.com>

---------

Co-authored-by: duskzhen <zerob13@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

* fix: review issue

---------

Co-authored-by: zhangmo8 <zhangmo8@users.noreply.github.com>
Co-authored-by: duskzhen <zerob13@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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