plm-engine-core 1.3.0__tar.gz → 1.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/PKG-INFO +1 -1
  2. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/__init__.py +1 -1
  3. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/dto.py +76 -0
  4. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/executor.py +44 -5
  5. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/registry.py +16 -1
  6. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/main.py +47 -0
  7. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/routers/agent_runs.py +10 -0
  8. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/settings.py +10 -0
  9. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/agent_telemetry_service.py +18 -2
  10. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/invocation_telemetry.py +9 -2
  11. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/llm_service.py +9 -1
  12. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core.egg-info/PKG-INFO +1 -1
  13. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core.egg-info/SOURCES.txt +2 -0
  14. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/pyproject.toml +1 -1
  15. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_agent_turn_execution.py +2 -2
  16. plm_engine_core-1.4.0/tests/test_dev_tenant_middleware.py +110 -0
  17. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_execution_error_normalization.py +3 -3
  18. plm_engine_core-1.4.0/tests/test_governed_turn_contract_extension.py +286 -0
  19. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_mcrc_trace.py +2 -2
  20. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_proof_driver.py +1 -1
  21. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_skill_dispatch_turn.py +1 -1
  22. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/README.md +0 -0
  23. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/agent_runtime/__init__.py +0 -0
  24. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/agent_runtime/dispatcher.py +0 -0
  25. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/agent_runtime/selector.py +0 -0
  26. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/cli/__init__.py +0 -0
  27. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/cli/__main__.py +0 -0
  28. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/cli/auth.py +0 -0
  29. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/__init__.py +0 -0
  30. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/_lint_fixtures/__init__.py +0 -0
  31. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/_lint_fixtures/violation_demo.py +0 -0
  32. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/capability_registry/__init__.py +0 -0
  33. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/capability_registry/errors.py +0 -0
  34. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/capability_registry/registry.py +0 -0
  35. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/connectors/__init__.py +0 -0
  36. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/connectors/dispatcher.py +0 -0
  37. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/connectors/runtime.py +0 -0
  38. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/dispatch.py +0 -0
  39. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/hitl/__init__.py +0 -0
  40. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/hitl/errors.py +0 -0
  41. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/hitl/gate.py +0 -0
  42. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/hitl/sql_store.py +0 -0
  43. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/identity/__init__.py +0 -0
  44. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/identity/middleware.py +0 -0
  45. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/identity/provider.py +0 -0
  46. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/identity/system_identity.py +0 -0
  47. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/identity/telemetry.py +0 -0
  48. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/knowledge/__init__.py +0 -0
  49. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/knowledge/curation_index.py +0 -0
  50. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/knowledge/envelope.py +0 -0
  51. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/knowledge/runtime.py +0 -0
  52. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/policies/__init__.py +0 -0
  53. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/policies/authorization.py +0 -0
  54. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/policies/autonomy_gating.py +0 -0
  55. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/policies/base.py +0 -0
  56. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/policies/cost_budget.py +0 -0
  57. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/policies/rate_limit.py +0 -0
  58. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/retry_policy.py +0 -0
  59. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/control_plane/run_task_tracker.py +0 -0
  60. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/__init__.py +0 -0
  61. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/__main__.py +0 -0
  62. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/__init__.py +0 -0
  63. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/bundle.py +0 -0
  64. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/event_bus.py +0 -0
  65. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/governance.py +0 -0
  66. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/hitl.py +0 -0
  67. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/lifecycle.py +0 -0
  68. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/mcrc.py +0 -0
  69. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/run_projection.py +0 -0
  70. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/snapshot.py +0 -0
  71. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/agent_run/taxonomy.py +0 -0
  72. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/readiness.py +0 -0
  73. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/routers/__init__.py +0 -0
  74. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/routers/config.py +0 -0
  75. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/core_host/routers/health.py +0 -0
  76. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/llm_catalog/__init__.py +0 -0
  77. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/llm_catalog/loader.py +0 -0
  78. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/llm_catalog/model_list.yaml +0 -0
  79. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/mcp/__init__.py +0 -0
  80. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/mcp/asgi.py +0 -0
  81. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/mcp/errors.py +0 -0
  82. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/mcp/manifest.py +0 -0
  83. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/mcp/openapi.py +0 -0
  84. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/mcp/server.py +0 -0
  85. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/mcp/tools.py +0 -0
  86. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/__init__.py +0 -0
  87. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/database.py +0 -0
  88. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/database_service.py +0 -0
  89. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/default_bindings.py +0 -0
  90. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/invocation_context.py +0 -0
  91. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/invocation_lifecycle.py +0 -0
  92. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/llm_env.py +0 -0
  93. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/plan_analysis_service.py +0 -0
  94. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/pricing_service.py +0 -0
  95. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/retry_orchestrator.py +0 -0
  96. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/retry_policy.py +0 -0
  97. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/run_task_tracker.py +0 -0
  98. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/scoped_state.py +0 -0
  99. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/token_estimator.py +0 -0
  100. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/runtime/workspace_port.py +0 -0
  101. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/studio/__init__.py +0 -0
  102. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/studio/readers/__init__.py +0 -0
  103. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core/studio/readers/mcrc_v1.py +0 -0
  104. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core.egg-info/dependency_links.txt +0 -0
  105. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core.egg-info/entry_points.txt +0 -0
  106. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core.egg-info/requires.txt +0 -0
  107. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/plm_engine_core.egg-info/top_level.txt +0 -0
  108. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/setup.cfg +0 -0
  109. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_agent_run_contract.py +0 -0
  110. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_agent_run_feature_flag.py +0 -0
  111. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_agent_run_hitl_contract.py +0 -0
  112. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_agent_run_mcrc_projection.py +0 -0
  113. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_agent_snapshot.py +0 -0
  114. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_authorization_policy.py +0 -0
  115. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_autonomy_gating_policy.py +0 -0
  116. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_capability_registry.py +0 -0
  117. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_cli_auth.py +0 -0
  118. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_connector_dispatcher.py +0 -0
  119. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_contract_bundle.py +0 -0
  120. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_core_host_build_app.py +0 -0
  121. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_core_host_wave9_parity_smoke.py +0 -0
  122. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_cost_budget_policy.py +0 -0
  123. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_error_code_mirror.py +0 -0
  124. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_error_taxonomy.py +0 -0
  125. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_evidence_pack.py +0 -0
  126. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_evidence_pack_cli.py +0 -0
  127. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_g8_conformance.py +0 -0
  128. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_gate_verdict.py +0 -0
  129. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_governance_chain.py +0 -0
  130. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_health_readiness.py +0 -0
  131. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_hitl_gate.py +0 -0
  132. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_hitl_resume.py +0 -0
  133. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_identity_middleware.py +0 -0
  134. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_identity_provider.py +0 -0
  135. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_import_linter.py +0 -0
  136. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_imports.py +0 -0
  137. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_knowledge_curation_index.py +0 -0
  138. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_knowledge_envelope.py +0 -0
  139. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_knowledge_runtime_adapter.py +0 -0
  140. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_mcp_asgi.py +0 -0
  141. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_mcp_server.py +0 -0
  142. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_mcrc_emitter_wiring.py +0 -0
  143. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_mcrc_v1_reader.py +0 -0
  144. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_model_dispatch.py +0 -0
  145. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_openapi.py +0 -0
  146. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_pf012_measure.py +0 -0
  147. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_plm_skill_kernel_optional.py +0 -0
  148. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_policy_pipeline_order.py +0 -0
  149. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_promotion_gate.py +0 -0
  150. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_rate_limit_policy.py +0 -0
  151. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_retry_policy.py +0 -0
  152. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_run_lifecycle.py +0 -0
  153. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_run_task_tracker.py +0 -0
  154. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_skill_selector.py +0 -0
  155. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_sse_backpressure.py +0 -0
  156. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_sse_event_stream.py +0 -0
  157. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_sse_reconnect.py +0 -0
  158. {plm_engine_core-1.3.0 → plm_engine_core-1.4.0}/tests/test_system_identity.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plm-engine-core
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: TracePulse PLM Engine Core — control_plane (governance, autonomy, HITL, run lifecycle, trace propagation) + agent_runtime (selector, dispatcher, retry, escalation). US-CR.1 scaffold; behaviour lands in US-CR.0+. Internal one-way import contract: control_plane MUST NOT import from agent_runtime (mechanical enforcement in US-CR.2).
5
5
  Author: TracePulse
