#19551: fix(reply): make overflow fallback deterministic for empty recovery payloads
size: S
Cluster:
Surrogate Pair Handling Fixes
## Summary
- Problem: overflow recovery had edge paths that could finalize with no renderable payload (undefined/empty outcome) when `meta.error` was `context_overflow`.
- Why it matters: this creates silent/non-actionable behavior in a high-friction reliability path.
- What changed:
- Added deterministic overflow fallback when embedded overflow meta-error returns zero payloads.
- Added deterministic overflow fallback when payloads normalize/filter to empty in `runReplyAgent`.
- Added two regressions covering both paths.
- What did NOT change (scope boundary): no config/schema changes, no provider selection logic changes, no broad compaction refactor.
## Change Type (select all)
- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [ ] Security hardening
- [ ] Chore/infra
## Scope (select all touched areas)
- [x] Gateway / orchestration
- [ ] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [ ] Integrations
- [ ] API / contracts
- [ ] UI / DX
- [ ] CI/CD / infra
## Linked Issue/PR
- Closes #19550
- Related #1187
- Related #18095
- Related #18997
- Related #15749
- Related #18663
- Related #18719
## User-visible / Behavior Changes
- Overflow edge paths now return a deterministic fallback response instead of potentially finalizing with an empty/undefined payload.
## Security Impact (required)
- New permissions/capabilities? (`No`)
- Secrets/tokens handling changed? (`No`)
- New/changed network calls? (`No`)
- Command/tool execution surface changed? (`No`)
- Data access scope changed? (`No`)
- If any `Yes`, explain risk + mitigation: `N/A`
## Repro + Verification
### Environment
- OS: Ubuntu 25.10
- Runtime/container: local source checkout
- Model/provider: N/A (runner behavior)
- Integration/channel (if any): reply-agent execution path
- Relevant config (redacted): defaults
### Steps
1. Return `meta.error.kind = context_overflow` with `payloads: []` and unavailable session reset context.
2. Return overflow error payload that normalizes/filters to empty.
3. Observe finalization behavior.
### Expected
- Deterministic fallback payload is returned in both edge paths.
### Actual
- Before fix: empty/undefined-style finalization possible.
- After fix: explicit overflow fallback response returned.
## Evidence
Attach at least one:
- [x] Failing test/log before + passing after
- [x] Trace/log snippets
- [ ] Screenshot/recording
- [ ] Perf numbers (if relevant)
Regression tests added:
- `returns a deterministic overflow fallback when error meta has no payloads`
- `returns a deterministic overflow fallback when error payload normalizes to empty`
## Human Verification (required)
What you personally verified (not just CI), and how:
- Verified scenarios:
- `pnpm vitest run src/auto-reply/reply/agent-runner.runreplyagent.test.ts` passed (25 tests).
- `pnpm test` passed.
- `pnpm build` passed.
- Edge cases checked:
- existing compaction-reset and role-ordering tests still pass.
- What you did **not** verify:
- exhaustive channel-by-channel delivery matrix.
Note: `pnpm check` reports pre-existing repository-wide formatting issues (`Format issues found in above 1121 files`) unrelated to this PR's touched files.
## Compatibility / Migration
- Backward compatible? (`Yes`)
- Config/env changes? (`No`)
- Migration needed? (`No`)
- If yes, exact upgrade steps: `N/A`
## Failure Recovery (if this breaks)
- How to disable/revert this change quickly:
- Revert this PR commit.
- Files/config to restore:
- `src/auto-reply/reply/agent-runner-execution.ts`
- `src/auto-reply/reply/agent-runner.ts`
- `src/auto-reply/reply/agent-runner.runreplyagent.test.ts`
- Known bad symptoms reviewers should watch for:
- reappearance of empty/undefined finalization behavior on overflow edge paths.
## Risks and Mitigations
- Risk: fallback could trigger in cases where empty payload was intentional.
- Mitigation: fallback is restricted to explicit overflow/compaction error kinds.
- Risk: overlap with adjacent overflow/compaction work.
- Mitigation: keep patch narrowly scoped and link related issues/PRs.
## AI assistance
- AI-assisted: Yes (author verified code paths, tests, and scope).
Most Similar PRs
#19636: fix(agents): harden overflow recovery observability + subagent term...
by Jackten · 2026-02-18
81.8%
#21561: runner: add usage preflight guard for near-limit requests
by VontaJamal · 2026-02-20
69.6%
#19764: fix(security): OC-65 fix compaction counter reset to prevent contex...
by aether-ai-agent · 2026-02-18
68.0%
#15749: fix: improve context overflow error with diagnostic details
by superlowburn · 2026-02-13
67.1%
#20235: fix(reply): prevent duplicate final payloads in block pipeline
by PeterShanxin · 2026-02-18
66.7%
#19510: fix(config): preserve configured values on invalid config validatio...
by yash27-lab · 2026-02-17
66.3%
#21560: runner: sanitize invalid UTF-16 surrogates in session/prompt payloads
by VontaJamal · 2026-02-20
66.1%
#19878: fix: Handle compaction when fallback model has smaller context window
by gaurav10gg · 2026-02-18
66.0%
#23192: fix(slack): remove ack reaction on NO_REPLY when removeAckAfterRepl...
by SidQin-cyber · 2026-02-22
65.8%
#19252: fix(agents): continue model fallback on failover text payloads
by mahsumaktas · 2026-02-17
65.6%