fix(aws-startup-advisor): probe embedding ids via InvokeModel under a runtime_messages plan and align the Mantle Messages snippet with the public page

Review iteration 1 findings (review.json CHANGES_REQUESTED):

- major: preflight_bedrock.main() routed every non-Mantle id to the Messages
  probe when --runtime-api messages was set, so a runtime_messages plan whose
  $TARGET_MODELS also carried an embedding id (B1 collects every
  bedrock_models[].aws_model_id) failed preflight spuriously. Embedding ids now
  fall through to probe_model (InvokeModel) before the messages branch. New
  test_main_messages_plan_probes_embedding_ids_via_invoke_model covers a
  Claude profile + amazon.titan-embed-text-v2:0 list.
- minor: agents/llm2bedrock-code-rewriter.md Mantle express lane Anthropic row
  and snippet used base_url .../anthropic/v1 with auth_token=; the SDK appends
  /v1/messages, so that resolved to /anthropic/v1/v1/messages. Now
  base_url .../anthropic with api_key=, matching the public Messages API page
  (inference-messages-api.html, read 2026-11-07) and the shared guide.
- minor: evaluator §6b and §9.5b heredocs are now executed by
  test_runtime_messages_connectivity_snippet_uses_the_messages_client and
  test_runtime_messages_vision_snippet_sends_a_base64_source_block.
- minor: preflight_bedrock.py module docstring now scopes in. to GPT-5.6
  Terra and Luna, with GPT-5.6 Sol and GPT-6 Astra us./global. only.
- minor: the mantle_selector enum paraphrase is removed from
  skills/shared/ai/ai-openai-to-bedrock.md and gcp design-ai.md; both now
  point at references/vendored/ai/bedrock-endpoint-policy.md. The
  llm-to-bedrock SKILL.md section stays as the one permitted restatement.
  Vendored copies re-synced (tools/sync-vendored.py).

Verification (plugins/aws-startup-advisor, 2026-11-07):
- sync-vendored --check: PASS 64 (2 re-synced)
- llm-to-bedrock scripts: 435 passed (431 + 4 new)
- agent-advisor scripts: 570 passed; no non-vendored agent-advisor change
- mise run ci: exit 0 (lint:md 0 errors, lint:skill-refs 1520/0 missing,
  lint:vendored-parity PASS 64, lint:artifacts 99/0, test 1408 passed +
  222 subtests, test:telemetry 311, test:heroku-source-review OK)
