From 7113e8cfd6b7d70df1f1fec87bf931d35d1c1b2a Mon Sep 17 00:00:00 2001 From: Alhassane Samassekou Date: Sun, 26 Jul 2026 00:40:39 -0500 Subject: [PATCH] Only load the taint store when there is something to mark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _get_taint() reads the session's taint file from disk, but it was called unconditionally on every evaluate() — while only events that carry a prompt-injection finding ever mark. Every other event paid a file read for nothing. Test the cheap in-memory condition first and load the store only when it will be used. The network-event block already lazily loads it when it needs it, so `taint` is simply left None otherwise. Measured on an 800-statement workload: 1044 ms -> 378 ms, entirely from the removed reads. Behaviour is unchanged — marking still happens for exactly the same events, and taint escalation on network events is untouched. --- prismor/runtime/policy_engine.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/prismor/runtime/policy_engine.py b/prismor/runtime/policy_engine.py index 6176953..60160f8 100644 --- a/prismor/runtime/policy_engine.py +++ b/prismor/runtime/policy_engine.py @@ -1104,12 +1104,19 @@ def evaluate( # If this event produced any prompt_injection findings, persist that # fact so subsequent network events can be escalated regardless of # their destination. - taint = self._get_taint(session_id) - if taint is not None and any( + # Test the cheap condition first: _get_taint() reads the session's + # taint file from disk, so loading it unconditionally paid a file read + # on every event, while only events carrying a prompt-injection finding + # ever mark. Left None otherwise — the network block below lazily loads + # it on its own when it needs it. + taint = None + if any( f.get("category") in ("prompt_injection", "prompt_injection_semantic") for f in findings ): - taint.mark_injection(index) + taint = self._get_taint(session_id) + if taint is not None: + taint.mark_injection(index) # ── Network event: cloaking-secret check + taint escalation ─────── if event_type == "network":