Repository navigation
Fix second-pass review suggestions for release 0.8.16 server code - #572
Merged
Merged
Conversation
A reply that ran code counts as answered with no text, so a reply whose text was only whitespace passed the emptiness check and was stored. langchain-anthropic replays it unchanged and Anthropic rejects a whitespace-only text block, so every later turn of the session would have failed. The store now tests the stripped text, streamed and not. Tested: new failing-first tests (scripted model on each provider path, and the real Anthropic client's request body); tests/test_api/test_cut_off_replies.py passes.
A provider failure no retry can fix always told the reader to start a new conversation. For a refused credential that cannot help: a caller's own (BYOK) key is now named as theirs to check, and logged at WARNING without a traceback since the operator did nothing wrong; a platform or community key says it is a server problem and keeps the ERROR with its traceback. /ask no longer offers a conversation it does not have. Tested: new tests through the real Anthropic client for each key source on /ask and /chat; test_stream_failures.py and test_unanswered_user_message.py pass.
…streamed The streamed error event carries both; the 502 for a non-streamed empty reply only logged the error id, so a client that retries on a 502 could not tie its attempts to the log or to the metrics row. The body keeps detail as the text to show (the CLI reads it there) and adds error_id and request_id, declared in the OpenAPI schema for /ask and /chat. Tested: new tests on the real /ask and /chat endpoints for each provider path, and on the declared schema; test_cut_off_replies.py and test_turn_outcome.py pass.
When a community's Bedrock default cannot be served, /config showed the platform's default_model_provider (DeepInfra/FP8 by default) next to a Claude model. That hint is an OpenRouter upstream host; a request for a bare Claude id carries none, so report None. Tested: test_bedrock_deployments.py updated to expect None (failed before the change, passes after).
_bedrock_default_outcome, the /config default and model menu, and the startup log read the platform's keys alone, so a community that names its own anthropic_api_key_env_var or openrouter_api_key_env_var (and has it set) could run a different model than they said. The precedence _resolve_provider applies (Anthropic variable first, naming it settles it) now lives in _community_key, and _resolve_provider and a new _funded_provider both use it. No shipped config sets these variables; the startup log now judges each community on its own key and names the variable. Tested: a matrix over every platform key combination and every state of both community variables, comparing /config, the model menu and the startup log to the route a request takes (failed before the change for the community-funded cases, passes after); the authorization, routing and health tests still pass.
The exception handlers wrote their rows with no error_message, so agent_errors counted the 502 rows of empty replies but not provider or unexpected failures, and the error event's request_id pointed at a row with no reason. The row now carries the failure's detail (the exception class and the provider's code or status, none of the provider's message). Input and session-limit errors (400) stay without one: they are the reader's, not the agent's. Tested: new tests through the real Bedrock wire and the scripted model, for /ask and /chat, reading the row back and counting agent_errors (failed before the change); the stream, cut-off and unanswered-message test files pass.
log_unserved_bedrock_defaults is a diagnostic but was called bare in the lifespan, next to the guarded init_metrics_db call. An exception in it would have kept the app from starting. It is now wrapped: the failure is logged with its traceback and startup goes on. Tested: new test runs the real lifespan with the check made to raise and confirms the metrics database is still initialized and the failure is logged (failed before); test_bedrock_deployments.py passes.
_select_model spelled out the same community-else-platform default that _configured_default returns (and that /config and the startup log already use). One place now decides it. _configured_default is typed as returning a str model, which is what both branches give. Tested: no behavior change; authorization, request-route and reasoning-effort routing tests pass.
…me probe /chat/resume routes its request twice: a probe to see whether the result may carry images, then the stream. The probe passed log_fallback=False, which silenced only the Bedrock-default fallback, so the platform's OpenRouter fallback warning and the no-key error were logged twice per request, as were a community key in use or missing and an unservable default. The flag is now 'log' and is threaded through _resolve_provider, _platform_choice and _select_model. Tested: /chat/resume against the real router and a local OpenRouter stand-in logs the fallback warning once (twice before); unit tests that a probe is silent for each situation and a normal route is not; tests/test_api passes.
Both of its branches return a str (the configured default, or the Claude fallback), so the | None only kept CommunityConfigResponse(default_model=...) from type checking. Tested: annotation only; test_bedrock_deployments.py passes; ty reports one diagnostic fewer.
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second-pass review of the server code merged for release 0.8.16 (#565, #566, #568) found no Critical or Important issue and eight suggestions. Each was confirmed first (a test that failed before the change where it is a behavior bug), then fixed.
Changes
"\n\n"passed the emptiness check and was stored.langchain-anthropicreplays it unchanged ascontent: "\n\n"(an empty string it drops), which Anthropic rejects. Both store sites (streamed and not) now test the stripped text. Failing-first tests on each provider path and on the real Anthropic client's request body./askno longer offers a conversation it does not have.error_idandrequest_idnext todetail(which stays the text to show; the CLI reads it there). Declared in the OpenAPI schema for/askand/chat. The endpoints return the 502 as aJSONResponsefrom a smallUnansweredReplyexception, because FastAPI'sHTTPExceptionhandler can only putdetailin the body./confighint in the fallback case.default_model_providerisNonewhen a Bedrock default falls back to Claude, not the platform's OpenRouter host hint._bedrock_default_outcome,_effective_default, the model menu and the startup log now read the key a request would use. The Anthropic-before-OpenRouter precedence moved into_community_key, used by_resolve_providerand a new_funded_provider. The startup log judges each community on its own key and names the variable. A matrix test covers every platform key combination against every state of both community variables, comparing/config, the menu and the log with the route a request takes.failure.detail(exception class and provider code or status, none of the provider's message) toerror_message, soagent_errorscounts them and the error event'srequest_idpoints at a row that says why.log_unserved_bedrock_defaultsis wrapped likeinit_metrics_db; a failure is logged with its traceback and startup continues._select_modeland the resume probe._select_modeluses_configured_default. The/chat/resumeprobe now logs nothing:log_fallbackbecamelogand covers the OpenRouter fallback warning, the no-key error, community key logs and the unservable-default error too, so each is logged once per request (checked end to end against the real router and a local OpenRouter stand-in: two warnings before, one after).Not changed
error_message: they are the reader's error, not the agent's, soagent_errorsshould not count them. A test pins it./configstill reports the platform'sdefault_model_providernext to a bare Claude model for a community with nodefault_modelof its own (the non-fallback path). No shipped community is affected; left for a separate decision.Tested
uv run ruff check . && uv run ruff format .: clean.uv run pytest --ignore=tests/test_integration -m "not integration and not llm and not network" -q -p no:cacheprovider --color=no --no-cov: 4686 passed, 14 skipped.test_cut_off_replies.py,test_stream_failures.py,test_bedrock_deployments.pyandtest_bedrock_routing.py. The one injected fault is the startup check made to raise, since nothing real makes it raise today.