-
Notifications
You must be signed in to change notification settings - Fork 0
closed — replaced by #4 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
af78eb3
fa678ad
e27c97b
a2c421b
af3d99e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,9 @@ | |
| from typing import Any | ||
|
|
||
| from fastapi import APIRouter, BackgroundTasks, Query, Request | ||
| from fastapi.responses import JSONResponse | ||
|
|
||
| from multihead.models import HeadState | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
@@ -16,7 +19,7 @@ | |
| "running": False, | ||
| "last_report": None, | ||
| "current_stage": None, | ||
| "progress": deque(maxlen=100), | ||
| "progress": deque(maxlen=5000), | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -28,12 +31,25 @@ async def trigger_nightshift( | |
| concurrency: int = Query(1, description="Parallel LLM calls per stage (1=sequential)"), | ||
| ) -> dict[str, Any]: | ||
| """Trigger a Night Shift run in the background.""" | ||
| # Check for at least one active head before starting | ||
| head_manager = request.app.state.head_manager | ||
| states = head_manager.get_states() | ||
| has_active = any( | ||
| info.get("state") == HeadState.ACTIVE.value | ||
| for info in states.values() | ||
| ) | ||
| if not has_active: | ||
| return JSONResponse( | ||
| status_code=400, | ||
| content={"error": "No active heads — wake a head before running Night Shift"}, | ||
| ) | ||
|
|
||
| async with _nightshift_lock: | ||
| if _nightshift_status["running"]: | ||
| return {"status": "already_running"} | ||
| _nightshift_status["running"] = True | ||
| _nightshift_status["current_stage"] = None | ||
| _nightshift_status["progress"] = deque(maxlen=100) | ||
| _nightshift_status["progress"] = deque(maxlen=5000) | ||
|
|
||
|
Comment on lines
49
to
53
|
||
| night_shift = request.app.state.night_shift | ||
| night_shift.config.concurrency = max(1, concurrency) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint is annotated to return
dict[str, Any]but returns aJSONResponsefor the 400 case. To keep the return type consistent and improve generated OpenAPI docs, prefer raisingfastapi.HTTPException(status_code=400, detail=...)(or update the return type annotation/response model to include theJSONResponsepath).