perf(policies): remove unused trajectory DB read from policy evaluation#2701
Conversation
|
EvaluationContext.trajectory was populated on every POST /policies/evaluate call via a list_items() query (last 10 conversation items), but no policy implementation ever read it — FunctionPolicy, PromptPolicy, and LabelPolicy all ignore ctx.trajectory. The fetch was dead work on every tool call hook. Remove _populate_trajectory, _TRAJECTORY_WINDOW, EvaluationContext.trajectory, and the now-unused ConversationItem import. Eliminates one DB read per policy evaluation, which fires multiple times per turn across all harnesses.
- Delete test_engine_trajectory.py: tested EvaluationContext.trajectory which no longer exists after removing the trajectory DB read - Fix test_hosts_changed_frame_updates_host_badge: stub /health to return empty sessions so liveOnline stays undefined; without this the health poll sets liveOnline=null (no real host bound), overriding the useHosts mock and preventing the badge from ever showing "online"
1227b0b to
1336caf
Compare
|
🏷️ Doc impact: This removes an internal, never-shipped policy-engine trajectory-population feature (types field, engine method, and its tests) and adjusts a test stub — no user-facing surface, integration, built-in policy, or documented default changed. Auto-classified on merge. Set the label manually before merging to override. · run |
Summary
EvaluationContext.trajectorywas populated on everyPOST /v1/sessions/{id}/policies/evaluatecall via alist_items()DB query (last 10 conversation items), but no policy implementation ever read it —FunctionPolicy,PromptPolicy, andLabelPolicyall ignorectx.trajectory. The fetch was dead work executed on every tool call hook invocation.Since
POST /policies/evaluateis called multiple times per turn (once perPHASE_TOOL_CALL,PHASE_TOOL_RESULT,PHASE_LLM_REQUEST, etc.), this was adding N redundant DB reads per turn across all harnesses._populate_trajectory()and its call site inengine.py_TRAJECTORY_WINDOW = 10constantEvaluationContext.trajectoryfield fromtypes.pyConversationItemimport andTYPE_CHECKINGTest Plan
ctx.trajectoryDemo
N/A — no visible change.
Type of change
Test coverage
Coverage notes
No policy implementation reads
ctx.trajectory— confirmed by grepping the entire codebase. Removal is safe.