Skip to content

API Reference parrot_tools.contracts.jobs

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.contracts.jobs

View source

Scheduler-free contracts watcher jobs (FEAT-539 M11).

Three plain async callables. They import no scheduler and send nothing: the deploying agent decides when to run them (@schedule) and what to do with the result (send_result). Every dependency — library, delta tool, publishers, clock, service principal and recipient scope — is injected.

ingest_delta is the one with teeth. Its cursor rule is the whole point: the committed delta link only advances once every item in the batch is durably processed or explicitly recorded as skipped, so an interrupted run replays idempotently instead of losing changes.

A 410 means the cursor is dead, never that everything was deleted. The job recovers by re-enumerating the drive in full — retaining the dead cursor would stall the source forever, since every later run would hit the same 410. Because a deletion that happened while the cursor was expired appears in no page, a recovered rescan is then reconciled against local state.

That reconciliation is the one destructive path here, so it is deliberately timid. It withdraws a contract only when absence really is evidence: a complete whole-drive rescan of the same drive, with its final cursor, no item errors, and no other live file still backing the card. A folder-scoped rescan cannot prove absence at all — it only ever sees part of the drive — so its missing items are reported in suspected_deletions for an operator rather than acted on.

Class DeltaEnumerationError

The delta tool could not be driven, or reported a failure.

Class DeltaIngestResult

What one ingest_delta run did.

rescan_required means the committed cursor is dead and could not be recovered — nothing was processed and the cursor is retained. rescan_performed means a full re-enumeration was attempted after a cursor expiry. It does not by itself mean reconciliation ran — that is separately gated on the rescan being complete, cursor-bearing, error-free and whole-drive. Read reconciled (contracts retracted because they were absent) and suspected_deletions to know what actually happened.

suspected_deletions lists source items missing from a rescan that were not retracted because absence did not prove deletion — a folder-scoped rescan only ever sees part of the drive. Those need an operator's eye, not an automatic withdrawal.

Fields:

Field Type Default Description
source str
report IngestReport
cursor_committed Optional[str] None
cursor_retained Optional[str] None
rescan_required bool False
rescan_performed bool False
reconciled list[str]
suspected_deletions list[str]
tombstoned list[str]
errors list[str]

Attributes:

Attribute Type Description
durable bool Whether every item was durably processed or explicitly skipped.

Class ObligationsDigest

Deterministic obligations digest output.

Fields:

Field Type Default Description
today date
until date
due list[dict[str, Any]]
recurring list[dict[str, Any]]
needs_review list[dict[str, Any]]
prose Optional[dict[str, Any]] None

Attribute RECOGNISED_RECURRENCE

Type: dict[str, int]

Attribute RENEWAL_BUCKETS

Type: tuple[tuple[str, int, int], ...]

Class RenewalBucket

One non-overlapping renewal window.

Fields:

Field Type Default Description
label str
start date
end date
contracts list[dict[str, Any]]

Class RenewalsReport

Deterministic renewals radar output.

Fields:

Field Type Default Description
today date
key str 'notice_deadline'
buckets list[RenewalBucket]
prose Optional[dict[str, Any]] None

Attributes:

Attribute Type Description
total int How many contracts the report covers.

Class SourceConfig

One configured document source to enumerate.

Fields:

Field Type Default Description
source str
drive_id str
folder_path Optional[str] None
folder_id Optional[str] None
download bool True

Function ingest_delta

Ingest changes from one configured source.

ingest_delta(*, library: Any, delta_tool: Any, source: SourceConfig, principal: RequestContext, retrieval: Any = None, graph_loader: Any = None, temporal: Any = None, tenant_context: Any = None, downloader: Any = None, now: Any = None) -> DeltaIngestResult

Parameter Type Default Description
library Any The :class:ContractLibrary doing the carding.
delta_tool Any A delta tool exposing _execute_graph_operation(client, **kwargs) or an enumerate-shaped helper.
source SourceConfig The configured source scope (drive/folder/cursor key).
principal RequestContext The trusted service principal this job runs as.
retrieval Any None Retrieval supplying the authorization gate. When it is omitted the gate is built from library.catalog — the principal is always authorized, never implicitly trusted.
graph_loader Any None Optional loader used to retract tombstoned contracts.
temporal Any None Optional temporal publisher to drain afterwards.
tenant_context Any None Tenant context for the temporal drain.
downloader Any None async (item) -> Path | None supplying local bytes.
now Any None Injectable clock.

Returns: DeltaIngestResult — class:DeltaIngestResult. The cursor is committed only when every item was durably processed or explicitly skipped.

Function obligations_digest

Digest obligations coming due in a window.

Fixed due dates inside the window are reported as due; recognised anchored recurrences are reported as recurring; anything with an unrecognised or unanchored recurrence is surfaced under needs_review rather than interpreted by a model.

obligations_digest(*, retrieval: Any, principal: RequestContext, today: Optional[date] = None, days: int = 7, kinds: Optional[Sequence[str]] = None, flow: Any = None, prose_question: Optional[str] = None) -> ObligationsDigest

Parameter Type Default Description
retrieval Any The authorized retrieval layer.
principal RequestContext The trusted service principal.
today Optional[date] None Injected current date.
days int 7 Window length (defaults to the weekly cadence).
kinds Optional[Sequence[str]] None Restrict to these obligation kinds.
flow Any None Optional fixed answer flow for the prose paragraph.
prose_question Optional[str] None The question that prose would answer.

Returns: ObligationsDigest — class:ObligationsDigest. Nothing is ever sent.

Function renewals_report

Bucket upcoming renewals into 30/60/90-day windows.

Buckets are inclusive and non-overlapping (0-30, 31-60, 61-90), the driving date is the notice deadline with an expiration fallback, and contracts with no date at all are omitted. Deterministic and SQL-only: no ArangoDB, no LLM.

renewals_report(*, retrieval: Any, principal: RequestContext, today: Optional[date] = None, key: str = 'notice_deadline', flow: Any = None, prose_question: Optional[str] = None) -> RenewalsReport

Parameter Type Default Description
retrieval Any The authorized retrieval layer.
principal RequestContext The trusted service principal.
today Optional[date] None Injected current date.
key str 'notice_deadline' notice_deadline (default) or expiration_date.
flow Any None Optional fixed answer flow for the prose paragraph.
prose_question Optional[str] None The question that prose would answer.

Returns: RenewalsReport — class:RenewalsReport; prose is present only when a flow was supplied. Nothing is ever sent.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally