Skip to content

feat(harness): opt-in risk classifier behind DEEPCODE_RISK_CLASSIFIER - #263

Open
raymondginger2018-sudo wants to merge 4 commits into
HKUDS:mainfrom
raymondginger2018-sudo:pr/risk-classifier
Open

raymondginger2018-sudo wants to merge 4 commits into
HKUDS:mainfrom
raymondginger2018-sudo:pr/risk-classifier

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Revives the risk-classifier split requested on #181 (08-17 review). The split PR #189 was opened and then self-closed during a strategy change; it was never declined in review. Rebased onto current main (f183965), conflict-free.

What

  • core/harness/classifier.py (289 lines; stdlib + loguru only): scores high-risk tool calls; enabled with DEEPCODE_RISK_CLASSIFIER=1 (model override via DEEPCODE_RISK_CLASSIFIER_MODEL), off by default.
  • core/agent_runtime/runner.py: the approval path consults the classifier and fails closed (deny + log) on classifier errors, the same pattern as permission_checker.
  • core/events/session.py: the classifier applies to turn builds when enabled.
  • With DEEPCODE_RISK_CLASSIFIER unset there is zero behavior change.

Verification

  • tests/test_harness_classifier.py + tests/test_classifier_wiring.py: 19 passed.
  • runner/session-area suite: 103 passed; the same 5 Windows-local failures occur on clean f183965f59 (differential-verified, unrelated).

Checks

  • Dedup: upstream core/harness/ had no classifier.
  • Dependency closure: stdlib + loguru only.
  • Scope: opt-in, in-repo, no default behavior change.

Prompt-injection defense: DEEPCODE_RISK_CLASSIFIER-gated classifier
that scores incoming user/harness content before it reaches the loop.
All new files; existing behavior untouched when the knob is off.
Add AgentRunSpec.risk_classifier seam: in _check_permission an 'ask' with no
approval_callback (headless) now consults the optional classifier and auto-allows
only a decisive 'low' verdict; medium/high/error/no-verdict keep the existing
deny — it can upgrade an ask, never widen a deny or escalate risk.
build_risk_classifier(provider) returns the env-gated (DEEPCODE_RISK_CLASSIFIER=1)
async resolver; off by default (P0-1 Claude Code Auto-mode lesson).

Co-Authored-By: Claude <noreply@anthropic.com>
When DEEPCODE_RISK_CLASSIFIER=1 and a provider is available, Session now attaches
risk_classifier=build_risk_classifier(provider) to the AgentRunSpec of each real
turn, so headless asks can be auto-allowed only when clearly low risk. Off by
default; inert when a human approver is attached.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant