Skip to content

fix(devin): recover oversized prompt history after rejection#6014

Merged
can1357 merged 7 commits into
can1357:mainfrom
riverpilot:fix/devin-payload-limit
Jul 20, 2026
Merged

fix(devin): recover oversized prompt history after rejection#6014
can1357 merged 7 commits into
can1357:mainfrom
riverpilot:fix/devin-payload-limit

Conversation

@riverpilot

@riverpilot riverpilot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Treat zero-output Devin invalid_argument: an internal error occurred trailers as context overflow when the serialized, compactable chatMessagePrompts history is already at least 512 KiB.
  • Exclude the system prompt, tool schemas, and other fixed request fields from the recovery threshold so context maintenance is selected only when it can shrink the qualifying bytes.
  • Preserve transient handling for small histories, fixed-envelope-heavy requests, partial-output failures, and specific invalid-argument responses.

Related #4218

Screenshots

No visual change.

Testing

  • bun test packages/ai/test/devin-large-request-recovery.test.ts — 5 passed
  • bun test packages/ai/test/devin-frame-cap.test.ts packages/ai/test/devin-streaming-args.test.ts packages/ai/test/devin-large-request-recovery.test.ts — 8 passed
  • bun test packages/coding-agent/test/agent-session-auto-compaction-progress-guard.test.ts — 28 passed
  • bun --cwd=packages/ai test — 3,009 passed, 337 skipped, 0 failed
  • bun run check:ts

Risk

  • The 512 KiB value is a recovery heuristic, not an asserted Devin backend limit. It is consulted only after the server rejects a zero-output request with the observed opaque trailer, so accepted large histories remain unaffected.
  • The qualifying size is re-encoded from only the repeated history field after rejection; large system prompts and tool schemas retain transient retry behavior.
  • Small intermittent Devin errors and errors after partial output retain their existing transient retry behavior.

Notes

  • The history measurement uses the uncompressed protobuf field bytes because the Connect server decodes the gzip frame before request handling.
  • The original error text and trace ID remain intact for backend diagnosis.

AI Review Report

Focused review verified that AIError.finalize preserves the structural ContextOverflow flag alongside text-derived Transient, AgentSession prioritizes overflow maintenance over retry, the revised threshold measures only compactable history, and partial-output/fixed-envelope cases remain non-overflow. No substantive findings remain.

Security Audit

  • No prompt or tool-result content is added to logs; only uncompressed and compressed byte counts are recorded.
  • No new network requests, credential handling, or silent history deletion paths are introduced.

@github-actions github-actions Bot added the vouched Passed the vouch gate label Jul 18, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

review:p2 — focused implementation; the six targeted Devin provider tests pass, but the recovery heuristic needs explicit maintainer sign-off.
Blocking: total protobuf size is not equivalent to compactable history, so the opaque intermittent trailer can misroute large system-prompt/tool-schema requests into ineffective context maintenance.
Coverage: no partial-output case protects the new zero-output guard. Maintainer call: accept this heuristic tradeoff or require size-causal evidence/a shrinkable-history measurement.
Thanks for the tightly scoped patch and regression coverage, @riverpilot.

Comment thread packages/ai/src/providers/devin.ts Outdated
Comment thread packages/ai/test/devin-large-request-recovery.test.ts
@riverpilot
riverpilot force-pushed the fix/devin-payload-limit branch from 314a919 to 73b9760 Compare July 18, 2026 19:52
@riverpilot

Copy link
Copy Markdown
Contributor Author

Addressed both review findings in 73b9760fe:

  • Recovery now measures only serialized chatMessagePrompts, excluding system prompt/tool-schema bytes that context maintenance cannot shrink.
  • Added negative coverage for a >512 KiB fixed request envelope with small history.
  • Added partial-output coverage using a real Devin text-delta frame before the trailer; it remains non-overflow/transient.

Re-verified: 8 focused Devin tests, 3,009 AI tests (337 skipped), and bun run check:ts pass.

@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: d6ce706662

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/ai/src/providers/devin.ts

@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: 450856e95f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/ai/src/providers/devin.ts Outdated
@riverpilot
riverpilot force-pushed the fix/devin-payload-limit branch from 8acfae8 to cc3b201 Compare July 20, 2026 17:08
@riverpilot

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main to clear the merge conflict (packages/ai/CHANGELOG.md and related history drift). No behavioral changes in this push.

  • New head: cc3b2011b
  • Verification: bun test packages/ai/test/devin-large-request-recovery.test.ts → 9 pass
  • Merge state after push: clean / mergeable

@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: cc3b2011b5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/ai/src/providers/devin.ts Outdated
Rebase onto main tightened AssistantMessage content to block arrays;
update the large tool-execution recovery fixture accordingly.
@riverpilot

Copy link
Copy Markdown
Contributor Author

Follow-up after rebase: CI Lint, type check & web build failed because the large tool-execution recovery fixture still used a string content + top-level toolCalls shape. Updated it to the current AssistantMessage block-array form.

  • New head: dcb04238d
  • Verification: bun run --cwd packages/ai check:types and bun test packages/ai/test/devin-large-request-recovery.test.ts → 9 pass

@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: 9cc82b1f03

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/ai/CHANGELOG.md Outdated
// A trailing developer message can accompany the current user
// prompt. Earlier user-role records may instead be flushed
// execution history and must remain eligible for compaction.
if (lastRole === "developer") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude all trailing user active-turn messages

The fresh remaining active-tail case is when the same prompt ends with another user-role companion: this backward scan is skipped unless the final role is developer, but #promptWithMessage can append same-turn messages after the prompt (e.g. file mentions after messages.push(message) in packages/coding-agent/src/session/agent-session.ts:8876-8892), and image file mentions convert to role: "user" in packages/coding-agent/src/session/messages.ts:845-872. For a huge current user prompt followed by a small user companion, the huge live prompt is counted in shrinkablePrompts, so the opaque Devin rejection is mislabeled as ContextOverflow and sent through compaction even though that active tail cannot be shrunk.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Investigated against the existing regression suite. The history contains indistinguishable consecutive user-role records: flushed prior execution history must remain compactable, while same-turn user companions must be excluded. Without an active-turn boundary in the Message/Context contract, excluding every trailing user record breaks the prior-history regression and misclassifies large flushed execution output. The current implementation preserves that safety invariant; this finding needs an explicit active-turn boundary before it can be implemented without regressing the earlier P1/P2 fixes.

@can1357
can1357 merged commit cc0635e into can1357:main Jul 20, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix provider:devin providers LLM provider-specific issues review:p2 triaged vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants