Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies = [
"structlog>=23.0.0",
"google-auth>=2.0.0",
"google-genai>=2.10.0",
"openai>=1.0.0",
"python-dotenv>=1.0.0",
"pydantic-settings>=2.0.0",
"opencv-python>=4.13.0.92",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ structlog>=23.0.0
google-auth>=2.0.0
python-dotenv>=1.0.0
google-genai>=2.10.0
openai>=1.0.0
google-cloud-storage>=2.0.0
google-cloud-documentai>=2.20.0
types-PyYAML>=6.0.12.20250915
Expand Down
114 changes: 91 additions & 23 deletions src/fathom/adapters/interaction/noop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from contextlib import asynccontextmanager
from typing import AsyncGenerator, List, Optional
from typing import AsyncGenerator, Dict, List, Optional

from fathom.constants.collaboration import (
IdempotencyState,
Expand Down Expand Up @@ -89,6 +89,14 @@ class NoopInteraction(InteractionPort):
absorbs without crashing the run. Reads return None or empty collections.
"""

def __init__(self) -> None:
"""Initialize ephemeral task state for the current local run."""

self.__executions: Dict[str, Execution] = {}
self.__idempotency: Dict[str, Idempotency] = {}
self.__jobs: Dict[str, Job] = {}
self.__tasks: Dict[str, Task] = {}

async def initialize(self) -> None:
"""
Realize adapter state. Noop adapter holds no schema or pool.
Expand Down Expand Up @@ -168,7 +176,7 @@ async def open_task(self, *, request: OpenTask) -> Task:
Echo a Task shaped from the request without persisting.
"""

return Task(
task = Task(
kind=request.kind,
plan=request.plan,
state=request.state,
Expand All @@ -180,13 +188,15 @@ async def open_task(self, *, request: OpenTask) -> Task:
assignment=request.assignment,
timing=Timing(created_at=request.created, updated_at=request.created),
)
self.__tasks[task.identity.id] = task
return task

async def start_execution(self, *, request: StartExecution) -> Execution:
"""
Echo an Execution shaped from the request without persisting.
"""

return Execution(
execution = Execution(
outcome=Metadata(),
state=request.state,
thread=request.thread,
Expand All @@ -199,15 +209,33 @@ async def start_execution(self, *, request: StartExecution) -> Execution:
started_at=request.started,
),
)
self.__executions[execution.identity.id] = execution
return execution

async def finish_execution(self, *, request: FinishExecution) -> Execution:
"""
Finishing an execution requires prior state; not supported without storage.
"""

_ = request

raise InteractionError("Finish execution requires durable storage; noop is not supported")
Finish an ephemeral execution so local runs can terminate cleanly.
"""

execution = self.__executions.get(request.execution)
if execution is None:
raise InteractionError(
f"Execution {request.execution} was not opened in this noop session"
)

finished = execution.model_copy(
update={
"state": request.state,
"terminal": request.terminal,
"summary": request.summary,
"outcome": request.outcome,
"timing": execution.timing.model_copy(
update={"updated_at": request.completed, "ended_at": request.completed}
),
}
)
self.__executions[request.execution] = finished
return finished

async def get_execution(self, *, query: ExecutionQuery) -> Optional[Execution]:
"""
Expand Down Expand Up @@ -248,12 +276,29 @@ async def sanitize_message(self, *, request: Sanitize) -> Message:

async def finish_task(self, *, request: FinishTask) -> Task:
"""
Finishing requires the prior task; not supported without state.
"""

_ = request

raise InteractionError("Finish task requires durable storage; noop is not supported")
Finish an ephemeral task so local runs can terminate cleanly.
"""

task = self.__tasks.get(request.task)
if task is None:
raise InteractionError(f"Task {request.task} was not opened in this noop session")

finished = task.model_copy(
update={
"state": request.state,
"terminal": request.terminal,
"summary": request.summary,
"timing": task.timing.model_copy(
update={
"updated_at": request.ended,
"ended_at": request.ended,
"elapsed": request.elapsed,
}
),
}
)
self.__tasks[request.task] = finished
return finished

async def get_thread(self, *, query: ThreadQuery) -> Optional[Thread]:
"""
Expand Down Expand Up @@ -509,7 +554,7 @@ async def schedule_job(self, *, request: ScheduleJob) -> Job:
Echo a pending Job shaped from the request without persisting.
"""

return Job(
job = Job(
attempts=0,
task=request.task,
kind=request.kind,
Expand All @@ -521,6 +566,8 @@ async def schedule_job(self, *, request: ScheduleJob) -> Job:
available_at=request.available,
timing=Timing(created_at=request.created, updated_at=request.created),
)
self.__jobs[job.identity.id] = job
return job

async def claim_job(self, *, request: ClaimJob) -> Optional[Job]:
"""
Expand All @@ -533,12 +580,25 @@ async def claim_job(self, *, request: ClaimJob) -> Optional[Job]:

async def finish_job(self, *, request: FinishJob) -> Job:
"""
Finishing requires the prior job; not supported without state.
Finish an ephemeral job so local runs can terminate cleanly.
"""

_ = request
job = self.__jobs.get(request.job)
if job is None:
raise InteractionError(f"Job {request.job} was not scheduled in this noop session")

raise InteractionError("Finish job requires durable storage; noop is not supported")
finished = job.model_copy(
update={
"state": request.state,
"owner": request.owner,
"outcome": request.outcome,
"timing": job.timing.model_copy(
update={"updated_at": request.finished, "ended_at": request.finished}
),
}
)
self.__jobs[request.job] = finished
return finished

async def recover_jobs(self, *, request: RecoverJob) -> List[Job]:
"""
Expand Down Expand Up @@ -572,7 +632,7 @@ async def begin_request(self, *, request: BeginRequest) -> Idempotency:
Echo an active Idempotency record without persisting.
"""

return Idempotency(
record = Idempotency(
key=request.key,
hash=request.hash,
tenant=request.tenant,
Expand All @@ -581,15 +641,23 @@ async def begin_request(self, *, request: BeginRequest) -> Idempotency:
metadata=request.metadata,
state=IdempotencyState.STARTED,
)
self.__idempotency[request.key] = record
return record

async def finish_request(self, *, request: FinishRequest) -> Idempotency:
"""
Finishing requires the prior idempotency record; not supported.
Finish an ephemeral idempotency record so local runs can terminate cleanly.
"""

_ = request
record = self.__idempotency.get(request.key)
if record is None:
raise InteractionError(
f"Idempotency key {request.key} was not started in this noop session"
)

raise InteractionError("Finish request requires durable storage; noop is not supported")
finished = record.model_copy(update={"state": request.state, "response": request.response})
self.__idempotency[request.key] = finished
return finished

async def get_idempotency(self, *, query: IdempotencyQuery) -> Optional[Idempotency]:
"""
Expand Down
Loading
Loading