noteflowai/ai-chat-for-amazon-bedrock · 1.74.0 · 2026-10-19

wp ai-chat-bedrock usage reports failed requests by cause

In its default per-day mode, wp ai-chat-bedrock usage [--days=N] now prints a 'Failed requests' line. It counts chat requests that still failed after any fallback model, grouped by cause, over the same window as the latency line: min(30, N) days, labelled '1 day' or 'N days'. Example: 'Failed requests (7 days): 3 after any fallback model: throttled 2, access denied 1.' Causes appear in the plugin's fixed FAILURE_CATEGORIES order. The printed labels are throttled, access denied, rejected, unavailable, network and other, and the validation category prints as 'rejected' (for example 'rejected 2'). Categories with zero failures are left out. The counts come from AI_Chat_Bedrock_Usage::failure_totals(), which reads the stored data the dashboard uses. A private failure_line() helper next to first_token_line() formats them. Stored counters that are non-numeric, negative or in an unknown category are ignored. The line comes after the day table, Total and Prompt cache lines and directly before the Time to first text line, which stays last. When the window has no valid failures, the line is left out, the same way the Prompt cache line is, and the command still succeeds. --by-model output does not change. The plugin version is 1.74.0. Controller-run checks on commit 457bedd: the acceptance test tests/test_feature_2d89f9484181.php failed on the base commit with 8 assertion failures and passed on the candidate. bin/prerelease.sh passed, with 72 PHP suites run (including the unchanged tests/cli.php, tests/usage.php and tests/test_feature_fe5052185c45.php), phpcs clean and versions consistent. tests/tooling.php passed, and bin/build-package.py built the 1.74.0 package (136 files). I did not run any of these checks myself.

Use it

Prerequisites: WordPress with this plugin (1.74.0) active, and WP-CLI. The command needs no input file because it reads the counters the plugin already stores.

1) Report on a real site (read-only):
  wp ai-chat-bedrock usage --days=7

2) Optional synthetic demo. Use a disposable test site only, because this writes fake failure counters into the real usage statistics:
  wp eval 'AI_Chat_Bedrock_Usage::record_failure("throttled"); AI_Chat_Bedrock_Usage::record_failure("throttled"); AI_Chat_Bedrock_Usage::record_failure("access_denied");'
  wp ai-chat-bedrock usage --days=7

Expected output (synthetic):
  (day table)
  Total: ...
  Failed requests (7 days): 3 after any fallback model: throttled 2, access denied 1.
  Time to first text (streamed, 7 days): ...

When the Prompt cache line is present, it comes before the Failed requests line. wp ai-chat-bedrock usage --days=60 counts and labels 30 days, the retention limit. When nothing has failed in the window, no Failed requests line is printed. Scripts should find the line by its 'Failed requests (' prefix, not by its position.

To run the behavioral test from a repository checkout (synthetic seeded counters, no AWS calls):
  php -d zend.assertions=1 -d assert.exception=1 tests/test_feature_2d89f9484181.php

Scope

Deviation from the plan: the plan specified 'Failed requests (N days): none recorded.' for an empty window. The existing regression test tests/test_feature_fe5052185c45.php requires exactly three per-day output lines when no failure data is stored, and existing tests must stay unchanged. The line is therefore left out when the window has no valid failures. That covers a new install, a reset, days stored before failure counting existed, and windows where every stored value is invalid. A missing line means no failures were recorded. It does not signal an error and does not change the exit code. The acceptance test uses labelled synthetic counters and makes no Bedrock calls, so it does not show that real-world failures are classified correctly. The counts are what this plugin recorded after any fallback model, not an AWS-side failure rate. The controller ran prerelease.sh without --wp-cli, so the official Plugin Check, the live WordPress integration check and the translation template comparison did not run, and core-ai-library.php was skipped. The prerelease JavaScript tests that ran are existing regression tests and do not exercise this CLI change. This is a CLI-only feature, so there was no browser or visual review. Out of scope: per-model or per-day failure breakdowns, JSON output, dashboard changes, new failure recording, alerting and exit codes driven by failures. The CLI strings are plain, untranslated English, like the existing usage lines.

Upgrade and rollback

Upgrading to 1.74.0 changes CLI output only. Stored options and the failure-recording path are unchanged, and nothing migrates. The Time to first text (streamed, ...) line is still the last line, and --by-model output is the same. Scripts that count lines or parse by position should match on line prefixes instead, because a Failed requests line now appears whenever the window has recorded failures. To roll back, reinstall 1.73.1. No data is lost, and the stored failure counters still show on the dashboard as before.

Source commit: 3dd28ae5f152ba70a233962edb87ccfb8a76cd81