This commit is contained in:
2026-01-03 21:23:55 -08:00
parent 73f3005393
commit 3acf21a673
10 changed files with 1244 additions and 43 deletions

View File

@@ -10,7 +10,7 @@ from dataclasses import dataclass, field
from contextvars import ContextVar
from typing import Any, Dict, List, Optional, Sequence
from SYS.models import PipelineStageContext
from SYS.logger import log
from SYS.logger import log, debug, is_debug_enabled
def set_live_progress(progress_ui: Any) -> None:
@@ -696,8 +696,11 @@ def restore_previous_result_table() -> bool:
# If an underlying table exists, we're done.
# Otherwise, fall through to history restore so @.. actually returns to the last table.
if state.last_result_table is not None:
# Ensure subsequent @N selection uses the table the user sees.
state.current_stage_table = state.last_result_table
return True
if not state.result_table_history:
state.current_stage_table = state.last_result_table
return True
if not state.result_table_history:
@@ -723,6 +726,15 @@ def restore_previous_result_table() -> bool:
state.display_table = None
state.display_subject = None
# Sync current stage table to the restored view so provider selectors run
# against the correct table type.
state.current_stage_table = state.last_result_table
try:
debug_table_state("restore_previous_result_table")
except Exception:
pass
return True
@@ -740,8 +752,11 @@ def restore_next_result_table() -> bool:
# If an underlying table exists, we're done.
# Otherwise, fall through to forward restore when available.
if state.last_result_table is not None:
# Ensure subsequent @N selection uses the table the user sees.
state.current_stage_table = state.last_result_table
return True
if not state.result_table_forward:
state.current_stage_table = state.last_result_table
return True
if not state.result_table_forward:
@@ -769,6 +784,15 @@ def restore_next_result_table() -> bool:
state.display_table = None
state.display_subject = None
# Sync current stage table to the restored view so provider selectors run
# against the correct table type.
state.current_stage_table = state.last_result_table
try:
debug_table_state("restore_next_result_table")
except Exception:
pass
return True
@@ -819,6 +843,78 @@ def get_last_result_items() -> List[Any]:
return []
def debug_table_state(label: str = "") -> None:
"""Dump pipeline table and item-buffer state (debug-only).
Useful for diagnosing cases where `@N` selection appears to act on a different
table than the one currently displayed.
"""
if not is_debug_enabled():
return
state = _get_pipeline_state()
def _tbl(name: str, t: Any) -> None:
if t is None:
debug(f"[table] {name}: None")
return
try:
table_type = getattr(t, "table", None)
except Exception:
table_type = None
try:
title = getattr(t, "title", None)
except Exception:
title = None
try:
src_cmd = getattr(t, "source_command", None)
except Exception:
src_cmd = None
try:
src_args = getattr(t, "source_args", None)
except Exception:
src_args = None
try:
no_choice = bool(getattr(t, "no_choice", False))
except Exception:
no_choice = False
try:
preserve_order = bool(getattr(t, "preserve_order", False))
except Exception:
preserve_order = False
try:
row_count = len(getattr(t, "rows", []) or [])
except Exception:
row_count = 0
try:
meta = (
t.get_table_metadata() if hasattr(t, "get_table_metadata") else getattr(t, "table_metadata", None)
)
except Exception:
meta = None
meta_keys = list(meta.keys()) if isinstance(meta, dict) else []
debug(
f"[table] {name}: id={id(t)} class={type(t).__name__} title={repr(title)} table={repr(table_type)} rows={row_count} "
f"source={repr(src_cmd)} source_args={repr(src_args)} no_choice={no_choice} preserve_order={preserve_order} meta_keys={meta_keys}"
)
if label:
debug(f"[table] state: {label}")
_tbl("display_table", getattr(state, "display_table", None))
_tbl("current_stage_table", getattr(state, "current_stage_table", None))
_tbl("last_result_table", getattr(state, "last_result_table", None))
try:
debug(
f"[table] buffers: display_items={len(state.display_items or [])} last_result_items={len(state.last_result_items or [])} "
f"history={len(state.result_table_history or [])} forward={len(state.result_table_forward or [])} last_selection={list(state.last_selection or [])}"
)
except Exception:
pass
def get_last_selectable_result_items() -> List[Any]:
"""Get items from the last *selectable* result table, ignoring display-only items.