agentscope-ai / agentscope-ai/QwenPaw

[Bug] RetryChatModel hardcoded 32768 context_size fallback causes CONTEXT_UNFIT (>31130 tokens) for all models

Abierto
#7,576 5 comentarios 0 reacciones 1 asignado Reclamado por @wangfei010313 Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
35k
Forks
3.1k
Merge medio
1 d 13 h
PR fusionados (30 d)
228

Descripción

## QwenPaw Version
v2.1.0 through v2.2.0 (confirmed buggy in all published releases)

## Description
The `RetryChatModel.__init__` in `src/qwenpaw/providers/retry_chat_model.py` contains a hardcoded fallback that forces ALL models to use a 32768 token context window:

```python
context_size=getattr(inner, "context_size", 32768),
model=getattr(inner, "model", "unknown"),
```

This means:
- Even models configured with `max_input_length=131072` (128K) in agent.json get capped at 32768
- The compaction hard limit becomes `32768 × 0.95 = 31130 tokens`
- When conversation context exceeds ~31K tokens, QwenPaw throws `MODEL_CONTEXT_LENGTH_EXCEEDED` / `CONTEXT_UNFIT`
- Error message shows `model 'unknown'` because `getattr(inner, "model", "unknown")` also defaults

## Error Log Example
```
ContextWindowUnfitError: CONTEXT_UNFIT: context compaction could not fit the active request into the model input window (31430 > 31130 tokens)
```

First observed: 2026-08-23 16:35:41 UTC on hosted QwenPaw (AgentScope platform)

## Root Cause Analysis
The `get_model_max_input_length()` function in `src/qwenpaw/config/config.py` was updated (likely in PR #5586) to query `ProviderManager.get_active_model()`, but this only affects the **display** of context usage. The actual compaction hard limit comes from `agent.model.context_size` in `manager.py`, which reads from the `RetryChatModel` wrapper — and that wrapper still has the hardcoded 32768 fallback.

Evidence:
- `src/qwenpaw/agents/context/scroll/manager.py` line ~16566:
```python
hard_limit = int(agent.model.context_size)
```
- `src/qwenpaw/providers/retry_chat_model.py` line ~13518:
```python
context_size=getattr(inner, "context_size", 32768),
```

Both are **identical** across v2.1.0, v2.2.0-beta.1, and v2.2.0. The bug persists in all published releases.

## Verification
Checked source code for:
- v2.1.0: ❌ BUGGY (32768 fallback present)
- v2.2.0-beta.1 (2026-08-27): ❌ BUGGY (32768 fallback present)
- v2.2.0 (2026-09-03): ❌ BUGGY (32768 fallback present)
- main branch: ❌ BUGGY (32768 fallback present)

PR #5586 is still open and unmerged, but it only fixes the config-level function, NOT the RetryChatModel wrapper.

## Expected Behavior
Models configured with larger context windows (e.g., 128K via `max_input_length: 131072`) should have those values respected. The 32768 fallback should only apply when no context size can be determined, not as a global cap.

## Workarounds Used
1. Start fresh chat sessions before context reaches ~31K tokens
2. Self-host QwenPaw v2.0.1 (which predates this regression)

## Requested Fix
Remove the hardcoded `32768` default in `RetryChatModel.__init__` and properly resolve the inner model's context size from the provider configuration.

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start with src/qwenpaw/providers/retry_chat_model.py and trace how context_size and model are obtained from the wrapped provider. Compare this with src/qwenpaw/config/config.py and the hard_limit read in src/qwenpaw/agents/context/scroll/manager.py. Done means configured values such as max_input_length: 131072 reach compaction and the error identifies the model instead of using the fallback values.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
ai, backend
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.