:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(signals): start implementation at report settle, not per research run (#83106)
Georgiy Tarasovae8c9e46efe5
diff --git a/posthog/temporal/tests/ai/test_module_integrity.py b/posthog/temporal/tests/ai/test_module_integrity.pyindex 7eb3d6ca1a9e..133708363fa5 100644--- a/posthog/temporal/tests/ai/test_module_integrity.py+++ b/posthog/temporal/tests/ai/test_module_integrity.py@@ -142,6 +142,9 @@ class TestSignalsProductModuleIntegrity:"mark_report_in_progress_activity","mark_report_pending_input_activity","mark_report_ready_activity",+ "maybe_autostart_implementation_activity",+ "implementation_buffer_seconds_activity",+ "report_is_candidate_activity","publish_report_completed_activity","report_has_assigned_signals_activity","revert_report_to_candidate_activity",diff --git a/products/signals/backend/temporal/__init__.py b/products/signals/backend/temporal/__init__.pyindex 34b8617bc26b..834d5e1c9172 100644--- a/products/signals/backend/temporal/__init__.py+++ b/products/signals/backend/temporal/__init__.py@@ -65,12 +65,15 @@ from products.signals.backend.temporal.summary import (SignalReportSummaryWorkflow,check_report_quota_gate_activity,dispatch_inbox_slack_notifications_activity,+ implementation_buffer_seconds_activity,mark_report_failed_activity,mark_report_in_progress_activity,mark_report_pending_input_activity,mark_report_ready_activity,+ maybe_autostart_implementation_activity,publish_report_completed_activity,report_has_assigned_signals_activity,+ report_is_candidate_activity,reset_report_to_potential_activity,revert_report_to_candidate_activity,)@@ -120,6 +123,9 @@ ACTIVITIES = [mark_report_in_progress_activity,mark_report_pending_input_activity,mark_report_ready_activity,+ maybe_autostart_implementation_activity,+ implementation_buffer_seconds_activity,+ report_is_candidate_activity,publish_report_completed_activity,report_has_assigned_signals_activity,revert_report_to_candidate_activity,diff --git a/products/signals/backend/temporal/agentic/report.py b/products/signals/backend/temporal/agentic/report.pyindex cf7637bfd33e..7401e0be57d3 100644--- a/products/signals/backend/temporal/agentic/report.py+++ b/products/signals/backend/temporal/agentic/report.py@@ -22,7 +22,7 @@ from posthog.temporal.oauth import McpScopePreset, grants_scratchpad_writefrom products.business_knowledge.backend.logic import is_available_for_teamfrom products.signals.backend.agent_runtime import STEP_RESEARCH, resolve_agent_runtimefrom products.signals.backend.artefact_schemas import ArtefactContent, RelatedTo, SuggestedReviewers-from products.signals.backend.auto_start import ReviewerContent, maybe_autostart_implementation_task+from products.signals.backend.auto_start import ReviewerContentfrom products.signals.backend.models import ArtefactAttribution, SignalReport, SignalReportArtefactfrom products.signals.backend.report_charts import ReportChart, chart_batch_errorfrom products.signals.backend.report_generation.research import (@@ -448,28 +448,10 @@ async def _persist_agentic_report_artefacts(await database_sync_to_async(tasks_facade.set_task_title, thread_sensitive=False)(result.research_task_id, team_id, f"Research: {result.title}")-- try:- await maybe_autostart_implementation_task(- team_id=team_id,- report_id=report_id,- repository=repo_selection.repository or "",- title=result.title,- summary=result.summary,- actionability=result.effective_actionability(),- priority=result.effective_priority(),- reviewers_content=reviewers_content,- repository_autostart_eligible=repo_selection.autostart_eligible,- )- except Exception as error:- posthoganalytics.capture_exception(error)- logger.exception(- "signals auto-start task failed",- report_id=report_id,- team_id=team_id,- repository=repo_selection.repository,- error=str(error),- )+ # Auto-start is not triggered here. The summary workflow starts implementation once the report+ # has settled (READY with no pending signals), so the task is scoped to the report's final+ # summary rather than whichever research pass finished first — see+ # `maybe_autostart_implementation_activity` in temporal/summary.py.def _team_has_business_knowledge(team_id: int) -> bool:diff --git a/products/signals/backend/temporal/grouping.py b/products/signals/backend/temporal/grouping.pyindex dea0c3042d6c..e56bc3af0985 100644--- a/products/signals/backend/temporal/grouping.py+++ b/products/signals/backend/temporal/grouping.py@@ -61,6 +61,7 @@ from products.signals.backend.temporal.signal_queries import ()from products.signals.backend.temporal.summary import SignalReportSummaryWorkflowfrom products.signals.backend.temporal.types import (+ IMPLEMENTATION_DEBOUNCE_SECONDS,RERESEARCH_MAX_SIGNALS,RESEARCH_DEBOUNCE_SECONDS,EmitSignalInputs,@@ -1400,7 +1401,13 @@ async def _process_signal_batch(task_queue=settings.VIDEO_EXPORT_TASK_QUEUE,parent_close_policy=ParentClosePolicy.ABANDON,id_reuse_policy=WorkflowIDReusePolicy.ALLOW_DUPLICATE,- execution_timeout=timedelta(hours=1, seconds=report_input.debounce_seconds),+ # The hour covers the research work; the two terms after it cover the workflow's own+ # sleeps, which the hour was never sized for — the research debounce at entry and the+ # implementation buffer at settle. A run that loops through several buffers can still+ # outlive this; it's a backstop, and the report stays READY and re-promotes.+ execution_timeout=timedelta(+ hours=1, seconds=report_input.debounce_seconds + IMPLEMENTATION_DEBOUNCE_SECONDS+ ),)except temporalio.exceptions.WorkflowAlreadyStartedError:metrics.increment_research_run_collapsed()diff --git a/products/signals/backend/temporal/summary.py b/products/signals/backend/temporal/summary.pyindex c347d44826a4..4533c2a5d6a5 100644--- a/products/signals/backend/temporal/summary.py+++ b/products/signals/backend/temporal/summary.py@@ -8,6 +8,7 @@ from typing import Anyfrom django.conf import settingsfrom django.db import transaction+from django.utils import timezoneimport structlogimport temporalio@@ -26,8 +27,9 @@ from posthog.sync import database_sync_to_asyncfrom posthog.temporal.common.scoped import scoped_temporalfrom posthog.temporal.common.utils import close_db_connections+from products.signals.backend.auto_start import maybe_autostart_from_report_artefactsfrom products.signals.backend.daily_limit import capture_signal_report_daily_limit_paused, daily_report_limit_gate-from products.signals.backend.models import SignalReport+from products.signals.backend.models import SignalReport, SignalTeamConfigfrom products.signals.backend.quota import (capture_signal_report_quota_paused,record_quota_check_failed_open,@@ -56,6 +58,8 @@ from products.signals.backend.temporal.signal_queries import (fetch_signals_for_report_activity,)from products.signals.backend.temporal.types import (+ IMPLEMENTATION_DEBOUNCE_SECONDS,+ NEW_SELF_DRIVING_GRACE,RERESEARCH_MAX_SIGNALS,SignalData,SignalReportSummaryWorkflowInputs,@@ -506,6 +510,47 @@ class SignalReportSummaryWorkflow:workflow.logger.exception(f"Failed to publish report_completed notification for {inputs.report_id}",)+ # Start implementation once the report has settled, after an optional buffer. A signal+ # landing just after the report went READY would otherwise ship a PR for a summary the+ # re-research is about to rewrite; waiting lets that signal fold into a re-research run.+ # Runs before the notification below on purpose: the notification decides whether to+ # wait for the implementation PR from the task existing on its first check, so it has+ # to find the task already created, and a buffer that ends in a re-research must not+ # announce the summary that re-research is about to replace.+ # The whole block is best-effort — the report is already READY, so a failure here must+ # not flip it to FAILED via the outer handler. patched(): in-flight histories predate it+ # and already auto-started from the research activity, so they skip this.+ if workflow.patched("signals-autostart-on-settle"):+ try:+ buffer_seconds = await workflow.execute_activity(+ implementation_buffer_seconds_activity,+ ImplementationBufferInput(team_id=inputs.team_id),+ start_to_close_timeout=timedelta(minutes=1),+ retry_policy=RetryPolicy(maximum_attempts=3),+ )+ if buffer_seconds > 0:+ await workflow.sleep(timedelta(seconds=buffer_seconds))+ # A signal arriving during the wait collapsed into this run and re-promoted+ # the report; loop to re-research it rather than implement a stale summary.+ became_candidate = await workflow.execute_activity(+ report_is_candidate_activity,+ ReportIsCandidateInput(team_id=inputs.team_id, report_id=inputs.report_id),+ start_to_close_timeout=timedelta(minutes=1),+ retry_policy=RetryPolicy(maximum_attempts=3),+ )+ if became_candidate:+ log.info("New signal arrived during implementation buffer, looping to re-research")+ return True+ await workflow.execute_activity(+ maybe_autostart_implementation_activity,+ MaybeAutostartImplementationInput(team_id=inputs.team_id, report_id=inputs.report_id),+ start_to_close_timeout=timedelta(minutes=5),+ retry_policy=RetryPolicy(maximum_attempts=3),+ )+ except Exception:+ workflow.logger.exception(+ f"Implementation buffer/auto-start failed for {inputs.report_id}",+ )# Slack notification is detached (ABANDON) so it can wait out the implementation PR.# patched(): summary workflows already in flight at deploy replay the prior inline path.try:@@ -794,6 +839,75 @@ async def mark_report_ready_activity(input: MarkReportReadyInput) -> bool:return has_new_signals+@frozen+class ImplementationBufferInput:+ team_id: int+++@scoped_temporal()+@close_db_connections+async def implementation_buffer_seconds_activity(input: ImplementationBufferInput) -> int:+ """Effective wait, in seconds, before a settled report starts its implementation task.++ 0 (no wait) when the buffer is disabled globally, or when the team is new to self-driving — a+ team whose signals config was created within NEW_SELF_DRIVING_GRACE implements without the extra+ delay while it's still evaluating the product. Otherwise IMPLEMENTATION_DEBOUNCE_SECONDS.+ """+ if IMPLEMENTATION_DEBOUNCE_SECONDS <= 0:+ return 0+ created_at = (+ await SignalTeamConfig.objects.filter(team_id=input.team_id).values_list("created_at", flat=True).afirst()+ )+ if created_at is not None and (timezone.now() - created_at) < NEW_SELF_DRIVING_GRACE:+ return 0+ return IMPLEMENTATION_DEBOUNCE_SECONDS+++@frozen+class ReportIsCandidateInput:+ team_id: int+ report_id: str+++@scoped_temporal()+@close_db_connections+async def report_is_candidate_activity(input: ReportIsCandidateInput) -> bool:+ """Whether the report is back in CANDIDATE.++ A signal landing during the implementation buffer collapses into this workflow's id and+ re-promotes the report, so a CANDIDATE status is the signal to re-research instead of+ implementing the now-stale summary.+ """+ status = (+ await SignalReport.objects.filter(id=input.report_id, team_id=input.team_id)+ .values_list("status", flat=True)+ .afirst()+ )+ return status == SignalReport.Status.CANDIDATE+++@frozen+class MaybeAutostartImplementationInput:+ team_id: int+ report_id: str+++@scoped_temporal()+@close_db_connections+async def maybe_autostart_implementation_activity(input: MaybeAutostartImplementationInput) -> None:+ """Evaluate self-driving auto-start from the report's current artefacts, once it has settled.++ Runs at the workflow's settle point (report READY, no pending signals) rather than per research+ run, so the implementation task is scoped to the report's final summary — not whichever research+ pass finished first. Idempotent: `maybe_autostart_from_report_artefacts` no-ops if an+ implementation task already exists for the report.+ """+ await maybe_autostart_from_report_artefacts(team_id=input.team_id, report_id=input.report_id)++@dataclassclass MarkReportFailedInput:team_id: intdiff --git a/products/signals/backend/temporal/types.py b/products/signals/backend/temporal/types.pyindex 301c831093d0..6e81262c4fdb 100644--- a/products/signals/backend/temporal/types.py+++ b/products/signals/backend/temporal/types.py@@ -1,6 +1,6 @@import osfrom dataclasses import dataclass, field-from datetime import datetime+from datetime import datetime, timedeltafrom typing import Any, Optional# Above this many assigned signals, an already-researched (READY/RESOLVED) report stops@@ -16,6 +16,20 @@ RERESEARCH_MAX_SIGNALS = int(os.getenv("SIGNAL_RERESEARCH_MAX_SIGNALS", "10"))# that run rather than forcing an immediate re-research. 0 disables the wait.RESEARCH_DEBOUNCE_SECONDS = int(os.getenv("SIGNAL_RESEARCH_DEBOUNCE_SECONDS", "0"))+# How long a report waits after research settles (READY, no pending signals) before its+# implementation task starts. A report re-promotes on every new signal, so a signal landing just+# after research finishes would otherwise ship a PR for a summary that's about to be rewritten by+# the re-research. The wait lets that late signal fold into a re-research run instead. The waiting+# run still owns the report's workflow ID, so a signal arriving during the wait collapses into it+# (see the WorkflowAlreadyStartedError handler in grouping) and re-promotes the report to CANDIDATE;+# the run then loops to re-research rather than implement. 0 disables the wait.+IMPLEMENTATION_DEBOUNCE_SECONDS = int(os.getenv("SIGNAL_IMPLEMENTATION_DEBOUNCE_SECONDS", "900"))++# Orgs new to self-driving skip the implementation buffer: a team whose signals config was created+# within this window implements without the extra wait, so the product feels responsive while+# they're still evaluating it. Measured against SignalTeamConfig.created_at.+NEW_SELF_DRIVING_GRACE = timedelta(hours=24)+@dataclassclass EmitSignalInputs:diff --git a/products/signals/backend/test/test_summary_settle_autostart.py b/products/signals/backend/test/test_summary_settle_autostart.pynew file mode 100644index 000000000000..022f646423d4--- /dev/null+++ b/products/signals/backend/test/test_summary_settle_autostart.py@@ -0,0 +1,295 @@+import uuid+import random+import asyncio+from datetime import UTC, datetime, timedelta++import pytest+from unittest.mock import patch++from django.conf import settings+from django.utils import timezone++import pytest_asyncio+from asgiref.sync import sync_to_async+from temporalio import activity, workflow+from temporalio.contrib.pydantic import pydantic_data_converter+from temporalio.testing import WorkflowEnvironment+from temporalio.worker import UnsandboxedWorkflowRunner, Worker++from posthog.models import Organization, Team++from products.signals.backend.models import SignalTeamConfig+from products.signals.backend.report_generation.research import ActionabilityChoice, Priority+from products.signals.backend.report_generation.select_repo import RepoSelectionResult+from products.signals.backend.temporal.agentic.report import RunAgenticReportInput, RunAgenticReportOutput+from products.signals.backend.temporal.agentic.select_repository import SelectRepositoryInput+from products.signals.backend.temporal.inbox_notification import (+ InboxNotificationInput,+ SignalReportInboxNotificationWorkflow,+)+from products.signals.backend.temporal.report_safety_judge import SafetyJudgeInput, SafetyJudgeOutput+from products.signals.backend.temporal.signal_queries import FetchSignalsForReportInput, FetchSignalsForReportOutput+from products.signals.backend.temporal.summary import (+ ImplementationBufferInput,+ MarkReportInProgressInput,+ MarkReportReadyInput,+ MaybeAutostartImplementationInput,+ PublishReportCompletedInput,+ ReportIsCandidateInput,+ SignalReportSummaryWorkflow,+ implementation_buffer_seconds_activity,+)+from products.signals.backend.temporal.types import SignalData, SignalReportSummaryWorkflowInputs++SUMMARY_MODULE_PATH = "products.signals.backend.temporal.summary"+# The settle branch starts the inbox-notification child on VIDEO_EXPORT_TASK_QUEUE; run the worker+# on that same queue so the stub child completes. Otherwise the child stays pending on an unpolled+# queue and the test server's automatic time-skipping never advances past the buffer timer.+TASK_QUEUE = settings.VIDEO_EXPORT_TASK_QUEUE+++@pytest_asyncio.fixture+async def aorganization():+ organization = await sync_to_async(Organization.objects.create)(+ name=f"SettleAutostartOrg-{random.randint(1, 99999)}",+ )+ yield organization+ await sync_to_async(organization.delete)()+++@pytest_asyncio.fixture+async def ateam(aorganization):+ team = await sync_to_async(Team.objects.create)(+ organization=aorganization,+ name=f"SettleAutostartTeam-{random.randint(1, 99999)}",+ )+ yield team+ await sync_to_async(team.delete)()+++# ---------------------------------------------------------------------------+# implementation_buffer_seconds_activity: the 24h new-self-driving carve-out+# ---------------------------------------------------------------------------+++async def _set_config_created_at(team_id: int, created_at: datetime) -> None:+ # created_at is auto_now_add, so it can't be set on create — update it directly.+ await SignalTeamConfig.objects.filter(team_id=team_id).aupdate(created_at=created_at)+++ "name,configured_seconds,config_age,expected",+ [+ # Buffer disabled globally: no wait for anyone, regardless of org age.+ ("disabled", 0, timedelta(days=30), 0),+ # Org new to self-driving (config younger than the 24h grace): no wait.+ ("new_org", 120, timedelta(hours=1), 0),+ # Established org (config older than the grace): the configured buffer applies.+ ("established_org", 120, timedelta(days=2), 120),+ ],+)+async def test_implementation_buffer_carve_out(ateam, name, configured_seconds, config_age, expected):+ # SignalTeamConfig is auto-created with the team (post_save signal); age it to exercise the carve-out.+ await _set_config_created_at(ateam.id, timezone.now() - config_age)++ with patch(f"{SUMMARY_MODULE_PATH}.IMPLEMENTATION_DEBOUNCE_SECONDS", configured_seconds):+ result = await implementation_buffer_seconds_activity(ImplementationBufferInput(team_id=ateam.id))++ assert result == expected+++async def test_implementation_buffer_applies_when_no_config_row(ateam):+ # A team with no signals config row is not "new to self-driving", so the buffer still applies.+ await SignalTeamConfig.objects.filter(team_id=ateam.id).adelete()++ with patch(f"{SUMMARY_MODULE_PATH}.IMPLEMENTATION_DEBOUNCE_SECONDS", 120):+ result = await implementation_buffer_seconds_activity(ImplementationBufferInput(team_id=ateam.id))++ assert result == 120+++# ---------------------------------------------------------------------------+# Workflow: implementation starts at settle, after the buffer, and re-loops+# instead of implementing a stale summary when a signal lands during the wait.+# ---------------------------------------------------------------------------+++class _Recorder:+ def __init__(self, buffer_seconds: int, candidate_on_first_check: bool) -> None:+ self.buffer_seconds = buffer_seconds+ self.candidate_on_first_check = candidate_on_first_check+ self.researches = 0+ self.autostarts = 0+ self.candidate_checks = 0+ # Auto-starts completed by the time the notification child made its first state check. The+ # child only waits for the implementation PR if the task already exists then, so a 0 here+ # means the card ships without the PR link.+ self.autostarts_at_notification: list[int] = []+++def _signal_data() -> SignalData:+ return SignalData(+ signal_id=str(uuid.uuid4()),+ content="something happened",+ source_product="error_tracking",+ source_type="issue",+ source_id=str(uuid.uuid4()),+ weight=1.0,+ timestamp=datetime(2026, 1, 1, tzinfo=UTC),+ )+++# The deferred-notification branch starts this child workflow by name; a stub stands in for it so+# the child can start without wiring its activities. The one activity it does run mirrors the real+# child's first state check, which is what decides whether it waits for the implementation PR.[email protected](name="signal-report-inbox-notification")+class _StubInboxNotificationWorkflow:+ @workflow.run+ async def run(self, input: InboxNotificationInput) -> None:+ await workflow.execute_activity(+ "record_notification_check_activity",+ input,+ start_to_close_timeout=timedelta(seconds=10),+ )+++async def _run_summary_workflow(recorder: _Recorder) -> None:+ @activity.defn(name="check_report_quota_gate_activity")+ async def fake_quota(input) -> bool:+ return False++ @activity.defn(name="fetch_signals_for_report_activity")+ async def fake_fetch(input: FetchSignalsForReportInput) -> FetchSignalsForReportOutput:+ return FetchSignalsForReportOutput(signals=[_signal_data()])++ @activity.defn(name="mark_report_in_progress_activity")+ async def fake_mark_in_progress(input: MarkReportInProgressInput) -> None:+ return None++ @activity.defn(name="report_safety_judge_activity")+ async def fake_safety(input: SafetyJudgeInput) -> SafetyJudgeOutput:+ return SafetyJudgeOutput(safe=True, explanation="ok")++ @activity.defn(name="select_repository_activity")+ async def fake_select_repo(input: SelectRepositoryInput) -> RepoSelectionResult:+ return RepoSelectionResult(repository="owner/repo", reason="selected")++ @activity.defn(name="run_agentic_report_activity")+ async def fake_research(input: RunAgenticReportInput) -> RunAgenticReportOutput:+ recorder.researches += 1+ return RunAgenticReportOutput(+ title="t",+ summary="s",+ choice=ActionabilityChoice.IMMEDIATELY_ACTIONABLE,+ priority=Priority.P1,+ explanation="e",+ already_addressed=False,+ repository="owner/repo",+ )++ @activity.defn(name="mark_report_ready_activity")+ async def fake_mark_ready(input: MarkReportReadyInput) -> bool:+ # No new signals arrived during the run itself; the buffer is what catches late signals.+ return False++ @activity.defn(name="publish_report_completed_activity")+ async def fake_publish(input: PublishReportCompletedInput) -> None:+ return None++ @activity.defn(name="implementation_buffer_seconds_activity")+ async def fake_buffer(input: ImplementationBufferInput) -> int:+ return recorder.buffer_seconds++ @activity.defn(name="report_is_candidate_activity")+ async def fake_candidate(input: ReportIsCandidateInput) -> bool:+ recorder.candidate_checks += 1+ return recorder.candidate_on_first_check and recorder.candidate_checks == 1++ @activity.defn(name="maybe_autostart_implementation_activity")+ async def fake_autostart(input: MaybeAutostartImplementationInput) -> None:+ recorder.autostarts += 1++ @activity.defn(name="record_notification_check_activity")+ async def fake_notification_check(input: InboxNotificationInput) -> None:+ recorder.autostarts_at_notification.append(recorder.autostarts)++ report_id = str(uuid.uuid4())++ async with await WorkflowEnvironment.start_time_skipping(data_converter=pydantic_data_converter) as env:+ async with Worker(+ env.client,+ task_queue=TASK_QUEUE,+ workflows=[SignalReportSummaryWorkflow, _StubInboxNotificationWorkflow],+ activities=[+ fake_quota,+ fake_fetch,+ fake_mark_in_progress,+ fake_safety,+ fake_select_repo,+ fake_research,+ fake_mark_ready,+ fake_publish,+ fake_buffer,+ fake_candidate,+ fake_autostart,+ fake_notification_check,+ ],+ workflow_runner=UnsandboxedWorkflowRunner(),+ ):+ await asyncio.wait_for(+ env.client.execute_workflow(+ SignalReportSummaryWorkflow.run,+ SignalReportSummaryWorkflowInputs(team_id=1, report_id=report_id),+ id=f"summary-settle-{uuid.uuid4()}",+ task_queue=TASK_QUEUE,+ ),+ timeout=30,+ )+ # The notification child is detached (ABANDON), so it can outlive the parent; wait for+ # it before asserting on what it saw.+ await asyncio.wait_for(+ env.client.get_workflow_handle(+ SignalReportInboxNotificationWorkflow.workflow_id_for(1, report_id)+ ).result(),+ timeout=30,+ )+++async def test_no_buffer_autostarts_immediately_at_settle():+ recorder = _Recorder(buffer_seconds=0, candidate_on_first_check=False)+ await _run_summary_workflow(recorder)+ # With the buffer disabled, implementation starts right at settle: no candidate re-check, one run.+ assert recorder.researches == 1+ assert recorder.candidate_checks == 0+ assert recorder.autostarts == 1+ # The task exists before the notification looks, so its card can wait for the PR.+ assert recorder.autostarts_at_notification == [1]+++async def test_buffer_autostarts_when_no_signal_arrives():+ recorder = _Recorder(buffer_seconds=120, candidate_on_first_check=False)+ await _run_summary_workflow(recorder)+ # The buffer elapses, the report is still settled (not candidate), so implementation starts once.+ assert recorder.researches == 1+ assert recorder.candidate_checks == 1+ assert recorder.autostarts == 1+ assert recorder.autostarts_at_notification == [1]+++async def test_signal_during_buffer_re_researches_instead_of_implementing():+ recorder = _Recorder(buffer_seconds=120, candidate_on_first_check=True)+ await _run_summary_workflow(recorder)+ # A signal landed during the buffer (report back to candidate), so the run loops to re-research+ # rather than implementing the now-stale summary; implementation only starts after it settles again.+ assert recorder.researches == 2+ assert recorder.candidate_checks == 2+ assert recorder.autostarts == 1+ # Only the settled run notifies, so no card goes out for the summary the re-research replaced.+ assert recorder.autostarts_at_notification == [1]