Skip to content

Fix second-pass review suggestions for release 0.8.16 server code - #572

Merged
neuromechanist merged 10 commits into
developfrom
fix/release-0.8.16-second-pass-server
Oct 1, 2026
Merged

neuromechanist merged 10 commits into
developfrom
fix/release-0.8.16-second-pass-server

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

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

  • 1. Whitespace-only text after a code run was stored. A reply that ran code counts as answered with no text, so "\n\n" passed the emptiness check and was stored. langchain-anthropic replays it unchanged as content: "\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.
  • 2. A refused key told everyone to start a new conversation. The message now depends on the failure kind and key source. A caller's own (BYOK) key: "The provider refused your API key. Check that it is valid and can use this model.", logged at WARNING without a traceback. A platform or community key: a server-problem message, still ERROR with the traceback. /ask no longer offers a conversation it does not have.
  • 3. The non-streamed 502 returned no ids. The body now carries error_id and request_id next to detail (which stays the text to show; the CLI reads it there). Declared in the OpenAPI schema for /ask and /chat. The endpoints return the 502 as a JSONResponse from a small UnansweredReply exception, because FastAPI's HTTPException handler can only put detail in the body.
  • 4. /config hint in the fallback case. default_model_provider is None when a Bedrock default falls back to Claude, not the platform's OpenRouter host hint.
  • 5. Community keys. _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_provider and 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.
  • 6. Stream error rows had no reason. Provider and unexpected failures now write failure.detail (exception class and provider code or status, none of the provider's message) to error_message, so agent_errors counts them and the error event's request_id points at a row that says why.
  • 7. Startup check guarded. log_unserved_bedrock_defaults is wrapped like init_metrics_db; a failure is logged with its traceback and startup continues.
  • 8. _select_model and the resume probe. _select_model uses _configured_default. The /chat/resume probe now logs nothing: log_fallback became log and 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

  • 400 rows of the stream handlers (input validation, session limits) still have no error_message: they are the reader's error, not the agent's, so agent_errors should not count them. A test pins it.
  • /config still reports the platform's default_model_provider next to a bare Claude model for a community with no default_model of 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.
  • New tests use the scripted-model boundary and real-client fixtures (Bedrock wire, Anthropic wire, local OpenRouter) in test_cut_off_replies.py, test_stream_failures.py, test_bedrock_deployments.py and test_bedrock_routing.py. The one injected fault is the startup check made to raise, since nothing real makes it raise today.

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.
@neuromechanist
neuromechanist merged commit d835be2 into develop Oct 1, 2026
7 checks passed
@neuromechanist
neuromechanist deleted the fix/release-0.8.16-second-pass-server branch October 1, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant