Skip to content

Fix sandbox literal hit double counting - #14

Merged
minto-dane merged 1 commit into
masterfrom
codex/fix-double-counting-of-literal-hits-tedsfd
Jun 1, 2026
Merged

Fix sandbox literal hit double counting#14
minto-dane merged 1 commit into
masterfrom
codex/fix-double-counting-of-literal-hits-tedsfd

Conversation

@minto-dane

Copy link
Copy Markdown
Owner

Motivation

  • Literal sequence matches were being counted twice because the detector passed total_count (which includes sequence_hits) into the sandbox, and the sandbox also independently counts literal oo/おお/オオ sequences. This could turn single-match inputs that should only get a reaction into outbound SendMessage actions.
  • The response compiler chose send-vs-react based on the untrusted sandbox proposal before capping repeats to the trusted detector count, enabling an inflated proposal to override the trusted detector.

Description

  • Change DetectionReport::backend_count_for_sandbox() to return kanji_hits instead of total_count so only morphological/kanji hits (not configured literal sequence hits) are supplied to the sandbox (src/domain/detector.rs).
  • Update proposal_to_action so the SendStamped branch computes repeats = (*count as usize).min(detector_total_count.max(1)) first and then decides react-vs-send based on repeats <= 1, ensuring the trusted detector count caps the outbound/send decision (src/security/response_compiler.rs).
  • Add unit/regression tests: sandbox_backend_count_excludes_literal_sequence_hits for the detector sandbox count, caps_send_decision_to_trusted_detector_count for the compiler capping, and single_literal_match_reacts_once in the integration tests to assert governed behavior for a single literal match (src/domain/detector.rs, src/security/response_compiler.rs, tests/runtime_protection_integration.rs).

Testing

  • Ran the new detector unit test sandbox_backend_count_excludes_literal_sequence_hits with DOCS_RS=1 and it passed.
  • Ran the new response-compiler unit test caps_send_decision_to_trusted_detector_count with DOCS_RS=1 and it passed.
  • Ran the new integration test single_literal_match_reacts_once with DOCS_RS=1 and it passed.
  • cargo fmt --check and repository checks (git diff --check) passed.
  • Note: running the full runtime_protection_integration test suite without DOCS_RS=1 failed earlier because the lindera-ipadic build script could not download dictionary assets in this environment; targeted tests were executed with DOCS_RS=1 to avoid that external download and validate the fixes.

Codex Task

@minto-dane
minto-dane merged commit e1a43aa into master Jun 1, 2026
8 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant