Add window-scoped session closure fallback

This commit is contained in:
2026-07-13 16:23:38 +08:00
parent eb67212b17
commit 5ae0525611
3 changed files with 324 additions and 11 deletions

View File

@@ -86,7 +86,9 @@ def main() -> int:
if not source_trace.is_file():
raise SystemExit(f"source trace does not exist: {source_trace}")
source_sampling_strategy = source_window.get("sampling_strategy")
session_coherent_source = source_sampling_strategy == "session_coherent_uniform_score"
full_session_source = source_sampling_strategy == "session_coherent_uniform_score"
window_session_source = source_sampling_strategy == "window_session_closed_uniform_score"
session_closed_source = full_session_source or window_session_source
args.output_dir.mkdir(parents=True, exist_ok=True)
output_trace = args.output_dir / f"{args.output_window_id}.jsonl"
@@ -105,10 +107,10 @@ def main() -> int:
raise SystemExit(f"row {row_index}: expected an object")
sampling_u = numeric(row.get("sampling_u"), field="sampling_u", row_index=row_index)
session_entry: dict[str, int] | None = None
if session_coherent_source:
if session_closed_source:
if "session_root" not in row:
raise SystemExit(
f"row {row_index}: session-coherent source has no session_root"
f"row {row_index}: session-closed source has no session_root"
)
session_key = stable_session_key(row["session_root"])
session_entry = session_counts.setdefault(
@@ -153,8 +155,12 @@ def main() -> int:
"num_requests": selected,
"sampling_strategy": (
"session_coherent_uniform_score_then_greedy_temperature"
if session_coherent_source
else "fixed_uniform_score_then_greedy_temperature"
if full_session_source
else (
"window_session_closed_uniform_score_then_greedy_temperature"
if window_session_source
else "fixed_uniform_score_then_greedy_temperature"
)
),
"collectivespec_source_window_id": args.window_id,
"collectivespec_sampling_u_threshold": threshold,
@@ -162,7 +168,10 @@ def main() -> int:
"collectivespec_source_trace_path": str(source_trace),
"collectivespec_source_trace_sha256": sha256(source_trace),
"collectivespec_source_sampling_strategy": source_sampling_strategy,
"collectivespec_session_closed_within_window": session_coherent_source,
"collectivespec_session_closed_within_window": session_closed_source,
"collectivespec_session_closure_scope": (
"full_session" if full_session_source else "window_only" if window_session_source else None
),
}
)
output_windows = {
@@ -197,13 +206,14 @@ def main() -> int:
},
"temperature": {"distinct_value_count": 1, "all_zero": True},
"session": {
"source_is_session_coherent": session_coherent_source,
"session_root_count": len(session_counts) if session_coherent_source else None,
"source_is_session_coherent": full_session_source,
"source_is_window_session_closed": window_session_source,
"session_root_count": len(session_counts) if session_closed_source else None,
"selected_session_count": (
len(selected_session_turn_counts) if session_coherent_source else None
len(selected_session_turn_counts) if session_closed_source else None
),
"split_session_count": len(split_sessions) if session_coherent_source else None,
"all_selected_or_dropped": not split_sessions if session_coherent_source else None,
"split_session_count": len(split_sessions) if session_closed_source else None,
"all_selected_or_dropped": not split_sessions if session_closed_source else None,
"selected_turns": {
"min": min(selected_session_turn_counts)
if selected_session_turn_counts