세션 계약과 메모리 경계 보강
This commit is contained in:
parent
391639c1de
commit
2bb052f624
12 changed files with 836 additions and 116 deletions
|
|
@ -26,6 +26,7 @@ from .. import session_persistence
|
|||
from ..deps import Principal, Role, require_role
|
||||
from ..engine_client import EngineError, engine_client
|
||||
from ..runtime_policy import runtime_fallback_allowed
|
||||
from ..session_read_model import StageLabel, stage_label_or_none
|
||||
from ..services import evaluator
|
||||
from ..services.evaluator import SessionEvaluation, TurnEvaluation
|
||||
from ..store import InProcSession
|
||||
|
|
@ -50,11 +51,19 @@ class EvaluationSummary(BaseModel):
|
|||
"""회기 평가 조회 응답(분포 + deep 결과 합본)."""
|
||||
|
||||
session_id: str
|
||||
stage: str
|
||||
stage: StageLabel | None = None
|
||||
deep: Optional[dict[str, Any]] = None
|
||||
distribution: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class TurnEvaluationResponse(TurnEvaluation):
|
||||
stage: StageLabel
|
||||
|
||||
|
||||
class SessionEvaluationResponse(SessionEvaluation):
|
||||
stage: StageLabel
|
||||
|
||||
|
||||
async def _load_session_or_404(session_id: str, principal: Principal) -> InProcSession:
|
||||
sess = await session_persistence.load_session(session_id, principal, allow_ended=True)
|
||||
if sess is not None:
|
||||
|
|
@ -74,6 +83,10 @@ def _theory_mode_of(sess) -> Optional[str]:
|
|||
return getattr(sess, "theory_mode", None)
|
||||
|
||||
|
||||
def _summary_stage(value: object) -> StageLabel | None:
|
||||
return stage_label_or_none(value)
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def eval_health() -> dict[str, str]:
|
||||
"""평가 라우터 헬스 — Features:evaluator 로 전환됨."""
|
||||
|
|
@ -83,7 +96,7 @@ async def eval_health() -> dict[str, str]:
|
|||
# ════════════════════════════════════════════════════════════════════════════
|
||||
# 회기 deep-loop 재평가 트리거 (교수자/관리자)
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
@router.post("/sessions/{session_id}/reevaluate", response_model=SessionEvaluation)
|
||||
@router.post("/sessions/{session_id}/reevaluate", response_model=SessionEvaluationResponse)
|
||||
async def reevaluate_session(
|
||||
session_id: str,
|
||||
body: ReevaluateRequest,
|
||||
|
|
@ -139,7 +152,7 @@ async def reevaluate_session(
|
|||
# ════════════════════════════════════════════════════════════════════════════
|
||||
# 단일 턴 fast-loop 재평가 트리거 (교수자/관리자)
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
@router.post("/sessions/{session_id}/turn", response_model=TurnEvaluation)
|
||||
@router.post("/sessions/{session_id}/turn", response_model=TurnEvaluationResponse)
|
||||
async def reevaluate_turn(
|
||||
session_id: str,
|
||||
body: TurnReevaluateRequest,
|
||||
|
|
@ -211,13 +224,13 @@ async def get_session_evaluation(
|
|||
await _load_session_or_404(session_id, principal)
|
||||
record, _durable = await session_persistence.load_session_evaluation(session_id, principal)
|
||||
if record is None:
|
||||
return EvaluationSummary(session_id=session_id, stage="", deep=None, distribution={})
|
||||
return EvaluationSummary(session_id=session_id, stage=None, deep=None, distribution={})
|
||||
payload = record.get("payload")
|
||||
deep = payload if isinstance(payload, dict) else {}
|
||||
distribution = deep.get("distribution")
|
||||
return EvaluationSummary(
|
||||
session_id=session_id,
|
||||
stage=str(record.get("stage") or deep.get("stage") or ""),
|
||||
stage=_summary_stage(record.get("stage") or deep.get("stage")),
|
||||
deep=deep,
|
||||
distribution=distribution if isinstance(distribution, dict) else {},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue