Bound and instrument large plugin tool-result payloads in chat turns
I maintainer di solito rispondono entro 1 giorno
@paullizer ci sta già lavorando.
Dal 20/8/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Summary
Plugin (action) tool results are retained and passed around a chat turn without a shared size bound, and we have no diagnostics that would let us distinguish a memory problem from a Cosmos write problem from a model context-window problem.
A customer running Simple Chat locally reports the app crashing when an action returning large result sets is combined with an Azure AI Search workspace. We cannot currently diagnose that from logs, because nothing reports how much data a turn actually accumulated or where it went.
Add size instrumentation first so the failure mode can be identified, then apply a shared bounding policy for plugin results. This is not specific to any one action type.
User Value
- Admins and developers can see why a chat turn failed instead of getting an opaque crash or a generic error.
- Actions that legitimately return large datasets degrade predictably instead of taking down the process.
- Removes the need for each action type to invent its own limits, which is the current situation and is inconsistent.
Proposed Behavior
Phase 1 — Diagnostics
Instrument with debug_print / log_event:
- Serialized byte size of each plugin invocation result, attributed to plugin and function name.
- Cumulative tool-result bytes accumulated for the current turn.
- Total retained size of
PluginInvocationLogger.invocationsafter each append, not just the item count. - Assembled prompt payload size immediately before the model call, broken down by conversation history, document/search citations, and tool results.
- Explicit classification of Azure OpenAI
400responses, distinguishingcontext_length_exceededfrom other bad requests.
Phase 2 — Shared bounding policy
- A single configurable cap for plugin tool-result payloads, applied consistently rather than per action type.
- Bound what is retained in memory, not only what is logged or persisted.
- Surface truncation explicitly to the model and to the user, so a truncated result is never silently presented as complete.
Acceptance Criteria
- Per-invocation and per-turn tool-result sizes appear in debug logging with plugin and function attribution.
- Retained invocation-history size is observable and bounded by bytes, not only by item count.
- Prompt assembly logs a size breakdown before the model call.
- Azure OpenAI context-length errors are logged distinctly and surfaced as an actionable message rather than a generic failure.
- A shared plugin result cap exists and applies regardless of action type.
- Truncation is explicitly marked in the result handed to the model.
- Functional test covering an oversized plugin result, asserting bounding and truncation signaling.
Notes
Current state
PluginInvocationLogger.__init__(semantic_kernel_plugins/plugin_invocation_logger.pyL343) retainsmax_history = 1000invocations holding the full, untruncatedresultobject. Truncation viasanitize_plugin_invocation_value(max_string_length=500) andMAX_SAFE_INVOCATION_STRING_LENGTH = 20000is applied to logging and persistence output only, never to retained state.get_invocations_for_conversation(..., limit=1000)is called from at least eight sites inroute_backend_chats.pyduring a single turn, including L3000, L3024, L18511, L18874, and L19418.- Per-action-type limits exist and are inconsistent:
MCP_MAX_TOOL_RESULT_TEXT_LENGTH = 120000infunctions_mcp_operations.py; the Yamcs action defaults tomax_rows = 500andbyte_limit = 250000; several other action types have no cap at all. - Search contributes independently:
SEARCH_DEFAULT_TOP_N = 12andSEARCH_MAX_TOP_N = 500infunctions_search.py. conversation_history_limit(default 10) replays prior messages, which may already carry large tool payloads from earlier turns.
Pattern to reuse
build_evidence_envelope in functions_mixed_source_orchestration.py L1121 already implements bounded JSON lists and UTF-8-safe truncation with an explicit bounds_applied flag. That is the shape the shared policy should follow rather than inventing a new one.
Leading hypothesis
Process memory exhaustion from retained full-size invocation results, not model context overflow. A context overflow would return a clean Azure OpenAI 400, which the customer is not seeing. Retaining up to 1000 full results and re-reading them from many call sites per turn is the mechanism that scales badly. This is masked in App Service by gunicorn worker recycling and available RAM, and manifests as a hard process exit on a developer workstation running other workloads alongside it.
Secondary candidates to confirm or eliminate with the same instrumentation, rather than assume:
- Cosmos DB 2 MB item size limit on message save when citations carry large tool results. The
log_tool_executionpath inagent_logging_chat_completion.pyL39 truncatesfunction_resultto 500 characters, but citations built from the invocation logger take a different path that needs verifying. - Repeated deep copy and serialization of large results across the sanitize → citation → persist chain.
- The Werkzeug development server with
threaded=Truebeing less resilient under memory pressure than gunicorn.
Related gap
route_backend_chats.py L14291 is the only place that pattern-matches BadRequestError, and it does not distinguish context-length failures. If the model is reporting an oversized prompt, we are currently discarding that signal.
Staging
Phase 1 is independently valuable and should ship first. Phase 2 should not be scoped until Phase 1 data identifies the actual failure mode.
- Lingua principale
- Python
- Stelle
- 155
- Fork
- 116
- Merge medio
- 5h 5m
- PR unite (30g)
- 204
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/simplechat
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
microsoft/simplechat#1491 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
microsoft/simplechat#1370 ·
I maintainer di solito rispondono entro 1 giorno
-
Harden deployer private networking and add optional AMPLS for Commercial and GovernmentForse già presa @paullizer l’ha presa oggi. Apertabug enhancement P1 security_improvement
microsoft/simplechat#1765 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
V2 bootstrap takes ~5s: optimize /api/v2/bootstrap backend and first paintForse già presa @paullizer l’ha presa 6 giorni fa. Apertaenhancement P1 python
microsoft/simplechat#1725 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Serve the new UI at the main URLs, move the legacy UI under /legacy, and let admins control interface accessForse già presa @paullizer l’ha presa 6 giorni fa. ApertaCreated By Copilot enhancement P1
microsoft/simplechat#1723 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/simplechat
Issue simili
-
Workflow.schedule stops when a cron deadline passes before sleepForse già presa @HuaTNA l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] HiveDialect shares its colspecs dict with SQLAlchemy's DefaultDialect (python/pyhive)Forse già presa @rusackas l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
apache/kyuubi#7786 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
I maintainer di solito rispondono entro 1 giorno
-
[20.0] hr_work_entry: Duration column of Export Time Entries is truncated to whole hoursForse già presa @odooaktiv l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
fix formatting of the sample database page of the docsForse già presa @Aaqibhafeezkhan l’ha presa oggi. Apertadocumentation good first issue help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
chaoss/CollectOSS#544 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno