Skip to content

fix(agent): surface blocked AGENTS.md warning to user and remove mythic false positive - #59918

Closed
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/59612-agents-block-notification
Closed

fix(agent): surface blocked AGENTS.md warning to user and remove mythic false positive#59918
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/59612-agents-block-notification

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

Summary

When the threat-scanner blocks a project context file (AGENTS.md, CLAUDE.md, .cursorrules), the user receives no notification — only a logger.warning to the log file. The content is silently replaced with [BLOCKED: ...] in the system prompt, invisible to the user.

Additionally, \bmythic\b in the C2 framework regex causes false positives on legitimate content mentioning "Mythic" (a well-known RPG product, Mythic Game Master Emulator).

Changes

1. User notification for blocked files (agent/prompt_builder.py)

When _scan_context_content() blocks a file, it now calls _record_truncation_warning() so the warning is surfaced to the user via the existing drain_truncation_warnings()_emit_status() pipeline — the same mechanism already used for truncation warnings.

Before: Only logger.warning() → goes to log file, user never sees it.
After: logger.warning() + _record_truncation_warning() → user sees the warning.

2. Remove mythic false positive (tools/threat_patterns.py)

Removed mythic from the known_c2_framework regex. The comment on lines 109-114 already warns against adding common English words — praxis was removed for exactly this reason. "Mythic" is a common English word and the name of a well-known RPG product (Mythic Game Master Emulator).

Files Changed

File Δ Description
agent/prompt_builder.py +5 lines Add _record_truncation_warning() call when blocking context files
tools/threat_patterns.py -1 token Remove mythic from C2 framework regex

Verification

  • _record_truncation_warning() is defined and exported in the same module (prompt_builder.py:1232), no import needed
  • _emit_status() already consumes drain_truncation_warnings() output — the pipeline is fully wired
  • mythic removal matches the existing pattern for praxis removal documented in the comment

Closes #59612

@webtecnica

Copy link
Copy Markdown
Contributor Author

@teknium1 Ready for review. Two fixes in one small PR:

  1. User notification — blocked AGENTS.md warnings now surface to the user via the existing _record_truncation_warning()_emit_status() pipeline (same mechanism as truncation warnings). No more silent blocking.

  2. mythic false positive — removed from C2 regex. Same treatment as praxis (already documented in the comment as the reason for not adding common words). "Mythic" is a common English word and an RPG product name, not a C2-specific tell.

6 lines total, CI should be clean. 🙏

@alex-portugal

Copy link
Copy Markdown

Code Quality Review:
Summary of Code Review

What I did:
Read the PR diff from /tmp/diff.txt and analyzed the two changed files for code style, potential bugs, and adherence to best practices.

Findings:

1. agent/prompt_builder.py

  • Code Style:
    • The new block (lines 9‑13) introduces a msg variable and calls _record_truncation_warning(msg). The code is readable, but there is no blank line between the added block and the existing return statement (line 14). Adding a blank line would improve visual separation and conform to typical Python style (PEP 8 suggests blank lines between logical sections).
    • The logger call uses % formatting correctly; the f‑string for msg is fine.
  • Potential Bugs:
    • No obvious bugs. The variable findings is assumed to be a list of strings (as used elsewhere), and ', '.join(findings) is safe.
    • Ensure _record_truncation_warning accepts a single string argument; the call matches that expectation.
  • Best Practices:
    • The change centralizes the warning message in msg before logging and recording, which avoids duplication and makes future edits easier.
    • The return string still informs the user why the file was blocked, maintaining clarity.

2. tools/threat_patterns.py

  • Code Style:
    • The removal of 'praxis' from the regex alternation is straightforward. The comment explains the rationale well, which is good practice for future maintainers.
    • Indentation remains consistent.
  • Potential Bugs:
    • The regex still compiles correctly; removing a term cannot introduce syntax errors.
    • Ensure that the removal does not unintentionally create a gap that could be exploited (e.g., if “praxis” was part of a larger malicious pattern). The justification provided indicates this was considered and deemed safe.
  • Best Practices:
    • Keeping the comment alongside the change helps reviewers understand why a seemingly benign term was removed, improving maintainability.
    • The pattern continues to use word boundaries (\b) to avoid partial matches, which is appropriate.

Overall:
The changes are small and focused. No critical issues were found. Minor style improvements (adding a blank line in prompt_builder.py) would enhance readability. The removal of 'praxis' from the threat patterns is well‑justified and does not introduce risks. No files were created or modified during this review; only the diff was examined.

Architecture Review:
Based on the provided diff, here's a concise architectural review focusing on design patterns, separation of concerns, scalability, and maintainability:

Design Patterns & Separation of Concerns

  • Threat Detection Separation: The threat pattern detection logic (tools/threat_patterns.py) is appropriately separated from the prompt building logic (agent/prompt_builder.py). This maintains a clear separation between threat scanning and prompt construction.
  • Minor Duplication: In prompt_builder.py, the findings string (', '.join(findings)) is computed twice—once for the warning message and once for the return string. This violates the DRY principle and could be refactored to compute it once.

Scalability

  • Pattern Management: The threat patterns are stored as a hardcoded list of tuples in threat_patterns.py. While acceptable for a small set, this approach doesn't scale well for large pattern sets. Consider externalizing patterns to a config file (YAML/JSON) or using a compiled regex engine for better performance at scale.
  • Performance: If the threat scanning function is called frequently (e.g., for many context files), repeatedly compiling regex patterns on each call could impact performance. Pre-compiling regex patterns at module load time would improve scalability.

Maintainability

  • Code Duplication: The duplicated string formatting in prompt_builder.py is a minor maintainability issue—changes to the message format would need to be made in two places.
  • Pattern Maintenance: Hardcoded regex lists require code changes for updates. Externalizing patterns would allow non-code updates and easier testing.
  • Clarity: The comment explaining the removal of 'mythic' (similar to prior removal of 'praxis') shows good maintenance awareness—removing overly generic terms that cause false positives.

Summary

The changes are modest and maintain acceptable separation of concerns. The primary architectural improvements would be:

  1. Eliminate the duplicated string formatting in prompt_builder.py.
  2. Consider pre-compiling regex patterns in threat_patterns.py for better scalability.
  3. For long-term maintainability, consider externalizing threat patterns to a configuration format.

None of these represent critical architectural flaws, but addressing them would improve long-term maintainability and scalability.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #59652 — same author, same two fixes (route threat-scanner context blocks through the truncation-warning pipeline in agent/prompt_builder.py, and remove bare mythic from the known_c2_framework regex in tools/threat_patterns.py). #59652 is the earlier-open version and additionally ships regression tests (tests/agent/test_prompt_builder.py, tests/tools/test_threat_patterns.py). Related: #59622 (canonical notification-only fix), #59625 (already dup of #59622), and issue #59612.

…ic false positive

Two changes:

1. When _scan_context_content() blocks a file, the warning was only
   logged to file via logger.warning(). Now it also calls
   _record_truncation_warning() so the message is surfaced to the user
   via the existing drain_truncation_warnings() -> _emit_status() pipeline.

2. Remove 'mythic' from the known_c2_framework regex in threat_patterns.py.
   'Mythic' is a common English word and the name of a well-known RPG product
   (Mythic Game Master Emulator). The comment on lines 109-114 already warns
   against adding common English words — 'praxis' was removed for exactly
   this reason.

Closes NousResearch#59612
@webtecnica

Copy link
Copy Markdown
Contributor Author

Closing as duplicate — the sweeper identified this as already covered by another PR. Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AGENTS.md Silent Threat-Scanner Block — No User Notification

3 participants