Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mediaforce/web/runtime/folder_tuning_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def _merge_operator_note_parse(
merged["operator_confirmed"] = True
if str(merged.get("intent_type") or "").strip().lower() in {"unclear", "other"}:
merged["intent_type"] = "direct_request"
if heuristic.get("measured_size_followup"):
merged["measured_size_followup"] = True
merged = _normalize_operator_note_parse(merged)
if merged is None:
return heuristic
Expand Down
11 changes: 8 additions & 3 deletions mediaforce/web/runtime/folder_tuning_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ def measured_size_budget_policy_fragment(
if str(request.get("request_type") or "").strip().lower() not in {"size_budget", "combined_experiment"}:
return {}
size_budget_request = object_dict(request.get("size_budget_request"))
hard_size_cap = bool(request.get("hard_size_cap") or size_budget_request.get("hard_size_cap"))
hard_size_cap = bool(
request.get("operator_confirmed")
and (request.get("hard_size_cap") or size_budget_request.get("hard_size_cap"))
)
measured_size_followup = bool(
request.get("operator_confirmed")
and (request.get("measured_size_followup") or size_budget_request.get("measured_size_followup"))
Expand Down Expand Up @@ -151,8 +154,10 @@ def allows_measured_size_quality_tradeoff(
return False
size_budget_request = object_dict(request.get("size_budget_request"))
return bool(
request.get("hard_size_cap")
or size_budget_request.get("hard_size_cap")
(
request.get("operator_confirmed")
and (request.get("hard_size_cap") or size_budget_request.get("hard_size_cap"))
)
or (
request.get("operator_confirmed")
and (request.get("measured_size_followup") or size_budget_request.get("measured_size_followup"))
Expand Down
55 changes: 55 additions & 0 deletions tests/test_tuning_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3555,6 +3555,47 @@ def test_operator_requested_experiment_marks_measured_size_followup(self) -> Non
self.assertTrue(request["measured_size_followup"])
self.assertFalse(request["hard_size_cap"])

def test_operator_requested_experiment_keeps_heuristic_followup_when_structured_parse_misses_it(self) -> None:
structured_parse = {
"summary": "Size follow-up request.",
"intent_type": "direct_request",
"request_type": "size_budget",
"operator_confirmed": True,
"measured_size_followup": False,
"metric": None,
"metric_target": None,
"size_budget_value": 300,
"size_budget_unit": "mb",
"scale_height": None,
"black_bar_handling": None,
"crop": None,
"hard_size_cap": False,
"reasoning_note": "Structured parse missed the measured follow-up wording.",
}

with patch(
"mediaforce.web.runtime.folder_tuning_advice.request_operator_note_parse",
return_value=structured_parse,
):
request = _operator_requested_experiment(
"Revise this sample smaller toward 300 MB per episode. The last sample was 766 MiB, 2.6x target.",
{
"source_size_bytes": 4_349_049_136,
"duration_seconds": 3161.376,
"audio_summary": [{"codec_name": "ac3", "channels": 6}],
"resolved_policy": {
"video": {"encoder": "libsvtav1"},
"audio": {
"convert_to_opus_codecs": ["ac3"],
"surround_5_1_opus_bitrate": "256k",
},
},
},
)

assert request is not None
self.assertTrue(request["measured_size_followup"])

def test_operator_requested_experiment_detects_scale_target_request(self) -> None:
request = _operator_requested_experiment("Downsample the 4K files to 1080p for this folder.")

Expand Down Expand Up @@ -4514,11 +4555,25 @@ def test_measured_size_budget_policy_fragment_ignores_unconfirmed_followup_after

self.assertEqual(fragment, {})

def test_measured_size_budget_policy_fragment_ignores_unconfirmed_hard_cap_after_miss(self) -> None:
fragment = measured_size_budget_policy_fragment(
operator_request={
"request_type": "size_budget",
"requested_max_encoded_percent": 7.23,
"operator_confirmed": False,
"hard_size_cap": True,
},
size_target_analysis={"status": "over_target"},
)

self.assertEqual(fragment, {})

def test_measured_size_budget_policy_fragment_enforces_explicit_hard_cap_after_miss(self) -> None:
fragment = measured_size_budget_policy_fragment(
operator_request={
"request_type": "size_budget",
"requested_max_encoded_percent": 7.23,
"operator_confirmed": True,
"hard_size_cap": True,
},
size_target_analysis={"status": "over_target"},
Expand Down