wip: first-chunk debug logging — paused waiting for platform-agent logs
This commit is contained in:
parent
2a23b30f83
commit
c34db0e6c0
5 changed files with 61 additions and 111 deletions
|
|
@ -1,62 +1,53 @@
|
|||
---
|
||||
context: phase
|
||||
phase: 04-matrix-mvp-shared-agent-context-and-context-management-comma
|
||||
task: 3
|
||||
total_tasks: 3
|
||||
status: paused
|
||||
last_updated: 2026-04-23T11:46:45.938Z
|
||||
task: 4
|
||||
total_tasks: 6
|
||||
status: in_progress
|
||||
last_updated: 2026-04-24T12:16:09.301Z
|
||||
---
|
||||
|
||||
<current_state>
|
||||
Phase 04 кодово стабилизирована вокруг direct upstream `AgentApi` per request. Коммит `7d58dd1` уже запушен в `origin/feat/matrix-direct-agent-prototype`. Старый checkpoint в этом файле устарел: после обратной связи от платформы мы убрали extra wrapper из prod path, перестали переиспользовать один websocket между запросами и после этого missing-first-chunk симптом перестал воспроизводиться локально.
|
||||
Debugging first-chunk truncation bug in Matrix bot. Logging added to both sdk/real.py and external/platform-agent/src/agent/service.py. Waiting for user to run docker compose up --build and share platform-agent logs with stream_event lines.
|
||||
</current_state>
|
||||
|
||||
<completed_work>
|
||||
|
||||
- Весь ранее собранный Matrix MVP контекст остаётся валидным: numeric `platform_chat_id`, staged attachments, shared workspace, context commands и Docker packaging уже на месте.
|
||||
- Продовый runtime path переведён на direct upstream client через `sdk/upstream_agent_api.py`; локальный `sdk/agent_api_wrapper.py` удалён из runtime path.
|
||||
- `sdk/real.py` теперь на каждый `send_message` и `stream_message` создаёт новый `AgentApi`, делает `connect()`, читает stream и сразу `close()`.
|
||||
- `AGENT_BASE_URL` зафиксирован как основной runtime contract; `AGENT_WS_URL` оставлен только как backward-compat fallback в env wiring.
|
||||
- Добавлена регрессия на reuse-sensitive missing-first-chunk сценарий и обновлены runtime/integration tests; `uv run pytest tests -q` прошёл (`196 passed`), `ruff` на затронутых файлах clean.
|
||||
- Кодовый фикс закоммичен и запушен: `7d58dd1` (`fix: use direct agent api per request`).
|
||||
- В сессионных выводах зафиксирован новый архитектурный принцип для следующих surfaces: не строить свой transport layer, держать только thin integration/session boundary над upstream transport.
|
||||
- docker-compose.yml: added `./config:/app/config:ro` volume mount so MATRIX_AGENT_REGISTRY_PATH works
|
||||
- config/matrix-agents.example.yaml: updated labels to Platform/Media
|
||||
- sdk/real.py: added structlog debug logging in _stream_agent_events (logs each chunk index + text[:40])
|
||||
- external/platform-agent/src/agent/service.py: added logging of langgraph_node, content_type, content[:60] for every on_chat_model_stream event
|
||||
|
||||
Bot is running and user confirmed it starts correctly with MATRIX_PLATFORM_BACKEND=real.
|
||||
</completed_work>
|
||||
|
||||
<remaining_work>
|
||||
|
||||
- Перед следующим кодом выбрать направление:
|
||||
- если продолжаем Matrix, прогнать live smoke в реальном окружении на text/tool/file flow и проверить отсутствие regressions на direct per-request path;
|
||||
- если переходим к Telegram/Max-подобной работе, открыть новую phase/spec под prod surface architecture.
|
||||
- Привести `.planning/STATE.md` и roadmap в полностью каноничное состояние отдельным planning/cleanup шагом, если хотим закрепить этот checkpoint не только через handoff.
|
||||
- Не смешивать дальнейшую surface/runtime работу с отдельным локальным diff в `core/handlers/message.py`, пока это не станет явной задачей.
|
||||
- Task 4: Get platform-agent debug logs (docker compose up --build, reproduce truncation, share stream_event lines)
|
||||
- Task 5: Analyze: check content_type (str vs list), check langgraph_node (which graph node produces the first chunk)
|
||||
- Task 6: Fix service.py based on findings
|
||||
</remaining_work>
|
||||
|
||||
<decisions_made>
|
||||
|
||||
- Matrix prod path должен использовать прямой upstream `AgentApi`, а не surface-owned wrapper с кастомной stream semantics.
|
||||
- Fresh connection per request принят как дефолтный lifecycle для этой surface, потому что именно reuse websocket оказался чувствительной точкой для missing-first-chunk симптома.
|
||||
- `AGENT_BASE_URL` это честный runtime contract; ws URL normalization допустим только как backward-compat env fallback.
|
||||
- Для следующих surfaces надо думать терминами `integration boundary` и `runtime contract`, а не терминами "написать свой transport layer".
|
||||
- Bug confirmed to be in platform-agent, NOT in surfaces bot: our sdk/real.py logs show chunk index=0 already has truncated text (e.g. ' Д Е Ё...' instead of 'А Б В Г Д...')
|
||||
- deepagents framework uses SubAgentMiddleware: main dispatcher agent + general-purpose subagent
|
||||
- service.py processes ALL on_chat_model_stream events from astream_events v2 with no node filtering
|
||||
- Two leading hypotheses: (A) chunk.content is a list for some events (multimodal), causing silent skip/error; (B) events from wrong graph node are being captured/not captured
|
||||
</decisions_made>
|
||||
|
||||
<blockers>
|
||||
- Подтверждённого локального Matrix blocker после `7d58dd1` больше нет; дальше это вопрос product direction и live validation, а не active transport-firefight.
|
||||
- В worktree остаётся посторонний локальный diff в `core/handlers/message.py`; не смешивать его с будущими surface/runtime изменениями без отдельной задачи.
|
||||
- Need user to run docker compose up --build and share platform-agent logs with DEBUG output
|
||||
</blockers>
|
||||
|
||||
<context>
|
||||
Важная ментальная модель теперь такая:
|
||||
The deepagents architecture: create_deep_agent creates a main orchestrator with SubAgentMiddleware wrapping a general-purpose subagent. When astream_events v2 runs, it may emit on_chat_model_stream from both the main agent's LLM call AND the subagent's LLM call. service.py captures ALL of them. The first chunk of the actual response might be from the subagent (not forwarded to client properly), while the main agent's response starts mid-sentence because it "sees" the subagent's output in its tool result context.
|
||||
|
||||
- upstream transport authoritative; `surfaces` владеет только lifecycle, serialization, attachment forwarding, error mapping и reconciliation.
|
||||
- Старый narrative "ждём platform triage перед любыми transport changes" больше не актуален; transport change уже сделан и дал положительный эффект.
|
||||
- Предыдущий handoff и текущий `STATE.md` были написаны до этого решения, поэтому их надо читать как исторический контекст, а не как последнюю истину.
|
||||
- Проверка на false completion ничего критичного не показала: grep задел только фразу "compatibility placeholder" в `04-01-SUMMARY.md`, а не реальный незаполненный summary.
|
||||
- Текущие локальные non-handoff diff: `.planning/STATE.md` и `core/handlers/message.py`.
|
||||
Two key things to look for in logs:
|
||||
1. content_type=list → fix is `chunk.content[0].get("text", "")` or similar
|
||||
2. langgraph_node varies between chunks → fix is to filter to the correct node (e.g. only "agent" node)
|
||||
</context>
|
||||
|
||||
<next_action>
|
||||
Start with:
|
||||
|
||||
1. Открыть этот обновлённый handoff, а не опираться на старый checkpoint про platform triage.
|
||||
2. Выбрать трек: Matrix live smoke или новая prod-surface phase.
|
||||
3. Если снова полезем в runtime, не возвращать custom transport wrapper и persistent shared websocket без очень сильной причины и регрессионных тестов.
|
||||
Start with: docker compose up --build. Then send a message with image context (e.g. send an image first, then ask 'Напомни алфавит'). Share platform-agent-1 logs — specifically the stream_event lines showing ns= and content_type= values.
|
||||
</next_action>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue