You are already running inside the megaplan harness for this step. Do the requested planning/review/execution work directly. Do NOT invoke the megaplan CLI, do NOT read or activate the megaplan skill, do NOT start nested megaplan plans, and do NOT recurse into another planning harness. Treat mentions of megaplan in the repository or environment as implementation context only.
You are an independent reviewer. Critique the plan against the actual repository.
Follow-up cleanup pass after the identity-based-routing megaplan. Four narrow, focused fixes to close quality gaps that the identity-routing plan explicitly left as TODO:
WIRE UP THE LLM CLASSIFIER that was scaffolded but never called. The identity-routing megaplan's admin_chat_cog instantiates an AsyncAnthropic client (self._classifier_client) in init at line 65 and logs a warning if ANTHROPIC_API_KEY is missing ('payment reply classification will fail closed'), but the actual classifier function _classify_confirmation is a classmethod that never touches self._classifier_client. The classifier function is keyword-based only. The operator specifically asked for LLM-based classification during scoping of the previous megaplan, and this was injected as a steering note, but the revise worker overrode it and specified keywords instead. This cleanup closes that gap: convert _classify_confirmation from a classmethod to an instance method, call self._classifier_client.messages.create with a narrow structured-output prompt (Anthropic tool_use API to force the schema) to classify the recipient's reply as confirmed/not_received/unclear, fall back to the existing keyword classification if the API key is missing or the call raises. The tests should cover both the LLM path (mocked) and the keyword fallback path. The LLM classifier prompt should be strict: only return confirmed if the recipient clearly indicates they see the test payment in their wallet, 'ok' or 'thanks' alone is NOT confirmed, 'wait let me check' is unclear not confirmed. The classifier must be stateless — no memory between calls, no channel history context beyond the single recipient message and the bot's prompt message. Use Claude Haiku (claude-haiku-4-5) or the current configured self._classifier_model. Structured output enforced via tool_use so the LLM cannot escape the schema.
FIX THE SILENT-ON-AMBIGUOUS UX HOLE in _handle_test_receipt_ambiguous. Today this handler silently increments an internal counter without telling the recipient anything. The recipient gets zero feedback on their first ambiguous reply, which is genuinely confusing — they don't know if their message was received, if the bot misunderstood, what format is expected, whether to try again. Fix: on the first ambiguous reply (count < 2), post a friendly clarification message to the recipient in the thread: 'I didn't quite understand — please reply with confirmed or yes once you see the test SOL in your wallet, or not received if you don't see it.' Keep the existing 2-strike escalation to negative. If the LLM classifier (from fix 1) returns unclear with a reply field, use that reply instead of a hardcoded template.
Assistant
{"checks":[],"flags":[{"id":"FLAG-001","concern":"Admin-chat cleanup: The plan's repo-wide zero-hit grep for _can_user_message_bot is not achievable within the stated scope, because src/features/admin/admin_cog.py still defines and uses its own live _can_user_message_bot for DM routing.","category":"correctness","severity_hint":"likely-significant","evidence":"The plan's Steps 7 and 12 say to grep src/ and tests/ and expect zero hits for _can_user_message_bot, but src/features/admin/admin_cog.py:211 defines async def _can_user_message_bot(...) and src/features/admin/admin_cog.py:363 still calls it. Satisfying the plan literally would require touching an out-of-scope file or weakening the verification target to the admin_chat package."}],"verified_flag_ids":[],"disputed_flag_ids":[]}
FIX THE NEGATIVE-PATH RECIPIENT MESSAGING GAP in _handle_test_receipt_negative. Today this handler posts a message addressed to the admin ('@admin manual review needed for intent X...') which the recipient can see but is not directed at them. The recipient has no idea what to do next. Fix: post a parallel recipient-facing message alongside the admin tag: 'Hey @recipient — I've flagged this for admin review. Please wait for @admin to follow up.' Do not remove the admin tag or the DM — keep both. Add the recipient-directed text as a separate send, so the admin still gets the alert they expect.
DELETE THE DEAD CODE that the identity-routing megaplan explicitly retained 'for staged cleanup in a follow-up'. The admin_chat_cog.py line 1052-1053 comment says: 'Identity-routing note: MEMBER_SYSTEM_PROMPT, _can_user_message_bot, and _is_directed_at_bot are intentionally retained as dead code for staged cleanup.' This cleanup actually removes them. Specifically delete: _can_user_message_bot method and any imports/calls, _is_directed_at_bot method if it exists, MEMBER_SYSTEM_PROMPT constant and any conditional tool palette logic that branches on admin vs approved-member. Verify nothing still references them via grep. Update any tests that exercised approved-member paths — those tests should be deleted or rewritten to test the identity router's fall-through behavior (non-admin, non-pending-recipient user should cause the cog to do nothing).
SCOPE CONSTRAINTS (CRITICAL — do not exceed):
Only touch files in src/features/admin_chat/ and their tests
Do NOT touch src/features/grants/solana_client.py, src/features/payments/solana_provider.py, payment_service.py, payment_worker_cog.py, payment_ui_cog.py, producer_flows.py, db_handler.py, or any other payment subsystem files. The identity-routing megaplan's cross-subsystem work is DONE and must stay that way.
Do NOT modify the state machine transitions themselves (awaiting_wallet, awaiting_test_receipt_confirmation, awaiting_admin_approval). Only modify the HANDLERS for those states to add recipient-facing messaging.
Do NOT add new intent states, new DB columns, new tools, or new flows. Pure cleanup.
Do NOT change the orphan sweep, the AdminApprovalView, the query tools, the batch tool, upsert_wallet_for_user, or any other feature from the identity-routing megaplan.
Preserve all hardening invariants: fail-closed on classifier failure, admin DM gate for real payments, auto-skip for verified wallets, test-first for unverified wallets, etc.
SUCCESS CRITERIA:
self._classifier_client is actually used by _classify_confirmation (no longer dead code)
LLM classifier path works end-to-end with structured output via tool_use
Keyword classifier path is preserved as the fallback for when ANTHROPIC_API_KEY is unset or the API call raises
First ambiguous reply from recipient receives a clear in-thread message asking them to clarify
Negative-path escalation posts both an admin-facing message (existing) AND a recipient-facing message (new)
MEMBER_SYSTEM_PROMPT, _can_user_message_bot, _is_directed_at_bot are fully deleted; grep finds no references
All existing tests still pass (189 baseline)
New tests cover: LLM classifier happy path (confirmed/not_received/unclear), keyword fallback when API key missing, keyword fallback when API call raises, recipient clarification message on first ambiguous, recipient-facing message on negative path, dead code removal verification
DELIBERATELY OUT OF SCOPE:
Changing the architecture (identity router stays, state machine stays)
Multi-admin support
Reply-to-bot detection (currently any in-thread message triggers the state machine; this is not being changed)
Grants cog
Any cross-subsystem refactoring
New tools or features
Manual smoke tests (those are a separate checklist outside any megaplan)
Four narrow cleanups inside src/features/admin_chat/ that close quality gaps the identity-routing megaplan explicitly deferred:
Wire the dead self._classifier_client into _classify_confirmation with a tool_use-enforced structured-output call; keep the existing keyword classifier as the fail-closed fallback.
Give the recipient a first-reply clarification message inside _handle_test_receipt_ambiguous instead of silently incrementing the counter.
Add a parallel recipient-directed message alongside the existing admin-tagged escalation in _handle_test_receipt_negative.
Delete the dead code (MEMBER_SYSTEM_PROMPT, _can_user_message_bot, _is_directed_at_bot, the member tool palette split, and the is_admin branching it fed) that the identity-routing plan deliberately retained.
Scope fence (critical): touch only src/features/admin_chat/admin_chat_cog.py, src/features/admin_chat/agent.py, src/features/admin_chat/tools.py, and their tests under tests/. Do not touch the payment subsystem, the state-machine transitions, the orphan sweep, AdminApprovalView, upsert_wallet_for_user, _ADMIN_IDENTITY_INJECTED_TOOLS, or the requester_id plumbing inside tools.py. Preserve fail-closed semantics (classifier exceptions → keyword fallback, not auto-positive).
tests/test_admin_payments.py:573-709 and 1419-1537 — existing tests for classifier, router, ambiguous, and negative handlers.
tests/test_social_route_tools.py:293-320 and 857-873 — tests that reference get_tools_for_role / ADMIN_ONLY_TOOLS.
tests/conftest.py (monkeypatches ANTHROPIC_API_KEY), and tests/test_admin_payments.py:573-576 where admin_chat_env autouse fixture deletes the API key (keeps keyword path as default in tests).
Main Phase
Step 1: Audit current classifier + handlers (src/features/admin_chat/admin_chat_cog.py, src/features/admin_chat/agent.py)
Scope: Small
Confirm_classify_confirmation is invoked only from _handle_pending_recipient_message (admin_chat_cog.py:1022) and from tests/test_admin_payments.py:600,606-607.
Confirmself._classifier_client is never read anywhere today (grep: only construction at line 65 and warning at line 67).
Confirm_can_user_message_bot, _is_directed_at_bot, MEMBER_SYSTEM_PROMPT, MEMBER_TOOLS, ADMIN_ONLY_TOOLS, get_tools_for_role, MEMBER_MAX_CONVERSATION_LENGTH, and the is_admin parameter on AdminChatAgent.chat() have no live readers outside the admin_chat package and the two test files already identified.
Step 2: Split the keyword classifier out so tests still have a sync entry point (src/features/admin_chat/admin_chat_cog.py)
Scope: Small
Rename the existing @classmethod def _classify_confirmation (lines 96-143) to _classify_confirmation_keyword with the same body, same classmethod decorator, and same return type Literal['positive','negative','ambiguous'].
Update the parametrized keyword tests at tests/test_admin_payments.py:597-607 to call cog._classify_confirmation_keyword(content) so the deterministic keyword path stays directly testable without async/mocking.
Step 3: Add the LLM-backed classifier instance method (src/features/admin_chat/admin_chat_cog.py)
Scope: Medium
Add a module-level constant next to the existing keyword tuples:
python
_CLASSIFIER_TOOL = {
"name": "classify_payment_reply",
"description": "Classify a recipient's reply to the bot's test-payment confirmation prompt.",
"input_schema": {
"type": "object",
"properties": {
"classification": {
"type": "string",
"enum": ["confirmed", "not_received", "unclear"],
},
"reply": {
"type": "string",
"description": "Optional clarification message for the recipient when classification is 'unclear'. Leave empty otherwise.",
},
},
"required": ["classification"],
},
}
_CLASSIFIER_SYSTEM_PROMPT = (
"You classify a Discord user's reply to a payout bot that just said: "
"'I sent you a small test payment — please reply confirmed or yes once "
"you see the test SOL in your wallet, or not received if you do not see it.' "
"Rules: return 'confirmed' ONLY if the user clearly indicates they can see "
"the test SOL in their wallet. 'ok' or 'thanks' alone is NOT confirmed. "
"'wait let me check', 'give me a sec', 'maybe' are 'unclear', NOT confirmed. "
"Return 'not_received' only if the user clearly reports the payment is missing. "
"Everything else is 'unclear'. When unclear, include a short plain-language "
"'reply' asking the user to respond with 'confirmed' or 'not received'. "
"You have no memory of prior turns — classify only the single reply you are given."
)
Add an async instance method on AdminChatCog:
python
async def _classify_confirmation(
self, content: str
) -> tuple[Literal['positive', 'negative', 'ambiguous'], Optional[str]]:
if self._classifier_client is None:
return self._classify_confirmation_keyword(content), None
try:
response = await self._classifier_client.messages.create(
model=self._classifier_model,
max_tokens=256,
system=_CLASSIFIER_SYSTEM_PROMPT,
tools=[_CLASSIFIER_TOOL],
tool_choice={"type": "tool", "name": "classify_payment_reply"},
messages=[{"role": "user", "content": content or ""}],
)
except Exception:
logger.warning(
"[AdminChat] LLM classifier failed, falling back to keywords",
exc_info=True,
)
return self._classify_confirmation_keyword(content), None
tool_input: Optional[Dict] = None
for block in getattr(response, "content", []) or []:
if getattr(block, "type", None) == "tool_use" and getattr(block, "name", None) == "classify_payment_reply":
tool_input = getattr(block, "input", None) or {}
break
if not isinstance(tool_input, dict):
return self._classify_confirmation_keyword(content), None
classification_raw = str(tool_input.get("classification") or "").strip().lower()
reply = tool_input.get("reply")
reply_text = reply.strip() if isinstance(reply, str) and reply.strip() else None
mapped = {
"confirmed": "positive",
"not_received": "negative",
"unclear": "ambiguous",
}.get(classification_raw)
if mapped is None:
return self._classify_confirmation_keyword(content), None
return mapped, reply_text # type: ignore[return-value]
Keepself._classifier_model at the existing string ("claude-opus-4-6") — the brief permits Haiku but explicitly allows "current configured self._classifier_model", and swapping the model is out of scope for this cleanup.
ImportOptional and Tuple/Dict as needed from typing (already imported on line 9, extend the import).
Step 4: Wire the new classifier into the state-machine dispatch (src/features/admin_chat/admin_chat_cog.py)
Scope: Small
Update_handle_pending_recipient_message near line 1022 to:
After the successful increment and before the >= 2 escalation branch, if int(updated_intent.get('ambiguous_reply_count') or 0) < 2, post a recipient-facing clarification in-thread:
python
default_text = (
f"<@{intent['recipient_user_id']}> I didn't quite understand — please "
"reply with **confirmed** or **yes** once you see the test SOL in your "
"wallet, or **not received** if you don't see it."
)
text = default_text
if clarification_reply:
text = f"<@{intent['recipient_user_id']}> {clarification_reply}"
await message.channel.send(text)
Leave the existing >= 2 → _handle_test_receipt_negative delegation untouched (recursive call already forwards the real intent; do not forward clarification_reply into the negative path — negative is a separate flow).
Step 6: Fix the negative-path recipient messaging gap (src/features/admin_chat/admin_chat_cog.py)
Scope: Small
In_handle_test_receipt_negative, after building the existing detail string and beforeawait message.channel.send(detail) (line 514), send an additional recipient-directed message:
python
recipient_notice = (
f"Hey <@{intent.get('recipient_user_id')}> — I've flagged this for "
f"admin review. Please wait for {self._admin_mention} to follow up."
)
await message.channel.send(recipient_notice)
Then keep the existing await message.channel.send(detail) and the existing _notify_intent_admin DM exactly as-is. Two channel sends, one admin DM, in that order.
Step 7: Delete the dead code in the cog (src/features/admin_chat/admin_chat_cog.py)
Scope: Small
Delete_is_directed_at_bot (lines 870-897) and _can_user_message_bot (lines 903-923) in full.
Delete the _message_access_cache instance field initialization (line 59). The _guild_context_cache and _ACCESS_CACHE_TTL_SECONDS stay — they are used by _resolve_context_guild_id.
Delete the retention comment at lines 1052-1053 inside _handle_admin_message.
Grepsrc/ and tests/ for _can_user_message_bot, _is_directed_at_bot, _message_access_cache, and confirm only the files in this plan touch them.
Step 8: Delete the dead code in the agent (src/features/admin_chat/agent.py)
Scope: Medium
DeleteMEMBER_SYSTEM_PROMPT (lines 166-207) and MEMBER_MAX_CONVERSATION_LENGTH (line 210).
Simplify_trim_conversation (line 246): drop the is_admin parameter and always use ADMIN_MAX_CONVERSATION_LENGTH.
SimplifyAdminChatAgent.chat() (line 279): drop the is_admin: bool = True parameter and every if is_admin branch at lines 349, 377-382, 390-391, 453, 472, 522. Always use SYSTEM_PROMPT (with the existing server-config override when present), always append _POM_ADDENDUM, always pass available_tools = TOOLS (from tools.py), keep _ADMIN_IDENTITY_INJECTED_TOOLS injection unchanged (the if is_admin and ... collapses to if ...), and always call execute_tool with requester_id=None (leave the keyword there; the requester_id plumbing inside tools.py is explicitly out of scope for deletion).
Update the import in agent.py:15 from from .tools import get_tools_for_role, execute_tool to from .tools import TOOLS, execute_tool.
Update the call site in admin_chat_cog.py:1144-1151 to drop is_admin=True from self.agent.chat(...). Keep requester_id=None (plumbing stays).
Step 9: Delete the dead code in tools (src/features/admin_chat/tools.py)
Scope: Small
DeleteMEMBER_TOOLS (line 1033), ADMIN_ONLY_TOOLS (line 1045), the two assert sanity checks (lines 1082-1083), and get_tools_for_role (lines 1086-1089).
KeepALL_TOOL_NAMES = {tool["name"] for tool in TOOLS} as a single post-TOOLS derivation if any other code references it (grep first; remove if not).
Do not touch _ADMIN_IDENTITY_INJECTED_TOOLS, requester_id branches in execute_tool (lines 3737-3767), or any query/batch/upsert tool implementations.
Step 10: Update tests that reference the deleted symbols (tests/test_social_route_tools.py, tests/test_admin_payments.py)
Scope: Medium
tests/test_social_route_tools.py:293-320 — rewrite test_route_tools_are_admin_only into test_expected_admin_tools_are_registered: build registered = {tool["name"] for tool in admin_tools.TOOLS} and assert the expected set is a subset. Drop the member_tool_names assertions — the member/admin split no longer exists.
tests/test_social_route_tools.py:857-873 — rewrite test_admin_tool_registration_and_identity_injection_sets to assert the expected tools exist in {t["name"] for t in admin_tools.TOOLS} and keep the _ADMIN_IDENTITY_INJECTED_TOOLS and _CHANNEL_POSTING_TOOLS assertions untouched.
tests/test_admin_payments.py:697-709 — delete test_approved_member_no_longer_routed_to_agent entirely. It's redundant with test_identity_router_falls_through_for_non_admin_without_intent at line 654 and its _can_user_message_bot AsyncMock patch references a deleted method.
tests/test_admin_payments.py:654-668 — in test_identity_router_falls_through_for_non_admin_without_intent, remove the cog._can_user_message_bot = AsyncMock(...) line and the corresponding .assert_not_awaited() assertion. Keep the core fall-through assertions (_handle_admin_message.assert_not_awaited, _handle_pending_recipient_message.assert_not_awaited).
tests/test_admin_payments.py:1496-1537 — update test_handle_test_receipt_ambiguous_escalates_on_second_reply: the first-reply branch now sends a clarification message, so change assert channel.sent_messages == [] to assert exactly one message was sent containing "<@42>" and "confirmed" after the first call. The second-call assertions (status manual_review, "multiple ambiguous receipt replies") are unchanged.
tests/test_admin_payments.py:1420-1454 — update test_handle_test_receipt_negative_moves_to_manual_review: assert two channel messages — the first containing "<@42>" and "admin review", the second containing the existing sig-123 / wallet detail. Admin DM assertion stays.
Greptests/ for MEMBER_SYSTEM_PROMPT, MEMBER_MAX_CONVERSATION_LENGTH, get_tools_for_role, MEMBER_TOOLS, ADMIN_ONLY_TOOLS, _can_user_message_bot, _is_directed_at_bot to confirm no other stale references.
Step 11: Add new tests for the classifier wiring, ambiguous clarification, negative recipient messaging, and dead-code removal (tests/test_admin_payments.py)
monkeypatch.setenv("ANTHROPIC_API_KEY", "test-key") to override the autouse fixture.
Construct the cog, then replace cog._classifier_client = AsyncMock() and set cog._classifier_client.messages.create = AsyncMock(return_value=SimpleNamespace(content=[SimpleNamespace(type="tool_use", name="classify_payment_reply", input={"classification": "confirmed"})])).
result = await cog._classify_confirmation("ok i see it"); assert result == ("positive", None) (and ("negative", None) / ("ambiguous", "please reply with confirmed or not received") for the others).
Verify cog._classifier_client.messages.create.await_args.kwargs["tool_choice"] == {"type": "tool", "name": "classify_payment_reply"} and that the single user message is the raw reply content.
Addtest_classify_confirmation_falls_back_to_keywords_when_api_key_missing — rely on the autouse fixture (no API key), assert await cog._classify_confirmation("confirmed, got it") == ("positive", None) without any network mock.
Seed an intent with ambiguous_reply_count=0, call _handle_test_receipt_ambiguous(message, intent), assert channel.sent_messages[-1].content contains "<@42>" and "confirmed" and "not received", and that db.intents[...]["ambiguous_reply_count"] == 1.
Same fixture, call with clarification_reply="Please say yes once you see 0.01 SOL", assert the sent message contains that exact string (minus leading mention).
Extend the existing setup, assert len(channel.sent_messages) == 2, the first contains "<@42>" and "admin review" and the configured admin mention, the second contains sig-123 and VALID_SOL_ADDRESS (the existing admin-tag line), and the admin DM still arrives.
Addtest_dead_code_is_removed:
import src.features.admin_chat.agent as admin_agent and import src.features.admin_chat.tools as admin_tools.
assert not hasattr(admin_agent, "MEMBER_SYSTEM_PROMPT").
assert not hasattr(admin_agent, "MEMBER_MAX_CONVERSATION_LENGTH").
assert not hasattr(admin_tools, "MEMBER_TOOLS").
assert not hasattr(admin_tools, "ADMIN_ONLY_TOOLS").
assert not hasattr(admin_tools, "get_tools_for_role").
assert not hasattr(AdminChatCog, "_can_user_message_bot").
assert not hasattr(AdminChatCog, "_is_directed_at_bot").
Step 12: Validate the change
Scope: Small
Run the targeted admin chat test file first: pytest tests/test_admin_payments.py -x -q. This catches the cog, classifier, and handler changes before the broader suite.
Runpytest tests/test_social_route_tools.py -x -q to confirm the rewritten tool-palette tests still pass.
Run the full suite: pytest -x -q. The baseline is 189 tests; expect baseline +7 (approx) new tests and −1 deleted (test_approved_member_no_longer_routed_to_agent).
Grep once more for any dangling references to the deleted symbols (MEMBER_SYSTEM_PROMPT, MEMBER_MAX_CONVERSATION_LENGTH, MEMBER_TOOLS, ADMIN_ONLY_TOOLS, get_tools_for_role, _can_user_message_bot, _is_directed_at_bot) across src/ and tests/ and confirm zero hits.
Execution Order
Steps 1-2: understand the current shape and carve out the keyword helper so existing tests have a stable target.
Steps 3-4: add the async LLM classifier and wire it into the state-machine dispatch.
Steps 5-6: patch the two recipient-facing UX gaps.
Steps 7-9: delete dead code across the cog, agent, and tools, in that order (cog first so is_admin=True kwarg removal at the call site lines up with the agent signature change).
Step 10: update existing tests that exercise the deleted symbols or the changed handler behavior.
Step 11: add the new tests covering every new behavior and the dead-code deletion.
Step 12: run targeted then full suite.
Validation Order
pytest tests/test_admin_payments.py -x -q (fastest signal on cog changes).
pytest tests/test_social_route_tools.py -x -q (catches the tools.py/agent.py palette cleanup).
pytest -x -q (full baseline sweep).
Final grep for deleted symbols.
code
Plan metadata:
{
"version": 1,
"timestamp": "2026-04-11T04:14:46Z",
"hash": "sha256:812a24ac4176a784d56cc55cbe188018e19c3d778218e6c6ef15b900a6e533d7",
"questions": [
"The brief allows either claude-haiku-4-5 or the currently configured self._classifier_model (today claude-opus-4-6). I'm planning to keep the existing model string since swapping models is extra surface area; confirm that's acceptable, or tell me to flip it to Haiku in Step 3.",
"The brief says the classifier must be stateless and see only the single recipient reply and the bot's prompt. I'm baking the bot's prompt into a static _CLASSIFIER_SYSTEM_PROMPT constant rather than fetching the exact prior bot message from the channel. OK, or do you want the real prior bot message pulled from the thread?",
"The test at tests/test_admin_payments.py:697 test_approved_member_no_longer_routed_to_agent is fully redundant with the existing fall-through test at line 654 once _can_user_message_bot is gone. I'm planning to delete it outright. Confirm that's preferred over rewriting it.",
"tools.py currently exposes ALL_TOOL_NAMES as a module-level constant derived from the MEMBER/ADMIN union. If nothing outside the assertions references it, I'll delete it too; if anything elsewhere (e.g. other cogs) imports it, I'll keep a direct ALL_TOOL_NAMES = {t['name'] for t in TOOLS} form. A grep during Step 9 will decide. Flag if you want it kept unconditionally."
],
"success_criteria": [
{
"criterion": "admin_chat_cog.py contains an async instance method _classify_confirmation that calls self._classifier_client.messages.create with tools=[...] and tool_choice={\"type\": \"tool\", \"name\": \"classify_payment_reply\"} when self._classifier_client is not None.",
"priority": "must"
},
{
"criterion": "When ANTHROPIC_API_KEY is unset (so self._classifier_client is None), _classify_confirmation returns the result of the keyword classifier without making any network calls.",
"priority": "must"
},
{
"criterion": "When self._classifier_client.messages.create raises an exception, _classify_confirmation catches it, logs a warning, and returns the keyword classifier result \u2014 fail-closed to keyword, not to auto-positive.",
"priority": "must"
},
{
"criterion": "The LLM confirmed / not_received / unclear outputs map to positive / negative / ambiguous respectively, and an unclear reply with a non-empty reply field propagates that string to _handle_test_receipt_ambiguous via the new clarification_reply kwarg.",
"priority": "must"
},
{
"criterion": "_handle_test_receipt_ambiguous posts a recipient-directed clarification message (default template OR the LLM-provided reply) to the channel on the first ambiguous reply (post-increment count < 2), and the existing 2-strike escalation to _handle_test_receipt_negative still fires on the second ambiguous reply.",
"priority": "must"
},
{
"criterion": "_handle_test_receipt_negative sends two channel messages: one recipient-directed (Hey <@recipient> \u2014 I've flagged this for admin review. Please wait for <@admin> to follow up.) and the existing admin-tagged detail message. The admin DM via _notify_intent_admin is still sent.",
"priority": "must"
},
{
"criterion": "MEMBER_SYSTEM_PROMPT, MEMBER_MAX_CONVERSATION_LENGTH, MEMBER_TOOLS, ADMIN_ONLY_TOOLS, get_tools_for_role, _can_user_message_bot, and _is_directed_at_bot are removed from the source tree; a repo-wide grep returns zero hits in src/ and tests/.",
"priority": "must"
},
{
"criterion": "AdminChatAgent.chat() no longer accepts an is_admin parameter; agent.py uses SYSTEM_PROMPT and TOOLS unconditionally, and the cog call site at admin_chat_cog.py:1144-1151 is updated accordingly.",
"priority": "must"
},
{
"criterion": "tests/test_admin_payments.py includes new tests covering: LLM happy path (confirmed/not_received/unclear+reply), keyword fallback when API key missing, keyword fallback when API raises, first-ambiguous clarification (default + LLM-provided reply), negative-path recipient-facing message, and dead-code removal.",
"priority": "must"
},
{
"criterion": "tests/test_social_route_tools.py is updated so that test_route_tools_are_admin_only and test_admin_tool_registration_and_identity_injection_sets no longer reference get_tools_for_role or ADMIN_ONLY_TOOLS, and both pass against the post-cleanup TOOLS list.",
"priority": "must"
},
{
"criterion": "pytest -x -q passes end-to-end (all previously passing tests still pass; new tests pass; the single intentionally deleted test_approved_member_no_longer_routed_to_agent is removed rather than skipped).",
"priority": "must"
},
{
"criterion": "No files outside src/features/admin_chat/ and tests/ are modified. Specifically, no changes to src/features/grants/solana_client.py, src/features/payments/*, src/common/db_handler.py, producer_flows.py, the state-machine transitions themselves, the orphan sweep, AdminApprovalView, or the identity-routing query/batch tools.",
"priority": "must"
},
{
"criterion": "Fail-closed posture is preserved: classifier exceptions, missing API key, malformed tool_use blocks, and unknown classification values all route to the keyword classifier (not to an auto-confirm path).",
"priority": "must"
},
{
"criterion": "The new _classify_confirmation is stateless \u2014 no channel history, no cross-call memory; the only inputs passed to the Anthropic API are the static _CLASSIFIER_SYSTEM_PROMPT and a single user message containing the raw recipient reply.",
"priority": "must"
},
{
"criterion": "Classifier prompt is strict about 'ok'/'thanks' alone not counting as confirmed and 'wait let me check' counting as unclear, per the brief.",
"priority": "should"
},
{
"criterion": "admin_chat_cog.py stays roughly the same size after cleanup \u2014 net line count delta is small (new classifier method + small handler edits \u2212 ~60 lines of dead methods), not a sprawling rewrite.",
"priority": "should"
},
{
"criterion": "Recipient-directed messages use the existing <@id> mention convention consistent with the rest of the cog and avoid introducing a new mention-formatting helper.",
"priority": "should"
},
{
"criterion": "Manual smoke test: admin triggers a real test payment, recipient replies 'ok thanks', bot classifies as unclear and posts the LLM-provided clarification; recipient then replies 'confirmed', bot moves to admin approval. Out-of-scope for automated validation.",
"priority": "info"
},
{
"criterion": "Manual smoke test: classifier exception path (e.g. temporarily revoke API key in staging) still routes an ambiguous-looking reply through keyword fallback and escalates correctly. Out-of-scope for automated validation.",
"priority": "info"
}
],
"assumptions": [
"The requester_id plumbing inside tools.py (lines 3737-3767) and the _ADMIN_IDENTITY_INJECTED_TOOLS injection in agent.py are part of the identity-routing megaplan and stay untouched, even though requester_id will always be None post-cleanup.",
"The classifier's reply field is used only by the ambiguous path \u2014 the negative path uses its own hardcoded recipient notice regardless of classifier output, consistent with the brief's description of fix #3.",
"Keyword classifier tests at tests/test_admin_payments.py:587-607 can be re-pointed at the renamed _classify_confirmation_keyword helper without losing coverage, because the keyword logic is byte-for-byte identical.",
"_classifier_model stays at the current string; the brief explicitly permits using the existing value.",
"The autouse admin_chat_env fixture that deletes ANTHROPIC_API_KEY is the intended default \u2014 new LLM-path tests will override it with monkeypatch.setenv and stub cog._classifier_client directly, so no real Anthropic client is ever constructed during tests.",
"The baseline of 189 tests is approximate; the success criterion is 'no existing test regresses', not 'exactly 189 pass after the change', since this plan adds ~7 new tests and deletes one redundant test.",
"_handle_test_receipt_ambiguous receiving the LLM's clarification reply as a kwarg is a strict addition \u2014 the recursive call from inside itself on the >= 2 branch is replaced by a direct call to _handle_test_receipt_negative, and clarification text is never forwarded into the negative path.",
"Messages sent via the newly added message.channel.send calls do not need Discord's mention-ping suppression beyond what the existing surrounding code already does; the existing handler freely uses raw <@id> mentions, so the new messages follow the same convention."
],
"structure_warnings": []
}
code
Plan structure warnings from validator:
[]
Existing flags:
[]
Known accepted debt grouped by subsystem:
{
"admin-chat-classification": [
{
"id": "DEBT-006",
"concern": "anthropic client may not be initialized when interceptor fires before _ensure_agent.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
}
],
"admin-payments-intent-state": [
{
"id": "DEBT-004",
"concern": "button confirmation path does not directly update admin_payment_intents \u2014 intent sync happens indirectly via handle_payment_result on terminal state.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-005",
"concern": "no direct bridge from paymentconfirmview to admin_payment_intents.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-008",
"concern": "awaiting_admin_init stale cleanup only runs at cog_load, not periodically, so stranded verified-batch intents could remain active until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-009",
"concern": "scheduling glue for periodic _reconcile_admin_chat_orphans invocation is not in the plan",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-010",
"concern": "awaiting_admin_init in the active set has broader effects on active-intent callers across the repo until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
}
],
"db-handler-social-publications": [
{
"id": "DEBT-001",
"concern": "mixing fluent client, raw sql, and rpc access patterns in one subsystem increases maintenance surface.",
"occurrence_count": 1,
"plan_ids": [
"implement-a-unified-social-20260409-1710"
]
}
],
"db-handler-supabase-infrastructure": [
{
"id": "DEBT-002",
"concern": "supabase rpc is untested in this codebase and may require dashboard configuration.",
"occurrence_count": 1,
"plan_ids": [
"implement-a-unified-social-20260409-1710"
]
}
],
"payment-service-confirmation": [
{
"id": "DEBT-007",
"concern": "success criterion bundles null-recipient dm wiring with cap-breach/collision dm wiring; step 1 only does log+return-none for null-recipient.",
"occurrence_count": 1,
"plan_ids": [
"harden-the-solana-payment-20260410-2147"
]
}
],
"social-channel-routes": [
{
"id": "DEBT-003",
"concern": "route management tooling is absent, leaving the routing system inert until manual db inserts.",
"occurrence_count": 1,
"plan_ids": [
"implement-a-unified-social-20260409-1710"
]
}
]
}
code
Escalated debt subsystems:
[
{
"subsystem": "admin-payments-intent-state",
"total_occurrences": 5,
"plan_count": 2,
"entries": [
{
"id": "DEBT-004",
"concern": "button confirmation path does not directly update admin_payment_intents \u2014 intent sync happens indirectly via handle_payment_result on terminal state.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-005",
"concern": "no direct bridge from paymentconfirmview to admin_payment_intents.",
"occurrence_count": 1,
"plan_ids": [
"admin-triggered-payments-let-20260410-1448"
]
},
{
"id": "DEBT-008",
"concern": "awaiting_admin_init stale cleanup only runs at cog_load, not periodically, so stranded verified-batch intents could remain active until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-009",
"concern": "scheduling glue for periodic _reconcile_admin_chat_orphans invocation is not in the plan",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
},
{
"id": "DEBT-010",
"concern": "awaiting_admin_init in the active set has broader effects on active-intent callers across the repo until restart",
"occurrence_count": 1,
"plan_ids": [
"identity-based-routing-for-20260411-0256"
]
}
]
}
]
code
Debt guidance:
- These are known accepted limitations. Do not re-flag them unless the current plan makes them worse, broadens them, or fails to contain them.
- Prefix every new concern with a subsystem tag followed by a colon, for example `Timeout recovery: retry backoff remains brittle`.
- When a concern is recurring debt that still needs to be flagged, prefix it with `Recurring debt:` after the subsystem tag, for example `Timeout recovery: Recurring debt: retry backoff remains brittle`.
Your output template is at: /Users/user_c042661f/Documents/banodoco-workspace/brain-of-bndc/.megaplan/plans/follow-up-cleanup-pass-after-20260411-0608/critique_output.json
Review the plan with a broad scope. Consider whether the approach is correct, whether it covers
all the places it needs to, whether it would break callers or violate codebase conventions,
and whether its verification strategy is adequate.
Place any concrete concerns in the flags array in the template file using the standard format
(id, concern, category, severity_hint, evidence). Leave checks as an empty array.
Workflow: read the file → investigate → read file again → add findings → write file back.
code
Additional guidelines:
- Robustness level: light. Be pragmatic. Only flag issues that would cause real failures. Ignore style, minor edge cases, and issues the executor will naturally resolve.
- Over-engineering: prefer the simplest approach that fully solves the problem.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids`: list flag IDs from prior iterations that the revised plan actually resolves (e.g., if the plan was revised to fix FLAG-001, and you confirm the fix is correct, include "FLAG-001"). Only include flags you've verified — don't guess.
- Verify that the plan follows the expected structure when validator warnings or the outline suggest drift.
- Additional flags may use these categories: correctness, security, completeness, performance, maintainability, other.
- Focus on concrete issues, not structural formatting.