Delivery and shutdown checks
Flush buffered work and inspect delivery before shutdown.
Check delivery while the session is open
Use these checks during service shutdown or when an expected Event is missing. When a managed call opens a temporary session, the SDK closes it after the call.
status = agent.delivery_status()
print({
"pending_records": status.pending_records,
"failed_records": status.failed_records,
"dropped_records": status.dropped_records,
"last_error_code": status.last_error_code,
"catalog_delivery_state": status.catalog_delivery_state,
})
print("publication_complete:", agent.catalog_snapshot().publication_complete){"pending_records": 0, "failed_records": 0, "dropped_records": 0,
"last_error_code": None, "catalog_delivery_state": "acknowledged"}
publication_complete: True| Signal | Next action |
|---|---|
| pending_records > 0 | Delivery has not settled. While the session is open, flush within a bounded timeout and inspect again. |
| failed_records or dropped_records > 0 | Delivery was not complete. Retain correlation IDs and the safe last_error_code; investigate without repeating the tool action. |
| publication_complete is false | Inspect catalog_status() for pending, partial or failed publication. Reconcile tool registration before another governed test. |
| Catalog is empty | An empty supported tool set needs no registration request. Confirm that this matches your application. |
| Counts settled and publication acknowledged | Open the Run in the Console and check for the expected Event. If the tool’s outcome is uncertain, check its own record before retrying. |
Flush pending records
Inside an entered Sync session, use status = agent.flush(timeout=10.0). Inside an entered Async session, use status = await agent.aflush(timeout=10.0). Choose a timeout that fits your shutdown budget, then inspect the returned counts.
Flush waits for queued delivery, not a running invocation. It does not guarantee that every item was acknowledged. After an automatic session closes, flush returns retained diagnostics rather than reopening delivery. Ordinary calls already settle their sessions; do not add flush after every call.
Verify shutdown and delivery
Keep the Run ID and the reported error code when investigating missing Events.
- Stop accepting new application requests and close abandoned streams.
- If records are pending, flush within your shutdown timeout. Then leave the managed context so accepted work settles.
- Inspect the retained delivery counts and catalog acknowledgment. Record unresolved delivery failures without rerunning an effect.
- Close application-owned models, backends and savers after agent cleanup finishes. If close or aclose raises
CleanupIncompleteError, keep those resources alive and retry cleanup once accepted work settles.