Restore pending user message during active replay

This commit is contained in:
wuyang6
2026-05-12 10:58:25 +08:00
parent 26fe0f6a9d
commit 1bd80db2db
2 changed files with 59 additions and 5 deletions
+9 -5
View File
@@ -354,6 +354,7 @@ class RunRecord:
updated_at: float
cancel_event: threading.Event
process_registry: RunProcessRegistry
pending_prompt: str = ''
current_stage: str = ''
error: str = ''
events: list[dict[str, Any]] = field(default_factory=list)
@@ -365,7 +366,7 @@ class RunManager:
self._runs: dict[str, RunRecord] = {}
self._latest_by_session: dict[tuple[str, str], str] = {}
def start(self, account_key: str, session_id: str) -> RunRecord:
def start(self, account_key: str, session_id: str, pending_prompt: str = '') -> RunRecord:
now = time.time()
record = RunRecord(
run_id=uuid4().hex,
@@ -376,6 +377,7 @@ class RunManager:
updated_at=now,
cancel_event=threading.Event(),
process_registry=RunProcessRegistry(),
pending_prompt=pending_prompt,
)
with self._lock:
self._runs[record.run_id] = record
@@ -442,6 +444,7 @@ class RunManager:
'current_stage': record.current_stage,
'started_at': record.started_at,
'updated_at': record.updated_at,
'pending_prompt': record.pending_prompt,
'error': record.error,
'events': [dict(event) for event in record.events],
}
@@ -1303,7 +1306,8 @@ def create_app(state: AgentState) -> FastAPI:
request.resume_session_id or request.session_id
) or uuid4().hex
account_key = state._account_key(request.account_id)
run_record = state.run_manager.start(account_key, requested_session_id)
prompt = request.prompt.strip()
run_record = state.run_manager.start(account_key, requested_session_id, prompt)
run_lock = state.run_lock_for(request.account_id, requested_session_id)
agent = state.agent_for(request.account_id, requested_session_id)
config = state.config_for(request.account_id)
@@ -1326,7 +1330,7 @@ def create_app(state: AgentState) -> FastAPI:
directory=session_directory,
agent=agent,
session_id=requested_session_id,
prompt=request.prompt.strip(),
prompt=prompt,
)
if run_lock.locked():
queued_event = {
@@ -1384,14 +1388,14 @@ def create_app(state: AgentState) -> FastAPI:
)
stored = _sanitize_stored_session_for_resume(stored)
result = agent.resume(
request.prompt.strip(),
prompt,
stored,
runtime_context=request.runtime_context,
event_sink=emit_agent_event,
)
else:
result = agent.run(
request.prompt.strip(),
prompt,
session_id=requested_session_id,
runtime_context=request.runtime_context,
event_sink=emit_agent_event,