6
6
  License: Proprietary
@@ -21,4 +21,4 @@ CR.11 retry, CR.12 capability registry, CR.13 HITL) lands its
21
21
  implementation inside these clear, enforceable internal boundaries
22
22
  from day one.
23
23
  """
24
- __version__ = "1.3.0"
24
+ __version__ = "1.4.0"
@@ -97,6 +97,52 @@ class AgentSnapshot(BaseModel):
97
97
  description="Skill references by id (an agent is not a skill — INV-003).",
98
98
  max_length=64,
99
99
  )
100
+ # ADR-0005 D1 — the agent's persona/expertise instruction. Placed on the
101
+ # snapshot (not the request) because it *is* agent configuration: it is
102
+ # therefore digest-covered and secret-scanned by E4 automatically
103
+ # (``_digest_content`` dumps the whole model minus ``digest``). Optional, so
104
+ # a consumer that omits it keeps the previous governed-runtime default.
105
+ system_prompt: Optional[str] = Field(
106
+ default=None,
107
+ max_length=65536,
108
+ description=(
109
+ "Agent persona/expertise system instruction (secret-free, "
110
+ "digest-covered). Omit to use the governed runtime default."
111
+ ),
112
+ )
113
+
114
+
115
+ class TurnRole(str, Enum):
116
+ """Role of a replayed conversational message (ADR-0005 D1)."""
117
+
118
+ USER = "user"
119
+ ASSISTANT = "assistant"
120
+ SYSTEM = "system"
121
+
122
+
123
+ class TurnMessage(BaseModel):
124
+ """One prior conversational turn replayed into a governed run (ADR-0005 D1).
125
+
126
+ Turn-scoped, not agent configuration — so this travels on the *request*,
127
+ never on the snapshot, and never enters the snapshot digest.
128
+ """
129
+
130
+ model_config = ConfigDict(extra="forbid")
131
+
132
+ role: TurnRole
133
+ content: str = Field(min_length=1, max_length=65536)
134
+
135
+
136
+ class TurnMode(str, Enum):
137
+ """Conversational mode of a governed turn (ADR-0005 D1).
138
+
139
+ Mirrors the consumer-side agent/plan/ask modes. Optional on the request; a
140
+ run without an explicit mode is executed as ``agent``.
141
+ """
142
+
143
+ AGENT = "agent"
144
+ PLAN = "plan"
145
+ ASK = "ask"
100
146
 
101
147
 
102
148
  class RunContext(BaseModel):
@@ -129,6 +175,21 @@ class AgentRunCreateRequest(BaseModel):
129
175
  agent: AgentSnapshot
130
176
  message: str = Field(min_length=1)
131
177
  context: Optional[RunContext] = None
178
+ # ADR-0005 D1 — turn-scoped conversational inputs. Both optional, so a
179
+ # single-shot consumer is unaffected. ``history`` is a bounded replay window
180
+ # the consumer chooses; Core does not read a conversation store.
181
+ history: Optional[List[TurnMessage]] = Field(
182
+ default=None,
183
+ max_length=200,
184
+ description=(
185
+ "Bounded prior-turn replay window, oldest first. Core is stateless "
186
+ "w.r.t. the consumer's conversation store (parity row P2)."
187
+ ),
188
+ )
189
+ mode: Optional[TurnMode] = Field(
190
+ default=None,
191
+ description="Conversational mode; absent is executed as 'agent'.",
192
+ )
132
193
 
133
194
 
134
195
  # ── Responses ─────────────────────────────────────────────────────────────
@@ -160,6 +221,18 @@ class AgentRunResource(BaseModel):
160
221
  state: RunState
161
222
  links: RunLinks
162
223
  created_at: str = Field(description="ISO-8601 UTC creation timestamp.")
224
+ # ADR-0005 D1 — the turn's reply text. Before this field the assistant's
225
+ # output had no channel out of Core at all: it lived only on the internal
226
+ # ``ExecutionResult`` for the E6 trace handoff. Optional and non-required,
227
+ # so a consumer pinned to the pre-extension shape stays wire-compatible.
228
+ # ``None`` until a terminal state carries a provider reply.
229
+ output_text: Optional[str] = Field(
230
+ default=None,
231
+ description=(
232
+ "Assistant reply text for a terminal run; None while non-terminal, "
233
+ "on failure, or when the turn required no provider call."
234
+ ),
235
+ )
163
236
 
164
237
 
165
238
  __all__ = [
@@ -168,6 +241,9 @@ __all__ = [
168
241
  "GenerationParameters",
169
242
  "ModelConfig",
170
243
  "AgentSnapshot",
244
+ "TurnRole",
245
+ "TurnMessage",
246
+ "TurnMode",
171
247
  "RunContext",
172
248
  "AgentRunCreateRequest",
173
249
  "RunLinks",
@@ -61,31 +61,60 @@ class LlmTurnResult:
61
61
  total_tokens: Optional[int] = None
62
62
 
63
63
 
64
+ #: Governed runtime default used when a snapshot announces no ``system_prompt``.
65
+ DEFAULT_SYSTEM_PROMPT = "You are a governed PLM agent runtime."
66
+
67
+
64
68
  class LlmTurnCallable(Protocol):
65
69
  """A single governed LLM turn. The concrete model + parameters are the
