Python results and events
Typed operations return results and can deliver events as work progresses. Use this reference to interpret those objects and handle failures. See the operations reference for calling conventions, or streams and mappings for their completion rules.
Operation results
cp and rm return a frozen dataclass once syq has exited and its results
stream has been checked; a stream cut short raises even if syq exits
successfully. A dry run returns the same type with planned totals, and a failed
call counts the work done before it stopped.
CpResult
Returned by cp(), and available as SyqOperationError.result after an
unsuccessful copy. Besides the common result fields below, it has:
| Attribute | Type | Meaning |
|---|---|---|
files_transferred | int | Regular files transferred |
files_unchanged | int | Regular files skipped as unchanged |
files_excluded | int | Source entries excluded from copying, including ignore matches; an ignored directory counts once |
directories_created | int | Directories created |
symlinks_created | int | Symbolic links created |
specials_created | int | Special filesystem objects created |
bytes_transferred | int | File-content bytes transferred, not compressed network traffic |
bytes_total_known | bool | None | For byte streams, whether the source length is known; otherwise None |
bytes_unchanged | int | Bytes not copied because the destination already had them: unchanged files and data reused inside transferred files |
deletions_planned | int or None | Entries selected for pruning; None without prune or prune_before |
deletions_completed | int or None | Entries pruned; None without pruning |
deletions_blocked | int or None | Deletions blocked by a safety limit; None without pruning |
replaced_not_in_place | dict[str, int] or None | With in_place="update", existing files replaced instead of updated in place, by reason |
RmResult
Returned by rm(), and available as SyqOperationError.result after an
unsuccessful removal. Besides the common result fields below, it has:
| Attribute | Type | Meaning |
|---|---|---|
selectors_total | int | Explicit source selectors supplied |
selectors_resolved | int | Selectors that resolved to an object |
selectors_missing | int | Selectors already missing; this is not an error |
entries_planned | int | Entries a dry run would remove; zero in live runs |
entries_removed | int | Entries removed; zero in dry runs |
entries_already_absent | int | Entries gone by removal time; zero in dry runs |
entries_failed | int | Removal or inspection failures, including during dry runs |
mode | str | Always "rm" |
A selector is one path you asked to remove, and an entry is one object that removal visits, so a directory selector can account for many entries.
Common result fields
Both CpResult and RmResult include:
| Attribute | Type | Meaning |
|---|---|---|
status | OperationStatus | Outcome from the table below |
exit_code | int | syq process exit code |
dry_run | bool | Whether this was a preview |
errors | int | Counted errors |
timings | Timings | Time spent in each phase, in milliseconds |
protocol | ProtocolMetadata | Automation envelope; also present on every event |
Timings
To see where a run spent its time, read result.timings, or event.timings
on progress events. Values are wall-clock milliseconds. They overlap, so do not
add them together. None means syq does not measure that phase for this
operation; zero means there was no such work, or it took under a millisecond.
See measurement boundaries.
| Attribute | Type | Meaning |
|---|---|---|
total_ms | int | The whole measured run, including installing syq on servers |
setup_ms | int | None | Preparing and connecting to the source and destination, excluding installation |
planning_ms | int | None | Finding source entries, checking destinations, and deciding what to copy |
transfer_ms | int | None | From the first file operation to the last |
finalization_ms | int | None | Work after file copying ends, such as pruning and directory metadata |
helper_install_ms | int | None | Installing syq on servers |
ProtocolMetadata
Frozen dataclass at result.protocol and event.protocol. The SDK checks
these fields; you need them only to record or diagnose a results stream.
| Attribute | Type | Meaning |
|---|---|---|
schema | str | "syq.automation" |
schema_version | int | 4; callback mappings use 5 |
seq | int | Record sequence number, starting at zero |
type | str | Record type; "result" for the final totals |
OperationStatus
String enum: compare with syq.OperationStatus.SUCCESS, or use .value for
"success".
| Member | Value | Exit code | Meaning |
|---|---|---|---|
SUCCESS | "success" | 0 | Requested operation succeeded |
PARTIAL | "partial" | 23 | Some entries failed; the rest of the work finished |
REFUSED | "refused" | 25 | A safety limit such as max_delete refused the deletions; cp only |
ABORTED | "aborted" | 1 | The copy stopped partway, for example when the destination filled up; cp only |
FAILED | "failed" | 1 | Fatal failure |
Event callbacks
on_event receives each event in the order syq reports it; events are not
kept in the result. With
AsyncClient, the callback can be async, and awaiting it counts toward the
timeout.
An event is one of the event types below, a final CpResult or RmResult, or
a MappingStreamResult from
callback mappings.
Each is a frozen dataclass with protocol: ProtocolMetadata. Fields match the
automation results records,
except that class is class_ and paths are PathValue; optional fields are
None when absent.
results= saves the checked records as NDJSON to a binary file-like object,
whose write(bytes) must return a positive count for nonempty data, and leaves
it open. If checking the stream, the process, or a callback fails,
the final record is left out, so the saved stream shows an incomplete run. If
writing fails, the operation is aborted and the error raised.
To retry a failed mapping entry, call retry_entry() on an OperationResult
whose is_retryable is true. It returns a MappingEntry with the same
expected_hash and metadata, or None if the event does not identify the
whole entry. Use these entries only once the call has returned success or
partial; the client never retries by itself.
Event types
Each event type lists its protocol.type and its fields besides protocol.
RunEvent
Sent first. started_at is Unix seconds, mode is "cp" or "rm", and
prune and mapping are None for removal.
protocol.type = "run":
run_id: str
started_at: int
syq_version: str
mode: str
prune: bool | None
mapping: bool | None
dry_run: bool
endpoints: tuple[Endpoint, ...]
ProgressEvent
Periodic progress for displays; use the final result for totals. activity
holds diagnostic measurements
when syq collects them.
protocol.type = "progress":
bytes_done: int
bytes_total: int
bytes_unchanged: int
files_done: int
files_total: int
files_unchanged: int
files_excluded: int
scanned: int
scan_done: bool
timings: Timings
activity: dict[str, Any] | None
rate_bytes_per_second: int | None
eta_ms: int | None
TraceEvent
One change a dry run would make, and the reason for it. dst is relative
to the destination directory, and src is the mapping source when available.
protocol.type = "trace":
action: OperationAction
dst: PathValue
src: PathValue | None
kind: EntryKind
bytes: int | None
reason: TraceReason
OperationResult
The outcome of one copy change. src is present for mapping entries when
available, and error fields when known. Outcomes reported by a restricted
receiver have no src, attempts, or retryable.
protocol.type = "operation_result":
action: OperationAction
dst: PathValue
src: PathValue | None
kind: EntryKind | None
disposition: Disposition
bytes: int | None
attempts: int | None
retryable: Retryability | None
class_: ErrorClass | None
os_kind: OsKind | None
message: str | None
expected_hash: Hash | None
metadata: DestinationMetadata | None
SelectionResult
One removal selector, indexed from zero, and whether it resolved.
protocol.type = "selection_result":
selector: int
path: PathValue
status: SelectionStatus
kind: EntryKind | None
RemovalTrace
One entry a dry run would remove, under the selector it came from.
protocol.type = "removal_trace":
selector: int
path: PathValue
kind: EntryKind
disposition: RemovalDisposition
s3_version_id: str | None
s3_delete_marker: bool | None
RemovalResult
One removal outcome, or a dry run’s failure to inspect an entry.
protocol.type = "removal_result":
selector: int
path: PathValue
kind: EntryKind | None
disposition: RemovalDisposition
attempts: int
retryable: Retryability | None
class_: ErrorClass | None
os_kind: OsKind | None
message: str | None
s3_version_id: str | None
s3_delete_marker: bool | None
ErrorEvent
One error. It counts toward the result’s errors unless it has
diagnostic_for: then it explains why a restricted receiver reported that
destination path as failed, and the receiver’s own error counts the failure.
protocol.type = "error":
message: str
class_: ErrorClass | None
os_kind: OsKind | None
diagnostic_for: PathValue | None
Endpoint
A nested frozen dataclass used by run events:
| Type | Fields | Meaning |
|---|---|---|
Endpoint | role: EndpointRole, kind: EndpointKind, host: str | None, user: str | None | Source/destination and local/SSH/S3 identity; host and user are optional |
Enums
All enums are string enums exported by syq. Members use uppercase names and
values lowercase, for example EntryKind.FILE.value == "file".
OperationStatus is described with the results above.
| Type | Members |
|---|---|
EntryKind | FILE, DIR, SYMLINK, SPECIAL |
EndpointKind | LOCAL, SSH, S3 |
EndpointRole | SOURCE, DESTINATION |
OperationAction | TRANSFER_FILE, CREATE_DIRECTORY, CREATE_SYMLINK, CREATE_SPECIAL, DELETE |
Disposition | SUCCEEDED, FAILED, BLOCKED |
Retryability | YES, NO, UNKNOWN |
ErrorClass | IO, TRANSPORT, CONFLICT, INTEGRITY, SAFETY_LIMIT, USAGE, INTERNAL |
OsKind | NOT_FOUND, PERMISSION_DENIED, ALREADY_EXISTS, INVALID_INPUT, NO_SPACE, QUOTA_EXCEEDED, READ_ONLY, OTHER |
TraceReason | DESTINATION_MISSING, TYPE_DIFFERS, CONTENT_DIFFERS, METADATA_DIFFERS, DESTINATION_ONLY |
SelectionStatus | RESOLVED, MISSING |
RemovalDisposition | WOULD_REMOVE, REMOVED, ALREADY_ABSENT, FAILED |
Failure model
Catch SyqError for every exception the SDK defines, or a subclass to tell an
unsuccessful operation from a broken results stream:
| Exception | Meaning / useful attributes |
|---|---|
SyqInstallError | Bundled executable is missing, or a managed download or its verification failed |
SyqInvocationError | Invalid Python arguments |
SyqOperationError | Typed operation was unsuccessful; .result and .stderr (last 8 KiB) |
SyqProtocolError | Results stream was invalid, unsupported, inconsistent, or incomplete; .returncode, .stderr |
SyqProcessError | Raw run exited nonzero; .result contains complete output |
SyqOutputError | A function such as version() got output it could not parse |
check=False makes cp and rm return an unsuccessful result instead of
raising, and run return a nonzero exit; it suppresses nothing else. Failures
to start syq, timeouts (subprocess.TimeoutExpired), and ordinary type and
value errors are standard Python exceptions, not SyqError. Exceptions from
your callbacks and mapping iterators propagate unchanged, and async
cancellation stays asyncio.CancelledError.
A timeout, cancellation, early exit from a mapping, or stream failure stops syq and every process it started locally, including SSH. Completed changes are not rolled back.