The platform for continuously improving AI agents.
from datetime import timedelta
import pytest
from django.utils import timezone
from test_research_experiments import setup_experiment
from overbae.models import ResearchAssignment
from overbae.services import research_experiments, research_memory
pytestmark = [pytest.mark.django_db, pytest.mark.covers("privacy")]
@pytest.mark.parametrize("infrastructure_failure", [False, True])
def test_recall_retains_failed_attempts_without_crossing_projects(infrastructure_failure):
experiment, user, _ = setup_experiment()
work = research_experiments.start(
experiment, user, revision=1, request_key="current", budget={}, instructions="Investigate"
)
other_experiment, other_user, _ = setup_experiment()
other = research_experiments.start(
other_experiment,
other_user,
revision=1,
request_key="other",
budget={},
instructions="Investigate",
)
# A matching resource string cannot grant access to another project's history.
other.context.roots = work.context.roots
other.context.save(update_fields=["roots"])
other.state = "completed"
other.completed_at = timezone.now()
other.result = {"summary": "Private other-project result"}
other.save(update_fields=["state", "completed_at", "result"])
previous = ResearchAssignment.objects.create(
project=work.project,
created_by=user,
context=work.context,
experiment_revision=work.experiment_revision,
request_key="prior-failure",
fingerprint="prior",
specification={"objective": "Earlier objective"},
state="blocked",
deadline=work.deadline,
completed_at=None if infrastructure_failure else timezone.now() - timedelta(minutes=5),
result={
"reason": "orchestration_failed",
"error": "The run stopped after repeated internal errors.",
}
if infrastructure_failure
else {"summary": "The selected runtime was unavailable", "limitations": ["x" * 5000]},
)
memory = research_memory.recall(work.agents.get(parent__isnull=True))
assert [item["assignment"] for item in memory["attempts"]] == [str(previous.pk)]
assert memory["attempts"][0]["state"] == "blocked"
assert memory["attempts"][0]["report"]
assert len(str(memory)) < 8000
if infrastructure_failure:
assert memory["attempts"][0]["completed_at"] is None
assert memory["attempts"][0]["reason"] == "orchestration_failed"
assert memory["attempts"][0]["revision"] == str(previous.experiment_revision_id)
assert memory["authority"] == "historical_reports"