66
70
  authorized/resolved values; credentials are resolved runtime-side only and
67
- never passed through this seam."""
71
+ never passed through this seam.
72
+
73
+ ``system_prompt``/``history``/``mode`` arrive from the ADR-0005 D1 contract
74
+ fields. All three are optional: a single-shot consumer that omits them gets
75
+ exactly the pre-extension behaviour.
76
+ """
68
77
 
69
78
  def __call__(
70
- self, *, model: str, message: str, parameters: Mapping[str, Any]
79
+ self,
80
+ *,
81
+ model: str,
82
+ message: str,
83
+ parameters: Mapping[str, Any],
84
+ system_prompt: Optional[str] = None,
85
+ history: Optional["list[Mapping[str, str]]"] = None,
86
+ mode: Optional[str] = None,
71
87
  ) -> Awaitable[LlmTurnResult]: ...
72
88
 
73
89
 
74
90
  async def _production_llm_call(
75
- *, model: str, message: str, parameters: Mapping[str, Any]
91
+ *,
92
+ model: str,
93
+ message: str,
94
+ parameters: Mapping[str, Any],
95
+ system_prompt: Optional[str] = None,
96
+ history: Optional["list[Mapping[str, str]]"] = None,
97
+ mode: Optional[str] = None,
76
98
  ) -> LlmTurnResult:
