← Back to Pull requests

feat(policy-engine): honor the manifest approval.timeout_seconds in HostSession #4045

Closed
unknown closed this pull request without merging on Sep 21, 2026 15:38 UTC
View on GitHub
unknown unknown commented on Sep 20, 2026 00:09 UTC
Author

HostSession bounded its synchronous approval wait with a fixed DEFAULT_APPROVAL_TIMEOUT_SECONDS (300 s) unless the caller passed approval_timeout_seconds, and its docstring noted that the manifest's approval.timeout_seconds (SPECIFICATION section 24, spec/schema/approval.schema.json: integer seconds) could not be read because nothing surfaced the approval section across the native boundary. A host that declared timeout_seconds: 120 in its manifest therefore still waited 300 s before failing closed with host_error:approval_unresolved. HostSession only ever sees an already-built control, and the SDK holds the manifest text only for from_native; from_path resolves extends parents, and from_url / from_manifest_chain never hand the merged text back to Python, so re-parsing on the Python side with the public parse_manifest would miss an inherited or chained approval block.

This follows the existing policy_labels pattern instead: NativeRuntime now keeps the merged manifest's approval section (serialised from the crate's typed ApprovalSection, None when undeclared) and exposes it as approval_config(); NativeRuntimeClient.approval_config() mirrors it best-effort (empty mapping when the extension or accessor is missing, like policy_labels); AgentControl.approval_config is a read-only mapping populated at construction for every native-backed constructor; and HostSession reads timeout_seconds from it when the caller passes no approval_timeout_seconds. The explicit argument still wins, a custom control without approval_config or with a non-integer value keeps the 300 s default, and on_timeout is left for a follow-up because HostSession does not implement the suspend outcome yet. The README's escalation section documents the new accessor.

Testing

Unit tests added: policy-engine/sdk/python/tests/test_host.py covers the manifest value replacing the default, the explicit argument winning over the manifest, unusable values ({}, no timeout_seconds, string, bool, negative, non-mapping) keeping the default, and a hung resolver being cut off by the manifest bound. policy-engine/sdk/python/tests/test_native_runtime.py adds a manifest fixture with an approval block (timeout_seconds: 120) and checks AgentControl.from_native(...).approval_config and the resulting HostSession timeout end to end through the real parser, plus the no-approval case.

The Rust change means _native must be rebuilt (maturin build / maturin develop); against a stale extension the two native-gated tests fail because the accessor is absent.

$ cd policy-engine/sdk/python && maturin build --out dist        # maturin 1.8.7
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.34s
📦 Built wheel for abi3 Python ≥ 3.11 to dist/agent_control_specification-0.4.0b0-cp311-abi3-macosx_14_0_arm64.whl

$ PYTHONPATH=policy-engine/sdk/python python -m pytest policy-engine/sdk/python/tests/test_host.py policy-engine/sdk/python/tests/test_native_runtime.py -q -k "manifest_timeout or manifest_without or manifest_approval or explicit_timeout"
12 passed, 48 deselected in 1.04s

$ PYTHONPATH=policy-engine/sdk/python python -m pytest policy-engine/sdk/python/tests -q
6 failed, 259 passed, 34 skipped, 54 subtests passed in 3.07s

$ cd policy-engine && cargo fmt --check -p agent_control_specification_py && echo clean
clean
$ cargo clippy -p agent_control_specification_py --all-targets -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 22.60s

The 6 failures are the pre-existing tests/test_validation.py cases that need an opa binary on PATH; origin/main gives 6 failed, 248 passed, 34 skipped in the same environment (Python 3.12, pytest 9.1.1).

Diff: 477 lines (+357 / -120) across 5 files Reviewer: david-long1 Review duration: 2368m
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.46) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 477 lines diff across 5 files
0.46
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.369
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #4045"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.8% (MEDIUM) · Higher = larger blast radius
45.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 19.8% · Safe to merge
19.8%