Skip to content

fix #335: stop logging expected AI prompt responses as errors - #336

Open
hdimer wants to merge 2 commits into
nacos-group:masterfrom
hdimer:fix/335-ai-grpc-expected-response-logging
Open

hdimer wants to merge 2 commits into
nacos-group:masterfrom
hdimer:fix/335-ai-grpc-expected-response-logging

Conversation

@hdimer

@hdimer hdimer commented Aug 29, 2026

Copy link
Copy Markdown

What type of PR is this?

  • Bug fix
  • New feature
  • Enhancement
  • Refactoring
  • Documentation
  • CI/CD
  • Other

What does this PR do?

AIGRPCClientProxy.request_ai_server logged every NacosException at ERROR
level, so a plain 304 / prompt data is up to date cache-validation response
produced an ERROR line on every prompt poll, even though
PromptCacheHolder._update_prompt_loop already treats NOT_MODIFIED as the
expected outcome and ignores it.

The HTTP AI proxy already has an idiom for this: _req_api and _req_api_bytes
in ai_http_client_proxy.py re-raise NOT_MODIFIED and NOT_FOUND without
logging. This applies the same two lines to the gRPC proxy so both transports
behave the same way. Every other error code still logs at ERROR exactly as
before.

One consequence worth confirming: subscribe_prompt swallows NOT_FOUND
without logging, so subscribing to a prompt that does not exist is now silent
over gRPC. That is already the behaviour on the HTTP transport, so this brings
the two into line, but say the word if you would rather I limit the change to
NOT_MODIFIED only.

Which issue(s) does this PR fix?

Fixes #335

How has this been tested?

New test/test_ai_grpc_client_proxy.py covers three cases: a 304 and a 404
response emit no ERROR record and still raise, and a 500 response still logs one
ERROR. The two 304/404 tests fail on master and pass with this change. The 500
test passes either way and is there to rule out the lazier fix of demoting the
whole logger.error call.

Ran locally: ruff check --select F --ignore F401 --exclude "*/grpcauto/*" v2/,
the import v2.nacos smoke check, and the offline tests under test/ (45 tests,
all passing). The tests that need a live Nacos server were not run.

I used an AI assistant while working on this. The reasoning, the tests and the
final code are mine and I have reviewed every line.

Checklist

  • Unit tests added/updated
  • Documentation updated (if needed)
  • No breaking changes (or described above)

Used AI assistance on this; I reviewed and tested the change myself.

The gRPC AI proxy logged every NacosException at ERROR level, so a normal
304 (prompt data is up to date) cache-validation response produced an
ERROR line on every prompt poll. The HTTP AI proxy already re-raises
NOT_MODIFIED and NOT_FOUND without logging; follow the same idiom here.
Other error codes still log at ERROR as before.
@CLAassistant

CLAassistant commented Aug 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hdimer
hdimer marked this pull request as ready for review August 29, 2026 15:48
@KomachiSion

Copy link
Copy Markdown

Reviewed head 0707b5e. The 304 fix is sound. I recommend merging after one logging adjustment and a successful CI rerun:

  • Keep NOT_MODIFIED (304) silent and re-raise the original exception.
  • Log NOT_FOUND (404) at WARN, then re-raise the original exception.
  • Keep the existing handling of other errors unchanged.

I checked the Java SDK implementations in both 3.2.3 and 3.3.0. Their common gRPC request method logs both 304 and 404 at WARN before rethrowing. Java does not currently silence these codes. Keeping 304 silent here is still a reasonable improvement: it is an expected conditional-fetch result, and the Prompt cache preserves the value without notifying listeners.

For 404, the new condition affects the shared AI request path, including MCP, Agent and endpoint operations. It therefore removes diagnostics beyond Prompt polling. In particular, an initial subscription to a missing Prompt catches 404, returns None and continues polling; with this patch, only the INFO “Subscribed prompt” message remains. Keeping a WARN makes a missing or mistyped key diagnosable without treating it as an ERROR. Direct queries still raise the exception, so this is a logging concern, not an exception-swallowing bug.

Please retain the existing cache semantics: an initial 404 may return None and keep polling, and a later 404 should evict the cached Prompt and notify listeners with None. Java has the same missing-resource subscription behavior. Please also add an explicit WARN assertion for 404 and a non-Prompt request case. The existing assertNoLogs(..., level=logging.ERROR) already permits WARN.

Local validation of the current head, before this requested adjustment:

  • 45 offline tests passed, covering the PR tests, Prompt/Skill, AI service, client configuration builder and naming cache tests.
  • Ruff 0.15.5 passed, using the CI F rules and including the new test file; the v2 import smoke check passed.
  • Additional base/head probes verified initial missing subscriptions, appearance, deletion, repeated absence, recreation and unchanged 304 responses. Cache updates, callbacks and exception propagation remained intact.
  • Across four AI request types, 401/403/500 still logged ERROR; null responses, invalid response types and simulated transport exceptions also retained ERROR handling.

These checks used macOS/Python 3.13.2 with mocked network responses. The Java comparison was source/test inspection; no live Nacos server or Java tests were run.

Please rerun CI after updating the PR. The current Actions run is marked failure. Its jobs and check-runs are empty in the queried API results, so I could not establish the failure cause. The successful commit status only covers CLA and should not be treated as a passing CI run.

A 404 goes through the shared AI request path, so silencing it also hid
a missing or mistyped Prompt key, MCP server or agent. Log it at WARN
before re-raising, as the Java SDK does. NOT_MODIFIED stays silent, since
it is the expected answer to every unchanged Prompt poll, and other
errors still log at ERROR.
@hdimer

hdimer commented Nov 27, 2026

Copy link
Copy Markdown
Author

Thanks for the thorough review. Pushed c83d2d3 on top of 0707b5e:

  • 304 stays silent and re-raises; 404 now logs at WARN before re-raising the original exception, as in the Java SDK; other errors are unchanged at ERROR.
  • Tests: 404 now asserts exactly one WARNING record, there is a 404 case for a non-Prompt request (QueryMcpServerRequest), and the 304 test now asserts nothing is logged at all.
  • Cache semantics are unchanged, since the same exception still reaches PromptCacheHolder: an initial 404 returns None and keeps polling, a later 404 evicts and notifies listeners with None.

The 46 offline tests across the files you listed pass, and ruff 0.15.5 with the CI rules is clean. On the CI failure: that run has no jobs at all, so it never started; the push should trigger a fresh run, which may need approval since it comes from a fork.

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.

[Bug] Expected prompt 304 responses are logged as ERROR by the AI gRPC proxy

3 participants