77
99
  """Default provider adapter over :class:`LlmService` (lazy import so local
78
- tests never require provider credentials or the LiteLLM import chain)."""
100
+ tests never require provider credentials or the LiteLLM import chain).
101
+
102
+ ``mode`` is **not** semantically reinterpreted here: the consumer owns
103
+ mode-specific prompting and encodes it in ``system_prompt``. It travels this
104
+ seam so it is governed and traced, and so an alternative adapter can honour
105
+ it (ADR-0005 D1).
106
+ """
79
107
  from ...runtime.llm_service import llm_service # lazy singleton
80
108
 
81
109
  temperature = parameters.get("temperature")
82
110
  max_tokens = parameters.get("max_output_tokens")
83
111
  text, usage = await llm_service.generate_reply_with_usage(
84
- system_prompt="You are a governed PLM agent runtime.",
112
+ system_prompt=system_prompt or DEFAULT_SYSTEM_PROMPT,
85
113
  user_prompt=message,
86
114
  temperature=temperature if temperature is not None else 0.7,
87
115
  model=model,
88
116
  max_tokens=max_tokens,
117
+ history=list(history) if history else None,
89
118
  )
90
119
  return LlmTurnResult(
91
120
  text=text,
@@ -487,6 +516,9 @@ async def execute_turn(
487
516
  autonomy_level: str = DEFAULT_AUTONOMY_LEVEL,
488
517
  parameters: Optional[Mapping[str, Any]] = None,
489
518
  skills: Optional["list[str]"] = None,
519
+ system_prompt: Optional[str] = None,
520
+ history: Optional["list[Mapping[str, str]]"] = None,
521
+ mode: Optional[str] = None,
490
522
  tenant_id: Optional[str] = None,
491
523
  trace_id: str = "",
492
524
  store: Optional[ContractRunStore] = None,
@@ -500,6 +532,10 @@ async def execute_turn(
500
532
  Returns the :class:`ExecutionResult`, or ``None`` when the run was not
501
533
  claimable (idempotent replay, already running/terminal, cancelled, or
502
534
  awaiting HITL) — in which case **no business action is taken**.
535
+
536
+ ``system_prompt``/``history``/``mode`` carry the ADR-0005 D1 conversational
537
+ inputs to the provider seam. Omitting all three reproduces the
538
+ pre-extension single-shot turn exactly.
503
539
  """
504
540
  store = store or get_contract_run_store()
505
541
  llm = llm or get_llm_callable()
@@ -561,6 +597,9 @@ async def execute_turn(
561
597
  model=resolved_model or "",
562
598
  message=message,
563
599
  parameters=parameters or _generation_parameters(evidence),
600
+ system_prompt=system_prompt,
601
+ history=history,
602
+ mode=mode,
564
603
  )
565
604
  except Exception as exc: # noqa: BLE001 — one terminal outcome (AC-052)
566
605
  # US-014 — preserve the source category/retryability through the
@@ -264,9 +264,24 @@ class ContractRunStore:
264
264
 
265
265
  def attach_execution_result(self, run_id: str, result: object) -> None:
266
266
  """Store the run-scoped execution result (model identities, usage,
267
- outcome) for the E6 trace handoff. Not part of the ``/v1`` contract."""
267
+ outcome) for the E6 trace handoff — internal, not the ``/v1`` contract.
268
+
269
+ Also projects the result's ``output_text`` onto the stored resource so
270
+ every read path (``get``/``cancel``/``mark_terminal``) surfaces the reply
271
+ consistently (ADR-0005 D1). Both terminal helpers — ``_fail`` and
272
+ ``_finalize`` — call this, so stamping here covers success, failure, and
273
+ cancellation from one site. Model identities and token usage stay
274
+ internal: only the reply text is contractual.
275
+ """
276
+ text = getattr(result, "output_text", None)
268
277
  with self._lock:
269
278
  self._execution[run_id] = result
279
+ if text is not None:
280
+ resource = self._runs.get(run_id)
281
+ if resource is not None:
282
+ self._runs[run_id] = resource.model_copy(
283
+ update={"output_text": text}
284
+ )
270
285
 
271
286
  def get_execution_result(self, run_id: str) -> Optional[object]:
272
287
  with self._lock:
@@ -59,6 +59,7 @@ from __future__ import annotations
59
59
  import argparse
60
60
  import logging
61
61
  import os
62
+ import uuid
62
63
  from pathlib import Path
63
64
  from typing import List, Optional
64
65
 
@@ -67,6 +68,7 @@ from fastapi import FastAPI
67
68
  from plm_shared.cors import PlmCorsSettings, install_cors
68
69
  from plm_shared.middleware import PlmTenantMiddleware
69
70
  from plm_shared.middleware.traceparent import TraceparentMiddleware
71
+ from plm_shared.trace_context import new_root_context, reset_context, set_context
70
72
 
71
73
  from . import __version__
72
74
  from .routers import agent_runs as agent_runs_router
@@ -78,6 +80,38 @@ from .settings import EngineHostSettings, _resolve_install_identity
78
80
  logger = logging.getLogger(__name__)
79
81
 
80
82
 
83
+ class DevTenantMiddleware:
84
+ """DEV-ONLY ASGI middleware: bind a fixed tenant when the real tenant
85
+ middleware is disabled.
86
+
87
+ In production ``PlmTenantMiddleware`` (frozen) derives the tenant from a
88
+ validated ``X-Core-Caller`` header and 400s requests without it. In the
89
+ dev/SPA-parity launch that middleware is off and the web-shell calls
90
+ ``:8000`` (config/models, health, process generation) with no header — so
91
+ those calls would 400, and governed ``/v1/agent-runs`` turns would 401 for
92
+ lack of a bound tenant. This shim mirrors ``PlmTenantMiddleware``'s context
93
+ binding with a fixed configured dev tenant so an unheadered dev request is
94
+ admitted with a resolved tenant. Installed ONLY when the real tenant
95
+ middleware is off AND ``ENGINE_HOST_DEV_TENANT`` is set; production never
96
+ installs it. Plain ASGI (mirrors the frozen middleware, not
97
+ ``BaseHTTPMiddleware``).
98
+ """
99
+
100
+ def __init__(self, app, tenant_id: str):
101
+ self._app = app
102
+ self._tenant_id = str(uuid.UUID(str(tenant_id)))
103
+
104
+ async def __call__(self, scope, receive, send) -> None:
105
+ if scope.get("type") != "http":
106
+ await self._app(scope, receive, send)
107
+ return
108
+ handle = set_context(new_root_context(tenant_id=self._tenant_id))
109
+ try:
110
+ await self._app(scope, receive, send)
111
+ finally:
112
+ reset_context(handle)
113
+
114
+
81
115
  def _wire_identity(app: FastAPI) -> bool:
82
116
  """Install IdentityMiddleware + Hs256JwtIdentityProvider.
83
117
 
@@ -362,6 +396,19 @@ def build_app(
362
396
  "ENGINE_HOST_INSTALL_TENANT_MIDDLEWARE=0 (dev parity with "
363
397
  "legacy backend pre-ENABLE_PLM_IDENTITY_MIDDLEWARE wiring)"
364
398
  )
399
+ # DEV-ONLY: with the real tenant middleware off, optionally bind a
400
+ # fixed dev tenant so unheadered SPA calls to :8000 aren't 400'd and
401
+ # governed /v1/agent-runs turns resolve a tenant. Never in production.
402
+ if host_settings.engine_host_dev_tenant:
403
+ # Fail loud at construction (middleware is instantiated lazily).
404
+ dev_tenant = str(uuid.UUID(str(host_settings.engine_host_dev_tenant)))
405
+ app.add_middleware(DevTenantMiddleware, tenant_id=dev_tenant)
406
+ logger.warning(
407
+ "engine_host_dev_tenant: DEV tenant binding active (tenant=%s) "
408
+ "— NOT for production; requests are bound to this tenant with "
409
+ "no X-Core-Caller. Set only in local/dev launches.",
410
+ host_settings.engine_host_dev_tenant,
411
+ )
365
412
  if install_identity:
366
413
  _wire_identity(app)
367
414
  install_cors(app, settings=cors_settings)
@@ -179,6 +179,16 @@ async def create_agent_run(
179
179
  autonomy_level=autonomy_level,
180
180
  parameters=body.agent.model.parameters.model_dump(exclude_none=True),
181
181
  skills=body.agent.skills,
182
+ # ADR-0005 D1 — conversational inputs. `system_prompt` rides the
183
+ # snapshot (agent configuration, digest-covered); `history`/`mode`
184
+ # are turn-scoped and ride the request body.
185
+ system_prompt=body.agent.system_prompt,
186
+ history=(
187
+ [m.model_dump(mode="json") for m in body.history]
188
+ if body.history
189
+ else None
190
+ ),
191
+ mode=body.mode.value if body.mode else None,
182
192
  tenant_id=str(tenant_id),
183
193
  trace_id=resource.trace_id,
184
194
  )
@@ -89,6 +89,16 @@ class EngineHostSettings(BaseSettings):
89
89
  # boot preserved.
90
90
  engine_host_mcrc_emitter_tenant: Optional[str] = None
91
91
 