- root python3 tools/validate.py: All validations passed; mise run validate: exit 0
- residual Mantle-default grep over plugins/aws-startup-advisor *.md/*.json: nothing
- gitleaks protect --staged: no leaks found
This commit is contained in:
Logan Kleier
2026-11-07 18:56:36 -08:00
parent 4361d51fd6
commit 6ca403b66f
8 changed files with 88 additions and 17 deletions
@@ -241,7 +241,7 @@ The source SDK stays. Per client, change only three things:
| ---------------------------------------- | ------------------------------------------------------ |
| Proprietary OpenAI GPT (`openai.gpt-5*` / `openai.gpt-6*`) | `https://bedrock-mantle.<REGION>.api.aws/openai/v1` |
| Other OpenAI-compatible targets | `https://bedrock-mantle.<REGION>.api.aws/v1` |
| Anthropic SDK | `https://bedrock-mantle.<REGION>.api.aws/anthropic/v1` |
| Anthropic SDK | `https://bedrock-mantle.<REGION>.api.aws/anthropic` (the SDK appends `/v1/messages`) |
If your context has a `Mantle base path` line, use it verbatim — it is authoritative over this table.
- **Credential** → a Bedrock bearer token, NOT the original provider key. For a short CLI or one-shot script, read it from the `AWS_BEARER_TOKEN_BEDROCK` env var; for any long-running process use the auto-refreshing `provide_token` client shown below (the env-var form expires within 12 hours). Do not leave the old `api_key=os.environ["OPENAI_API_KEY"]` line in place.
@@ -305,9 +305,12 @@ client = anthropic.Anthropic()
import os
import anthropic
client = anthropic.Anthropic(
base_url="https://bedrock-mantle.us-east-1.api.aws/anthropic/v1",
auth_token=os.environ["AWS_BEARER_TOKEN_BEDROCK"],
base_url="https://bedrock-mantle.us-east-1.api.aws/anthropic",
api_key=os.environ["AWS_BEARER_TOKEN_BEDROCK"],
)
# Same base_url/api_key form as the public Messages API page
# (https://docs.aws.amazon.com/bedrock/latest/userguide/inference-messages-api.html, read 2026-11-07);
# the SDK appends /v1/messages and the anthropic-version header itself.
```
Preserve compatible SDK request/response shapes. A model version change still requires §9 target checks, including typed response parsing for Opus 5.5. Apply the Chat Completions → Responses reshape only when that API change was selected. Preserve the exact validated runtime profile ID or ARN. After applying the changes above, skip the Converse-specific guidance in the rest of §8; the §9 behavior-delta application still applies normally.
@@ -93,9 +93,8 @@ Amazon Bedrock recommends `bedrock-runtime` for new applications
(`references/vendored/ai/bedrock-endpoint-policy.md`). Record `migration_path: "mantle_openai_chat"`
(Chat Completions source on a model whose card lists it on mantle — GPT-6, GPT-5.5, GPT-5.4) or
`"mantle_openai_responses"` **only** when the row also records a `bedrock_models[].mantle_selector`
from that policy file (background inference, server-side tools / Web Search, Projects / Workspaces,
a Mantle-only model or API, or strict in-Region processing where runtime offers only CRIS). API
continuity alone never selects Mantle.
from `references/vendored/ai/bedrock-endpoint-policy.md` (the selector enum is defined there and
only there). API continuity alone never selects Mantle.
Report the assessment honestly: `strong_migrate` here means "low-risk, well-supported move", not "cheaper".
@@ -411,8 +411,7 @@ ID becomes the CRIS profile and IAM is `bedrock:InvokeModel*`. A `mantle_*` path
(`"mantle_openai_chat"` for a Chat source, `"mantle_openai_responses"` for a Responses source — e.g.
Astra on Standard Mantle in `us-east-1` or `us-west-2`) is recorded **only** when the row also
records `bedrock_models[].mantle_selector` from `references/vendored/ai/bedrock-endpoint-policy.md`
(background inference, server-side tools / Web Search, Projects / Workspaces, a Mantle-only model or
API, or strict in-Region processing where runtime offers only CRIS); then keep the OpenAI SDK, use
(the selector enum is defined there and only there); then keep the OpenAI SDK, use
`/openai/v1` on Mantle, Bedrock credentials and Mantle IAM. API continuity alone never selects
Mantle. Do not reshape Astra Chat solely because it is proprietary GPT. Record `model_change: false` only when
the exact source model is retained; a Pro-to-Astra upgrade is a model change requiring eval.
@@ -93,9 +93,8 @@ Amazon Bedrock recommends `bedrock-runtime` for new applications
(`references/vendored/ai/bedrock-endpoint-policy.md`). Record `migration_path: "mantle_openai_chat"`
(Chat Completions source on a model whose card lists it on mantle — GPT-6, GPT-5.5, GPT-5.4) or
`"mantle_openai_responses"` **only** when the row also records a `bedrock_models[].mantle_selector`
from that policy file (background inference, server-side tools / Web Search, Projects / Workspaces,
a Mantle-only model or API, or strict in-Region processing where runtime offers only CRIS). API
continuity alone never selects Mantle.
from `references/vendored/ai/bedrock-endpoint-policy.md` (the selector enum is defined there and
only there). API continuity alone never selects Mantle.
Report the assessment honestly: `strong_migrate` here means "low-risk, well-supported move", not "cheaper".
@@ -12,8 +12,9 @@ runtime OpenAI-compatible APIs, or `messages` for the runtime Anthropic Messages
API. Embedding models (which don't speak Converse) go via InvokeModel with their
family's request body. Bare OpenAI proprietary GPT ids are the bedrock-mantle
form and are probed via the OpenAI Responses API on that endpoint; GPT-6 Astra
(us./global.) and GPT-5.6 (us./in./global.) CRIS ids are bedrock-runtime targets
and take the selected runtime API probe.
(us./global.), GPT-5.6 Terra and Luna (us./in./global.) and GPT-5.6 Sol
(us./global.) CRIS ids are bedrock-runtime targets and take the selected
runtime API probe.
Probe output budgets and cost depend on the selected API.
"""
import argparse, json, sys
@@ -411,7 +412,9 @@ def main(argv=None) -> int:
"Do not assume GPT-5.6's cached-input quota exemption or RPM rules "
"apply; Astra's documented 10x output burndown is runtime-specific.")
else:
if args.runtime_api == "messages":
# Embedding ids in a chat plan's $TARGET_MODELS never speak the selected
# chat API; they are always probed via InvokeModel (probe_model).
if args.runtime_api == "messages" and not is_embedding_model(model_id):
verdict = probe_runtime_messages_model(model_id, args.region)
elif (args.runtime_api != "converse" and ".openai.gpt-" in model_id
and "gpt-oss" not in model_id):
@@ -1,4 +1,5 @@
"""Execute the actual evaluator snippets and validate Astra handoff contracts."""
import base64
import json
import re
import sys
@@ -63,6 +64,47 @@ def test_astra_connectivity_uses_selected_openai_api(surface, mid, monkeypatch):
(responses if surface == "chat_completions" else chat).assert_not_called()
@pytest.mark.parametrize("mid", ["global.anthropic.claude-sonnet-5", "us.anthropic.claude-opus-5.5"])
def test_runtime_messages_connectivity_snippet_uses_the_messages_client(mid, monkeypatch, capsys):
# §6b is the Messages counterpart of §6a; execute the committed heredoc so a typo
# in the evaluator prose cannot ship unnoticed.
responses, chat, runtime, messages = clients(monkeypatch)
code = snippet("# 6b. Runtime Anthropic Messages connectivity", "# 7. Load golden")
code = code.replace("<TARGET_MODEL_ID>", mid).replace("<scriptsDir>", str(Path(__file__).parent))
monkeypatch.setenv("AWS_REGION", "us-west-2")
exec(compile(code, str(EVALUATOR), "exec"), {}) # nosec B102 - committed test fixture
assert messages.call_count == 1
assert messages.call_args.kwargs["model"] == mid
assert messages.call_args.kwargs["messages"] == [{"role": "user", "content": "ping"}]
assert "OK: answer" in capsys.readouterr().out
responses.assert_not_called()
chat.assert_not_called()
runtime.assert_not_called()
def test_runtime_messages_vision_snippet_sends_a_base64_source_block(monkeypatch, capsys):
import io
import urllib.request
responses, chat, runtime, messages = clients(monkeypatch)
monkeypatch.setattr(urllib.request, "urlopen", lambda *a, **k: io.BytesIO(b"test-image"))
code = snippet("# 9.5b Runtime Anthropic Messages vision", "# 10. Run golden")
code = code.replace("<TARGET_MODEL_ID>", "global.anthropic.claude-sonnet-5")
code = code.replace("<scriptsDir>", str(Path(__file__).parent))
monkeypatch.setenv("AWS_REGION", "us-west-2")
exec(compile(code, str(EVALUATOR), "exec"), {}) # nosec B102 - committed smoke snippet
call = messages.call_args.kwargs
assert call["model"] == "global.anthropic.claude-sonnet-5"
image_block, text_block = call["messages"][0]["content"]
assert image_block["type"] == "image"
assert image_block["source"] == {"type": "base64", "media_type": "image/jpeg",
"data": base64.b64encode(b"test-image").decode()}
assert text_block == {"type": "text", "text": "Describe this image briefly."}
assert "VISION_OK: answer" in capsys.readouterr().out
responses.assert_not_called()
chat.assert_not_called()
runtime.assert_not_called()
@pytest.mark.parametrize("mid,surface,endpoint", [
("openai.gpt-6-astra", "responses", "responses"),
("openai.gpt-6-astra", "chat_completions", "chat"),
@@ -370,3 +370,30 @@ def test_main_routes_messages_api_to_the_messages_probe(monkeypatch, capsys):
assert rc == 0
assert calls == [("messages", "global.anthropic.claude-sonnet-5", "us-west-2")]
assert json.loads(capsys.readouterr().out)["ok"] is True
def test_main_messages_plan_probes_embedding_ids_via_invoke_model(monkeypatch, capsys):
# Regression: B1 collects every bedrock_models[].aws_model_id into $TARGET_MODELS and
# B4 passes the whole list with one --runtime-api. A runtime_messages plan with a
# Claude profile plus an embedding id POSTed the embedding id to /anthropic/v1/messages
# and failed preflight spuriously; embeddings must still go via InvokeModel.
import boto3
import json
calls = []
monkeypatch.setattr(boto3, "client", lambda *a, **k: object())
monkeypatch.setattr(p, "fetch_bedrock_quotas", lambda region: [])
monkeypatch.setattr(p, "probe_runtime_messages_model",
lambda mid, region: calls.append(("messages", mid)) or
{"ok": True, "reason": "ok", "detail": "ok"})
monkeypatch.setattr(p, "probe_model",
lambda client, mid: calls.append(("invoke_model", mid)) or
{"ok": True, "reason": "ok", "detail": "ok"})
monkeypatch.setattr(p, "probe_runtime_openai_model",
lambda *a: (_ for _ in ()).throw(AssertionError("OpenAI probe must not run")))
rc = p.main(["--region", "us-west-2",
"--models", "global.anthropic.claude-sonnet-5,amazon.titan-embed-text-v2:0",
"--runtime-api", "messages"])
assert rc == 0
assert calls == [("messages", "global.anthropic.claude-sonnet-5"),
("invoke_model", "amazon.titan-embed-text-v2:0")]
assert json.loads(capsys.readouterr().out)["ok"] is True
@@ -93,9 +93,8 @@ Amazon Bedrock recommends `bedrock-runtime` for new applications
(`references/vendored/ai/bedrock-endpoint-policy.md`). Record `migration_path: "mantle_openai_chat"`
(Chat Completions source on a model whose card lists it on mantle — GPT-6, GPT-5.5, GPT-5.4) or
`"mantle_openai_responses"` **only** when the row also records a `bedrock_models[].mantle_selector`
from that policy file (background inference, server-side tools / Web Search, Projects / Workspaces,
a Mantle-only model or API, or strict in-Region processing where runtime offers only CRIS). API
continuity alone never selects Mantle.
from `references/vendored/ai/bedrock-endpoint-policy.md` (the selector enum is defined there and
only there). API continuity alone never selects Mantle.
Report the assessment honestly: `strong_migrate` here means "low-risk, well-supported move", not "cheaper".