feat(deep-research): 强化任务链路可靠性并接入 agentfx 报告助手种子

功能说明:\n- 重构 Deep Research 调度与执行链,补齐 dispatcher、executor、live hub 与依赖注入入口,提升任务下发、执行、回调的稳定性\n- 增强运行时持久化与恢复能力,接入业务映射、任务来源与任务事件日志模型,覆盖持久化与执行可靠性关键路径测试\n- 新增 agentfx 报告助手 seed 与任务报告导入脚本配置,支持离线环境快速初始化与任务流模板回填\n- 完善 deep-research 与 thread_runs 路由参数编排,兼容不同业务映射与运行入口的前后端联动\n- 补充前端 agentfx deep-link 解析,保证 deep-research 场景下的登录跳转与任务上下文一致
This commit is contained in:
董宏凯 committed 2026-09-04 23:18:52 +08:00
1 parent 438772f0b7
commit 5c75e1af16
36 files changed
+3163 -312

No files matched your search

@@ -27,7 +27,9 @@ async def test_event_persistence_failure_keeps_job_live_and_emits_unique_fallbac
first = await sink.emit("phase_changed", phase="planning", payload={"to": "planning"})
second = await sink.emit("queries_planned", phase="collecting", payload={"queries": ["AI"]})
assert (first.seq, second.seq) == (-1, -2)
# A degraded emit consumes two negative sequences: the original frame plus
# the copyable diagnostic that follows it, so the second emit lands on -3.
assert (first.seq, second.seq) == (-1, -3)
assert first.payload["eventPersistenceDegraded"] is True
assert published[0]["liveId"] == "event-persistence-fallback:drj_1:1"
assert published[1]["liveId"] == "event-persistence-fallback:drj_1:2"
@@ -59,6 +61,116 @@ async def test_live_publish_failure_does_not_fail_event_delivery():
assert event.seq == 1
class _RecordingEventRepository:
def __init__(self) -> None:
self.rows: list[dict] = []
async def append(self, **kwargs): # noqa: ANN003
self.rows.append(kwargs)
return {
"seq": len(self.rows),
"event_type": kwargs["event_type"],
"phase": kwargs["phase"],
"payload": kwargs["payload"],
}
async def _noop_publish(event: dict) -> None: # noqa: ARG001
return None
def _mirrored(repo: _RecordingEventRepository, event_type: str) -> list[dict]:
return [row for row in repo.rows if row["event_type"] == event_type]
@pytest.mark.asyncio
async def test_reasoning_frames_are_mirrored_durably_when_no_viewer_is_on_this_worker():
"""Multi-worker guard: thinking must not vanish into a subscriber-less hub.
A job runs on the worker that won its lease while the SSE connection is
served by whichever worker accepted it. Live-only frames published into an
empty in-process hub are lost with no durable row to replay them from,
which is what silently removed the step bar's thinking text.
"""
repo = _RecordingEventRepository()
sink = PersistingEventSink(
repo,
session_id="drs_1",
job_id="drj_1",
on_event=_noop_publish,
live_subscriber_probe=lambda _job_id: False,
)
for _ in range(3):
await sink.publish_live(
"report_thinking",
phase="writing",
payload={"delta": "思" * 240, "target": "report", "reportVersion": 1},
)
mirrored = _mirrored(repo, "report_thinking")
assert mirrored, "reasoning must be persisted when the hub has no subscriber"
assert "".join(row["payload"]["delta"] for row in mirrored) == "思" * 720
assert mirrored[0]["payload"]["liveMirror"] is True
assert mirrored[0]["payload"]["target"] == "report"
# Coalesced, never one row per provider token.
assert len(mirrored) == 1
@pytest.mark.asyncio
async def test_a_locally_attached_viewer_keeps_reasoning_off_the_database():
repo = _RecordingEventRepository()
sink = PersistingEventSink(
repo,
session_id="drs_1",
job_id="drj_1",
on_event=_noop_publish,
live_subscriber_probe=lambda _job_id: True,
)
for _ in range(5):
await sink.publish_live("report_thinking", phase="writing", payload={"delta": "思" * 240})
assert _mirrored(repo, "report_thinking") == []
@pytest.mark.asyncio
async def test_report_text_is_never_mirrored_and_the_tail_flushes_before_the_next_event():
repo = _RecordingEventRepository()
sink = PersistingEventSink(
repo,
session_id="drs_1",
job_id="drj_1",
on_event=_noop_publish,
live_subscriber_probe=lambda _job_id: False,
)
# Report prose already has a durable counterpart (``report_chunk``); a
# mirror would duplicate it in the assembled report.
await sink.publish_live("report_delta", phase="writing", payload={"delta": "正文", "offset": 0})
assert _mirrored(repo, "report_delta") == []
# A short reasoning tail stays buffered, then lands ahead of the next
# durable milestone instead of waiting for the job to end.
await sink.publish_live("report_thinking", phase="writing", payload={"delta": "短思考"})
assert _mirrored(repo, "report_thinking") == []
await sink.emit("report_completed", phase="writing", payload={})
assert [row["event_type"] for row in repo.rows] == ["report_thinking", "report_completed"]
@pytest.mark.asyncio
async def test_mirroring_is_off_without_a_probe():
"""Single-worker deployments and tests keep zero extra database writes."""
repo = _RecordingEventRepository()
sink = PersistingEventSink(repo, session_id="drs_1", job_id="drj_1", on_event=_noop_publish)
await sink.publish_live("report_thinking", phase="writing", payload={"delta": "思" * 900})
assert repo.rows == []
@pytest.mark.asyncio
async def test_document_rewrite_milestone_is_a_supported_durable_event():
"""Guard the artifact-rewrite job path against EventType regressions."""
@@ -42,6 +42,8 @@ async def test_report_is_persisted_before_job_is_marked_completed():
"drs_1",
"worker_1",
DeepResearchResult(report_markdown="# 报告", source_ids=["src_1"]),
user_id="user_1",
query="课题",
)
assert sessions.report_updates[0]["report_markdown"] == "# 报告"
@@ -62,6 +64,8 @@ async def test_report_projection_failure_never_marks_job_completed(monkeypatch):
"drs_1",
"worker_1",
DeepResearchResult(report_markdown="# 报告"),
user_id="user_1",
query="课题",
)
assert jobs.progress_calls == []
@@ -70,3 +74,26 @@ async def test_report_projection_failure_never_marks_job_completed(monkeypatch):
def test_terminal_timeline_events_are_valid_durable_event_types():
assert DeepResearchEvent(type="job_completed", phase="done").type == "job_completed"
assert DeepResearchEvent(type="job_failed", phase="done").type == "job_failed"
def test_zero_source_fallback_is_a_valid_completed_report():
from app.gateway.deep_research_job_executor import _terminal_report_validation_error
from deerflow.agents.deep_research.runners.basic import _build_report_fallback
report = _build_report_fallback("没有命中的课题", "", 0)
assert _terminal_report_validation_error(report) is None
assert "没有命中的课题" in report
def test_source_table_reload_does_not_become_session_error():
from app.gateway.deep_research_job_executor import _session_diagnostic_error
assert _session_diagnostic_error(
[
{
"code": "client_materials_reloaded_before_write",
"stage": "collecting",
"detail": "写作前再次从素材表读到 15 条",
}
]
) is None
@@ -321,6 +321,39 @@ async def test_job_expired_lease_reclaimable():
await repos["_engine"].dispose()
@pytest.mark.asyncio
async def test_dispatcher_drops_expired_running_job_instead_of_reclaiming():
from app.gateway.deep_research_job_dispatcher import DeepResearchJobDispatcher
class _Executor:
def __init__(self) -> None:
self.started: list[str] = []
def start_job(self, snapshot: dict, *, job_id: str, lease_owner: str | None) -> bool: # noqa: ARG002
self.started.append(job_id)
return True
repos = await _make_repos()
try:
await repos["jobs"].try_create_or_get_active(
id="drj_1",
session_id="drs_1",
user_id="u1",
input_snapshot={"query": "测试报告"},
)
expired = datetime.now(UTC) - timedelta(seconds=10)
await repos["jobs"].claim_job("drj_1", lease_owner="w1", lease_until=expired)
dispatcher = DeepResearchJobDispatcher(repos["jobs"], _Executor(), worker_id="worker_2")
started = await dispatcher.dispatch_once()
assert started == 0
row = await repos["jobs"].get_unscoped("drj_1")
assert row["status"] == "cancelled"
finally:
await repos["_engine"].dispose()
# ── jobs: two-phase cancel ──────────────────────────────────────────────────
@@ -1,7 +1,8 @@
"""Regression coverage for idempotent Deep Research job submission."""
import json
from datetime import UTC, datetime
import os
from datetime import UTC, datetime, timedelta
from types import SimpleNamespace
import pytest
@@ -25,6 +26,9 @@ class _SessionStore:
async def count_active_by_user(self, *, user_id: str) -> int: # noqa: ARG002
return 0
async def list_by_user(self, *, user_id: str, status: str | None = None, limit: int = 20, **_: object): # noqa: ARG002
return []
async def update(self, session_id: str, *, user_id: str, **fields): # noqa: ARG002
self.updates.append(fields)
return {"id": session_id, **fields}
@@ -47,6 +51,9 @@ class _Dispatcher:
def nudge(self) -> None:
self.nudges += 1
def cancel_running(self, job_id: str) -> bool: # noqa: ARG002
return False
def _request(*, sessions, jobs, dispatcher, sources=None):
return SimpleNamespace(
@@ -84,9 +91,16 @@ async def test_retry_of_existing_queued_job_nudges_dispatcher(monkeypatch):
"sessionId": "drs_1",
"status": "queued",
"reused": True,
"collectorMaterialCount": 0,
"persistedSourceCount": 0,
"diagnostics": [],
}
assert dispatcher.nudges == 1
assert sessions.updates == [{"status": "running", "active_job_id": "drj_existing"}]
# Restarting clears any diagnostic left by the previous attempt, so the
# frontend does not append a stale error to a healthy new run.
assert sessions.updates == [
{"status": "running", "active_job_id": "drj_existing", "error": None}
]
@pytest.mark.asyncio
@@ -119,6 +133,7 @@ async def test_queued_job_still_starts_when_session_projection_temporarily_fails
assert response["jobId"] == "drj_new"
assert response["reused"] is False
assert dispatcher.nudges == 1
assert any(item["code"] == "session_projection_failed" for item in response["diagnostics"])
@pytest.mark.asyncio
@@ -581,3 +596,487 @@ async def test_report_generation_continues_when_first_segment_has_no_completion_
assert result == "# 新报告\n\n第一部分。\n\n## 第二部分\n\n续写完成。"
assert cited == []
assert usage["completion_tokens"] == 150
@pytest.mark.asyncio
async def test_write_report_treats_browser_materials_as_authoritative(monkeypatch):
"""POST /report must freeze the request body as the writing input."""
async def fake_require_user(request): # noqa: ANN001
return "u1"
class _CapturingJobStore(_JobStore):
def __init__(self) -> None:
self.created: dict | None = None
async def try_create_or_get_active(self, **kwargs): # noqa: ANN003
self.created = kwargs
return {"id": "drj_write", "status": "queued"}, True
class _SourceStore:
def __init__(self) -> None:
self.rows: list[dict] = []
async def upsert(self, **kwargs): # noqa: ANN003
self.rows.append(kwargs)
monkeypatch.setattr(deep_research, "_require_user", fake_require_user)
jobs = _CapturingJobStore()
sources = _SourceStore()
materials = [
{
"title": "来源甲",
"url": "https://a.test/1",
"raw_content": "正文甲",
"snippet": "摘要甲",
}
]
response = await deep_research.write_report(
"drs_1",
deep_research.WriteReportRequest(
query="前端课题",
title="前端标题",
config={"mode": "basic"},
collector_materials=materials,
),
_request(sessions=_SessionStore(), jobs=jobs, dispatcher=_Dispatcher(), sources=sources),
)
assert response["jobId"] == "drj_write"
assert response["collectorMaterialCount"] == 1
assert response["persistedSourceCount"] == 1
snapshot = jobs.created["input_snapshot"]
assert snapshot["entry"] == "chat"
assert snapshot["query"] == "前端课题"
assert snapshot["title"] == "前端标题"
assert snapshot["client_materials_authoritative"] is True
assert snapshot["collector_materials"] == materials
assert snapshot["collector_material_count"] == 1
assert sources.rows[0]["title"] == "来源甲"
assert sources.rows[0]["selected"] is True
assert response["diagnostics"] == []
@pytest.mark.asyncio
async def test_write_report_caps_job_snapshot_to_fallback_limit(monkeypatch):
"""The job snapshot only keeps 20 fallback rows even if the client sent more."""
async def fake_require_user(request): # noqa: ANN001
return "u1"
class _CapturingJobStore(_JobStore):
def __init__(self) -> None:
self.created: dict | None = None
async def try_create_or_get_active(self, **kwargs): # noqa: ANN003
self.created = kwargs
return {"id": "drj_cap", "status": "queued"}, True
class _SourceStore:
def __init__(self) -> None:
self.rows: list[dict] = []
async def upsert(self, **kwargs): # noqa: ANN003
self.rows.append(kwargs)
return kwargs
monkeypatch.setattr(deep_research, "_require_user", fake_require_user)
jobs = _CapturingJobStore()
sources = _SourceStore()
materials = [
{"title": f"来源{index}", "url": f"https://a.test/{index}", "raw_content": f"正文{index}"}
for index in range(25)
]
response = await deep_research.write_report(
"drs_1",
deep_research.WriteReportRequest(query="大量素材", collector_materials=materials),
_request(sessions=_SessionStore(), jobs=jobs, dispatcher=_Dispatcher(), sources=sources),
)
snapshot = jobs.created["input_snapshot"]
assert response["collectorMaterialCount"] == 25
assert response["persistedSourceCount"] == 25
assert len(snapshot["collector_materials"]) == 20
assert snapshot["collector_materials"][0]["title"] == "来源0"
assert snapshot["collector_materials"][-1]["title"] == "来源19"
@pytest.mark.asyncio
async def test_write_report_empty_materials_stays_authoritative(monkeypatch):
"""An empty browser list must freeze as the writing input, not trigger harvest."""
async def fake_require_user(request): # noqa: ANN001
return "u1"
class _CapturingJobStore(_JobStore):
def __init__(self) -> None:
self.created: dict | None = None
async def try_create_or_get_active(self, **kwargs): # noqa: ANN003
self.created = kwargs
return {"id": "drj_empty", "status": "queued"}, True
monkeypatch.setattr(deep_research, "_require_user", fake_require_user)
jobs = _CapturingJobStore()
response = await deep_research.write_report(
"drs_1",
deep_research.WriteReportRequest(query="空素材课题", collector_materials=[]),
_request(sessions=_SessionStore(), jobs=jobs, dispatcher=_Dispatcher()),
)
assert response["collectorMaterialCount"] == 0
assert response["persistedSourceCount"] == 0
snapshot = jobs.created["input_snapshot"]
assert snapshot["client_materials_authoritative"] is True
assert snapshot["collector_materials"] == []
assert snapshot["collector_material_count"] == 0
assert snapshot["query"] == "空素材课题"
assert any(item["code"] == "empty_client_materials" for item in response["diagnostics"])
@pytest.mark.asyncio
async def test_write_report_force_no_materials_ignores_browser_snapshot(monkeypatch):
"""The card checkbox must freeze an empty pool even if the browser still has hits."""
async def fake_require_user(request): # noqa: ANN001
return "u1"
class _CapturingJobStore(_JobStore):
def __init__(self) -> None:
self.created: dict | None = None
async def try_create_or_get_active(self, **kwargs): # noqa: ANN003
self.created = kwargs
return {"id": "drj_force_empty", "status": "queued"}, True
class _SourceStore:
def __init__(self) -> None:
self.rows: list[dict] = []
async def upsert(self, **kwargs): # noqa: ANN003
self.rows.append(kwargs)
return kwargs
monkeypatch.setattr(deep_research, "_require_user", fake_require_user)
jobs = _CapturingJobStore()
sources = _SourceStore()
response = await deep_research.write_report(
"drs_1",
deep_research.WriteReportRequest(
query="强制无素材",
collector_materials=[{"id": "src_keep", "title": "来源甲", "raw_content": "正文"}],
force_no_materials=True,
),
_request(sessions=_SessionStore(), jobs=jobs, dispatcher=_Dispatcher(), sources=sources),
)
assert response["collectorMaterialCount"] == 0
assert response["persistedSourceCount"] == 0
assert sources.rows == []
snapshot = jobs.created["input_snapshot"]
assert snapshot["force_no_materials"] is True
assert snapshot["client_materials_authoritative"] is True
assert snapshot["collector_materials"] == []
assert snapshot["collector_material_count"] == 0
assert any(item["code"] == "force_no_materials" for item in response["diagnostics"])
@pytest.mark.asyncio
async def test_update_session_persists_collector_materials(monkeypatch):
"""Collection-complete PATCH must copy browser materials into the source table."""
async def fake_require_user(request): # noqa: ANN001
return "u1"
class _SourceStore:
def __init__(self) -> None:
self.rows: list[dict] = []
async def upsert(self, **kwargs): # noqa: ANN003
self.rows.append(kwargs)
return kwargs
monkeypatch.setattr(deep_research, "_require_user", fake_require_user)
sessions = _SessionStore()
sources = _SourceStore()
response = await deep_research.update_session(
"drs_1",
deep_research.UpdateSessionRequest(
status="awaiting_report",
collector_materials=[
{"title": "来源甲", "url": "https://a.test/1", "raw_content": "正文甲"},
],
),
_request(sessions=sessions, jobs=_JobStore(), dispatcher=_Dispatcher(), sources=sources),
)
assert response.status == "awaiting_report"
assert response.source_count == 1
assert sources.rows[0]["title"] == "来源甲"
assert sources.rows[0]["selected"] is True
@pytest.mark.asyncio
async def test_update_session_persists_incremental_search_batches(monkeypatch):
"""Each search batch is upserted on its own PATCH, not held until the turn ends."""
async def fake_require_user(request): # noqa: ANN001
return "u1"
class _SourceStore:
def __init__(self) -> None:
self.rows: list[dict] = []
async def upsert(self, **kwargs): # noqa: ANN003
self.rows.append(kwargs)
return kwargs
monkeypatch.setattr(deep_research, "_require_user", fake_require_user)
sources = _SourceStore()
request = _request(sessions=_SessionStore(), jobs=_JobStore(), dispatcher=_Dispatcher(), sources=sources)
await deep_research.update_session(
"drs_1",
deep_research.UpdateSessionRequest(
collector_materials=[
{"title": "检索1-甲", "url": "https://a.test/1", "raw_content": "正文1"},
{"title": "检索1-乙", "url": "https://a.test/2", "raw_content": "正文2"},
],
),
request,
)
await deep_research.update_session(
"drs_1",
deep_research.UpdateSessionRequest(
collector_materials=[
{"title": "检索2-甲", "url": "https://b.test/1", "raw_content": "正文3"},
],
),
request,
)
assert [row["title"] for row in sources.rows] == ["检索1-甲", "检索1-乙", "检索2-甲"]
class _RepairSessionStore:
def __init__(self, row: dict) -> None:
self.row = row
self.updates: list[dict] = []
async def update(self, session_id: str, **fields): # noqa: ARG002
self.updates.append(fields)
self.row = {**self.row, **fields}
return self.row
class _RepairSourceStore:
def __init__(self, rows: list[dict] | None = None) -> None:
self.rows = rows or []
async def list_by_session(self, session_id, **kwargs): # noqa: ANN001, ARG002
return self.rows
def _repair_request(session_row: dict, sources: list[dict] | None = None):
sessions = _RepairSessionStore(session_row)
return _request(
sessions=sessions,
jobs=_JobStore(),
dispatcher=_Dispatcher(),
sources=_RepairSourceStore(sources),
), sessions
@pytest.mark.asyncio
async def test_session_read_repair_skips_running_job():
request, sessions = _repair_request(
{
"id": "drs_live",
"status": "running",
"active_job_id": "drj_live",
"query": "课题",
"report_markdown": "无法生成研究报告",
"error": None,
}
)
result = await deep_research._repair_invalid_persisted_report(
request,
sessions.row,
user_id="u1",
)
assert sessions.updates == []
assert result["status"] == "running"
assert result["active_job_id"] == "drj_live"
assert result["report_markdown"] == "无法生成研究报告"
assert result.get("error") is None
@pytest.mark.asyncio
async def test_session_read_repair_skips_completed_session_that_still_owns_a_job():
request, sessions = _repair_request(
{
"id": "drs_owned",
"status": "completed",
"active_job_id": "drj_still_writing",
"query": "课题",
"report_markdown": "无法生成研究报告",
"error": None,
}
)
result = await deep_research._repair_invalid_persisted_report(
request,
sessions.row,
user_id="u1",
)
assert sessions.updates == []
assert result["active_job_id"] == "drj_still_writing"
assert result["report_markdown"] == "无法生成研究报告"
@pytest.mark.asyncio
async def test_session_read_repair_replaces_refusal_without_marking_session_failed():
request, sessions = _repair_request(
{
"id": "drs_old",
"status": "completed",
"active_job_id": None,
"query": "课题",
"source_count": 0,
"report_markdown": "无法生成研究报告",
"error": "old",
}
)
result = await deep_research._repair_invalid_persisted_report(
request,
sessions.row,
user_id="u1",
)
assert sessions.updates
assert sessions.updates[0]["status"] == "completed"
assert sessions.updates[0]["error"] is None
assert "active_job_id" not in sessions.updates[0]
assert result["error"] is None
assert result["report_markdown"] != "无法生成研究报告"
assert "课题" in result["report_markdown"]
def test_job_is_stale_when_lease_owner_pid_is_dead() -> None:
now = datetime.now(UTC)
dead = {
"status": "running",
"cancel_requested": False,
"lease_owner": "w-999999-deadbeef",
"lease_until": now + timedelta(seconds=180),
}
live = {
"status": "running",
"cancel_requested": False,
"lease_owner": f"w-{os.getpid()}-alive000",
"lease_until": now + timedelta(seconds=180),
}
assert deep_research._job_is_stale(dead, now=now) is True
assert deep_research._job_is_stale(live, now=now) is False
assert deep_research._job_is_stale(
{**live, "cancel_requested": True},
now=now,
) is True
@pytest.mark.asyncio
async def test_start_job_releases_dead_worker_running_sessions(monkeypatch) -> None:
async def fake_require_user(request): # noqa: ANN001
return "u1"
now = datetime.now(UTC)
zombie = {
"id": "drs_dead",
"user_id": "u1",
"query": "旧课题",
"title": "旧课题",
"status": "running",
"active_job_id": "drj_dead",
"runtime_thread_id": "dr_t",
"config_snapshot": {"mode": "basic", "collection_mode": "chat"},
}
target = {
"id": "drs_1",
"user_id": "u1",
"query": "新课题",
"title": "新课题",
"status": "draft",
"config_snapshot": {"mode": "basic"},
}
class _Sessions:
def __init__(self) -> None:
self.rows = {"drs_dead": dict(zombie), "drs_1": dict(target)}
async def get(self, session_id: str, *, user_id: str): # noqa: ARG002
return self.rows.get(session_id)
async def list_by_user(self, *, user_id: str, status: str | None = None, limit: int = 20, **_: object): # noqa: ARG002
return [row for row in self.rows.values() if status is None or row.get("status") == status]
async def count_active_by_user(self, *, user_id: str) -> int: # noqa: ARG002
return sum(1 for row in self.rows.values() if row.get("status") in ("running", "awaiting_input"))
async def update(self, session_id: str, *, user_id: str, **fields): # noqa: ARG002
self.rows[session_id] = {**self.rows[session_id], **fields}
return self.rows[session_id]
class _Jobs:
def __init__(self) -> None:
self.jobs = {
"drj_dead": {
"id": "drj_dead",
"session_id": "drs_dead",
"status": "running",
"lease_owner": "w-999999-deadbeef",
"lease_until": now + timedelta(seconds=180),
"cancel_requested": False,
}
}
self.created = None
async def get(self, job_id: str, *, user_id: str | None = None): # noqa: ARG002
return self.jobs.get(job_id)
async def request_cancel(self, job_id: str, *, user_id: str | None = None): # noqa: ARG002
self.jobs[job_id] = {**self.jobs[job_id], "cancel_requested": True}
return self.jobs[job_id]
async def finalize_cancel(self, job_id: str, *, lease_owner: str | None = None): # noqa: ARG002
self.jobs[job_id] = {
**self.jobs[job_id],
"status": "cancelled",
"lease_owner": None,
"lease_until": None,
}
return self.jobs[job_id]
async def get_active_for_session(self, session_id: str, *, user_id: str): # noqa: ARG002
return None
async def try_create_or_get_active(self, **kwargs): # noqa: ANN003
self.created = kwargs
return {"id": "drj_new", "status": "queued"}, True
monkeypatch.setattr(deep_research, "_require_user", fake_require_user)
sessions = _Sessions()
jobs = _Jobs()
response = await deep_research.start_job(
"drs_1",
deep_research.StartJobRequest(entry="legacy"),
_request(sessions=sessions, jobs=jobs, dispatcher=_Dispatcher()),
)
assert response["jobId"] == "drj_new"
assert sessions.rows["drs_dead"]["status"] == "awaiting_report"
assert sessions.rows["drs_dead"]["active_job_id"] is None
assert jobs.jobs["drj_dead"]["status"] == "cancelled"