92
+ # DEV-ONLY tenant binding. When the real tenant middleware is disabled
93
+ # (``engine_host_install_tenant_middleware=False`` — the dev/SPA-parity
94
+ # launch where the web-shell calls :8000 with no ``X-Core-Caller``), a set
95
+ # value binds this tenant per request so (a) unheadered SPA calls are not
96
+ # 400'd by the rejecting middleware and (b) ``current_principal()`` finds a
97
+ # tenant, admitting governed ``/v1/agent-runs`` turns. IGNORED when the real
98
+ # tenant middleware is installed (production). Never enable in delivery.
99
+ # Set by ``run.py`` full mode alongside ``engine_host_mcrc_emitter_tenant``.
100
+ engine_host_dev_tenant: Optional[str] = None
101
+
92
102
  class Config:
93
103
  env_prefix = ""
94
104
  case_sensitive = False
@@ -22,7 +22,22 @@ Import-rewires applied at lift:
22
22
 
23
23
  Fire-and-forget persistence of LLM invocation records. Never blocks
24
24
  callers. Failures are logged, never propagated.
25
+
26
+ **Provider-import hygiene (ADR-0005 D4).** ``LlmUsage`` is used here in
27
+ *type positions only* (the :class:`InvocationTracker` field and the
28
+ ``record_invocation`` signature). Importing it eagerly pulled the whole
29
+ ``llm_service`` → LiteLLM chain into every process that imports this
30
+ telemetry module — which is what made `litellm` load in Studio, whose
31
+ only use of this module is ``record_invocation`` /
32
+ ``InvocationTracker`` / ``stamp_cancelled``. The import is therefore
33
+ ``TYPE_CHECKING``-only, and PEP 563 (``from __future__ import
34
+ annotations``) makes the annotations lazy strings so nothing resolves
35
+ ``LlmUsage`` at runtime. Safe here because this module defines only a
36
+ plain class and a plain ``@dataclass`` — no Pydantic/SQLModel model and
37
+ no ``get_type_hints()`` call resolves annotations eagerly.
25
38
  """
39
+ from __future__ import annotations
40
+
26
41
  import asyncio
27
42
  import json
28
43
  import logging
@@ -32,11 +47,12 @@ import uuid
32
47
  from concurrent.futures import ThreadPoolExecutor
33
48
  from dataclasses import dataclass, field
34
49
  from datetime import datetime, timezone
35
- from typing import Optional
50
+ from typing import TYPE_CHECKING, Optional
36
51
 
37
52
  from sqlmodel import Session
38
53
 
39
- from plm_engine_core.runtime.llm_service import LlmUsage
54
+ if TYPE_CHECKING: # pragma: no cover - typing-only, see module docstring
55
+ from plm_engine_core.runtime.llm_service import LlmUsage
40
56
 
41
57
 
42
58
  class _SettingsResolver:
@@ -24,12 +24,19 @@ move + an opt-in `stamp_invocation` entry point. Call-site migration in
24
24
  from __future__ import annotations
25
25
 
26
26
  import logging
27
- from typing import Optional
27
+ from typing import TYPE_CHECKING, Optional
28
28
 
29
29
  from plm_engine_core.runtime.invocation_context import InvocationContext
30
30
  from plm_shared.invocation_kinds import coerce_kind
31
31
  from plm_shared.system_context import coerce_agent_id, coerce_workspace_id
32
- from plm_engine_core.runtime.llm_service import LlmUsage
32
+
33
+ if TYPE_CHECKING: # pragma: no cover - typing-only (ADR-0005 D4)
34
+ # ``LlmUsage`` is referenced only in a signature annotation, and this module
35
+ # already has PEP 563, so a lazy import keeps the LiteLLM chain out of every
36
+ # process that imports telemetry. This is the second link of the chain
37
+ # `agent_telemetry_service -> invocation_telemetry -> llm_service -> litellm`;
38
+ # guarding only the first link left `litellm` loading.
39
+ from plm_engine_core.runtime.llm_service import LlmUsage
33
40
 
34
41
  logger = logging.getLogger(__name__)
35
42
 
@@ -498,13 +498,21 @@ Return ONLY the raw JSON object.
498
498
  temperature: float = 0.7,
499
499
  model: str | None = None,
500
500
  max_tokens: int | None = None,
501
+ history: list[dict] | None = None,
501
502
  ) -> Tuple[str, LlmUsage]:
502
- """Like generate_reply but also returns token usage metadata."""
503
+ """Like generate_reply but also returns token usage metadata.
504
+
505
+ ``history`` (ADR-0005 D1) replays prior role-tagged turns between the
506
+ system and the current user message, so a governed multi-turn run keeps
507
+ real roles instead of a flattened transcript. Trailing keyword with a
508
+ default — every existing positional caller is unaffected.
509
+ """
503
510
  resolved_model = model or self.model
504
511
  kwargs: dict = dict(
505
512
  model=resolved_model,
506
513
  messages=[
507
514
  {"role": "system", "content": system_prompt},
515
+ *(list(history) if history else []),
508
516
  {"role": "user", "content": user_prompt},
509
517
  ],
510
518
  temperature=temperature,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plm-engine-core
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: TracePulse PLM Engine Core — control_plane (governance, autonomy, HITL, run lifecycle, trace propagation) + agent_runtime (selector, dispatcher, retry, escalation). US-CR.1 scaffold; behaviour lands in US-CR.0+. Internal one-way import contract: control_plane MUST NOT import from agent_runtime (mechanical enforcement in US-CR.2).
5
5
  Author: TracePulse
6
6
  License: Proprietary
@@ -112,6 +112,7 @@ tests/test_contract_bundle.py
112
112
  tests/test_core_host_build_app.py
113
113
  tests/test_core_host_wave9_parity_smoke.py
114
114
  tests/test_cost_budget_policy.py
115
+ tests/test_dev_tenant_middleware.py
115
116
  tests/test_error_code_mirror.py
116
117
  tests/test_error_taxonomy.py
117
118
  tests/test_evidence_pack.py
@@ -120,6 +121,7 @@ tests/test_execution_error_normalization.py
120
121
  tests/test_g8_conformance.py
121
122
  tests/test_gate_verdict.py
122
123
  tests/test_governance_chain.py
124
+ tests/test_governed_turn_contract_extension.py
123
125
  tests/test_health_readiness.py
124
126
  tests/test_hitl_gate.py
125
127
  tests/test_hitl_resume.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "plm-engine-core"
7
- version = "1.3.0"
7
+ version = "1.4.0"
8
8
  description = "TracePulse PLM Engine Core — control_plane (governance, autonomy, HITL, run lifecycle, trace propagation) + agent_runtime (selector, dispatcher, retry, escalation). US-CR.1 scaffold; behaviour lands in US-CR.0+. Internal one-way import contract: control_plane MUST NOT import from agent_runtime (mechanical enforcement in US-CR.2)."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -73,7 +73,7 @@ class _FakeLlm:
73
73
  )
74
74
  self._raises = raises
75
75
 
76
- async def __call__(self, *, model, message, parameters):
76
+ async def __call__(self, *, model, message, parameters, **_):
77
77
  self.calls.append({"model": model, "message": message, "parameters": dict(parameters)})
78
78
  if self._raises is not None:
79
79
  raise self._raises
@@ -184,7 +184,7 @@ async def test_ac052_cancel_after_provider_boundary_wins() -> None:
184
184
  store = get_contract_run_store()
185
185
  run_id = _queued_run(store)
186
186
 
187
- async def cancelling_llm(*, model, message, parameters):
187
+ async def cancelling_llm(*, model, message, parameters, **_):
188
188
  store.cancel(run_id) # cooperative cancel lands during the turn
189
189
  return LlmTurnResult(text="late", used_model="openai/gpt-4o")
190
190
 
@@ -0,0 +1,110 @@
1
+ """DevTenantMiddleware (core_host) — dev-only tenant binding for middleware-off.
2
+
3
+ In production ``PlmTenantMiddleware`` (frozen) 400s any :8000 request without a
4
+ valid ``X-Core-Caller``. In the dev/SPA-parity launch that middleware is off and
5
+ the web-shell calls :8000 with no header, so those calls would 400 and governed
6
+ ``/v1/agent-runs`` turns would 401 for lack of a bound tenant. ``ENGINE_HOST_DEV_TENANT``
7
+ installs ``DevTenantMiddleware`` in that (and only that) case, binding a fixed
8
+ tenant per request.
9
+
10
+ Proven here:
11
+ * the middleware binds the configured tenant into ``current_context()`` for an
12
+ HTTP request and resets it afterwards (no leak); non-HTTP scopes pass through;
13
+ * build_app installs it ONLY when the real tenant middleware is off AND
14
+ ``engine_host_dev_tenant`` is set — inert in production;
15
+ * an unheadered request is admitted (200, not the middleware 400) when bound;
16
+ * a malformed dev-tenant UUID fails loud at construction.
17
+ """
18
+ from __future__ import annotations
19
+
20
+ import uuid
21
+
22
+ import pytest
23
+ from fastapi import FastAPI
24
+ from httpx import ASGITransport, AsyncClient
25
+
26
+ from plm_shared.trace_context import current_context
27
+ from plm_engine_core.core_host.main import DevTenantMiddleware, build_app
28
+ from plm_engine_core.core_host.settings import EngineHostSettings
29
+
30
+ _DEV_TENANT = "e0b41f0c-c55c-43e8-b534-e375ea8b4ba2"
31
+
32
+
33
+ def _mw_names(app: FastAPI) -> list:
34
+ return [m.cls.__name__ for m in app.user_middleware]
35
+
36
+
37
+ @pytest.mark.asyncio
38
+ async def test_middleware_binds_and_resets_context() -> None:
39
+ captured = {}
40
+
41
+ async def _inner(scope, receive, send):
42
+ ctx = current_context()
43
+ captured["tenant"] = ctx.tenant_id if ctx else None
44
+
45
+ mw = DevTenantMiddleware(_inner, tenant_id=_DEV_TENANT)
46
+ await mw({"type": "http", "headers": []}, None, None) # no X-Core-Caller
47
+
48
+ assert captured["tenant"] == _DEV_TENANT # bound for the request
49
+ assert current_context() is None # reset afterwards (no leak)
50
+
51
+
52
+ @pytest.mark.asyncio
53
+ async def test_non_http_scope_passes_through() -> None:
54
+ seen = {}
55
+
56
+ async def _inner(scope, receive, send):
57
+ seen["type"] = scope["type"]
58
+ seen["ctx"] = current_context()
59
+
60
+ mw = DevTenantMiddleware(_inner, tenant_id=_DEV_TENANT)
61
+ await mw({"type": "lifespan"}, None, None)
62
+ assert seen["type"] == "lifespan"
63
+ assert seen["ctx"] is None # not bound for non-http
64
+
65
+
66
+ def test_build_app_installs_dev_when_tenant_middleware_off() -> None:
67
+ settings = EngineHostSettings(
68
+ engine_host_install_tenant_middleware=False,
69
+ engine_host_dev_tenant=_DEV_TENANT,
70
+ )
71
+ app = build_app(install_identity=False, skip_startup=True, host_settings=settings)
72
+ names = _mw_names(app)
73
+ assert "DevTenantMiddleware" in names
74
+ assert "PlmTenantMiddleware" not in names # real middleware stays off
75
+
76
+
77
+ def test_build_app_no_dev_when_tenant_middleware_on() -> None:
78
+ # Real middleware ON + a dev tenant set → the dev shim is NEVER installed.
79
+ settings = EngineHostSettings(
80
+ engine_host_install_tenant_middleware=True,
81
+ engine_host_dev_tenant=_DEV_TENANT,
82
+ )
83
+ app = build_app(install_identity=False, skip_startup=True, host_settings=settings)
84
+ names = _mw_names(app)
85
+ assert "PlmTenantMiddleware" in names
86
+ assert "DevTenantMiddleware" not in names
87
+
88
+
89
+ @pytest.mark.asyncio
90
+ async def test_unheadered_request_admitted_when_dev_bound() -> None:
91
+ settings = EngineHostSettings(
92
+ engine_host_install_tenant_middleware=False,
93
+ engine_host_dev_tenant=_DEV_TENANT,
94
+ )
95
+ app = build_app(install_identity=False, skip_startup=True, host_settings=settings)
96
+ transport = ASGITransport(app=app)
97
+ async with AsyncClient(transport=transport, base_url="http://test") as client:
98
+ # No X-Core-Caller — with the real middleware this 400s; the dev
99
+ # binding admits it (the SPA-unheadered-call fix).
100
+ resp = await client.get("/v1/health")
101
+ assert resp.status_code == 200
102
+
103
+
104
+ def test_build_app_malformed_dev_tenant_fails_loud() -> None:
105
+ settings = EngineHostSettings(
106
+ engine_host_install_tenant_middleware=False,
107
+ engine_host_dev_tenant="not-a-uuid",
108
+ )
109
+ with pytest.raises(ValueError):
110
+ build_app(install_identity=False, skip_startup=True, host_settings=settings)
@@ -140,7 +140,7 @@ async def test_ac060_executor_maps_content_filter_end_to_end() -> None:
140
140
  store = get_contract_run_store()
141
141
  run_id = _queued_run(store)
142
142
 
143
- async def filtered_llm(*, model, message, parameters):
143
+ async def filtered_llm(*, model, message, parameters, **_):
144
144
  raise _model_error(ModelErrorCode.MODEL_CONTENT_FILTERED)
145
145
 
146
146
  result = await execute_turn(run_id, message="m", store=store, llm=filtered_llm)
@@ -169,7 +169,7 @@ async def test_ac061_terminal_signal_emitted_exactly_once_on_failure() -> None:
169
169
  run_id = _queued_run(store)
170
170
  sink = _CountingSink()
171
171
 
172
- async def boom(*, model, message, parameters):
172
+ async def boom(*, model, message, parameters, **_):
173
173
  raise _model_error(ModelErrorCode.MODEL_PROVIDER_ERROR)
174
174
 
175
175
  await execute_turn(run_id, message="m", store=store, llm=boom, sink=sink)
@@ -184,7 +184,7 @@ async def test_ac061_terminal_signal_emitted_exactly_once_on_success() -> None:
184
184
  run_id = _queued_run(store)
185
185
  sink = _CountingSink()
186
186
 
187
- async def ok_llm(*, model, message, parameters):
187
+ async def ok_llm(*, model, message, parameters, **_):
188
188
  return LlmTurnResult(text="ok", used_model="openai/gpt-4o")
189
189
 
190
190
  await execute_turn(run_id, message="m", store=store, llm=ok_llm, sink=sink)