aga-runtime 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aga-runtime might be problematic. Click here for more details.

Files changed (66) hide show
  1. aga_runtime-0.4.0/.gitignore +18 -0
  2. aga_runtime-0.4.0/LICENSE +202 -0
  3. aga_runtime-0.4.0/PKG-INFO +239 -0
  4. aga_runtime-0.4.0/README.md +210 -0
  5. aga_runtime-0.4.0/pyproject.toml +75 -0
  6. aga_runtime-0.4.0/src/aga_runtime/__init__.py +99 -0
  7. aga_runtime-0.4.0/src/aga_runtime/_authoring/__init__.py +3 -0
  8. aga_runtime-0.4.0/src/aga_runtime/_authoring/adapters.py +132 -0
  9. aga_runtime-0.4.0/src/aga_runtime/_authoring/catalog.py +304 -0
  10. aga_runtime-0.4.0/src/aga_runtime/_authoring/contracts.py +168 -0
  11. aga_runtime-0.4.0/src/aga_runtime/_authoring/definitions.py +280 -0
  12. aga_runtime-0.4.0/src/aga_runtime/_authoring/lifecycle.py +251 -0
  13. aga_runtime-0.4.0/src/aga_runtime/_authoring/models.py +62 -0
  14. aga_runtime-0.4.0/src/aga_runtime/_authoring/operations.py +112 -0
  15. aga_runtime-0.4.0/src/aga_runtime/_authoring/ports.py +94 -0
  16. aga_runtime-0.4.0/src/aga_runtime/_authoring/runs.py +149 -0
  17. aga_runtime-0.4.0/src/aga_runtime/_authoring/scope.py +65 -0
  18. aga_runtime-0.4.0/src/aga_runtime/_lineage.py +197 -0
  19. aga_runtime-0.4.0/src/aga_runtime/_version.py +13 -0
  20. aga_runtime-0.4.0/src/aga_runtime/app.py +241 -0
  21. aga_runtime-0.4.0/src/aga_runtime/client/__init__.py +5 -0
  22. aga_runtime-0.4.0/src/aga_runtime/client/_http/__init__.py +3 -0
  23. aga_runtime-0.4.0/src/aga_runtime/client/_http/capabilities.py +66 -0
  24. aga_runtime-0.4.0/src/aga_runtime/client/_http/promises.py +77 -0
  25. aga_runtime-0.4.0/src/aga_runtime/client/_http/runs.py +130 -0
  26. aga_runtime-0.4.0/src/aga_runtime/client/_http/schedules.py +208 -0
  27. aga_runtime-0.4.0/src/aga_runtime/client/_http/storage.py +56 -0
  28. aga_runtime-0.4.0/src/aga_runtime/client/_http/transport.py +173 -0
  29. aga_runtime-0.4.0/src/aga_runtime/client/http.py +339 -0
  30. aga_runtime-0.4.0/src/aga_runtime/codec/__init__.py +5 -0
  31. aga_runtime-0.4.0/src/aga_runtime/codec/cbor.py +99 -0
  32. aga_runtime-0.4.0/src/aga_runtime/errors.py +128 -0
  33. aga_runtime-0.4.0/src/aga_runtime/payload/__init__.py +5 -0
  34. aga_runtime-0.4.0/src/aga_runtime/payload/blob.py +133 -0
  35. aga_runtime-0.4.0/src/aga_runtime/protocol/__init__.py +5 -0
  36. aga_runtime-0.4.0/src/aga_runtime/protocol/_runs.py +65 -0
  37. aga_runtime-0.4.0/src/aga_runtime/protocol/wire.py +320 -0
  38. aga_runtime-0.4.0/src/aga_runtime/py.typed +0 -0
  39. aga_runtime-0.4.0/src/aga_runtime/workflow/__init__.py +7 -0
  40. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/__init__.py +3 -0
  41. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/child_runs.py +107 -0
  42. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/children.py +244 -0
  43. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/control.py +52 -0
  44. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/execution.py +66 -0
  45. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/handles.py +220 -0
  46. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/ports.py +61 -0
  47. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/replay.py +338 -0
  48. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/replay_decisions.py +55 -0
  49. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/serialization.py +66 -0
  50. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/signals.py +99 -0
  51. aga_runtime-0.4.0/src/aga_runtime/workflow/_runtime/waiting.py +132 -0
  52. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/__init__.py +3 -0
  53. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/checkpoints.py +243 -0
  54. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/claims.py +118 -0
  55. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/host.py +121 -0
  56. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/invocations.py +93 -0
  57. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/leases.py +58 -0
  58. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/retry.py +49 -0
  59. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/roster.py +54 -0
  60. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/schedules.py +189 -0
  61. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/state.py +120 -0
  62. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/steps.py +254 -0
  63. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/tasks.py +93 -0
  64. aga_runtime-0.4.0/src/aga_runtime/workflow/_worker/workflows.py +272 -0
  65. aga_runtime-0.4.0/src/aga_runtime/workflow/decorators.py +89 -0
  66. aga_runtime-0.4.0/src/aga_runtime/workflow/saga.py +176 -0
@@ -0,0 +1,18 @@
1
+ # Build artifacts — never tracked; PyPI is the archive of published builds.
2
+ dist/
3
+ dist_pypi/
4
+ *.egg-info/
5
+ build/
6
+
7
+ # Tool caches
8
+ __pycache__/
9
+ *.py[cod]
10
+ .mypy_cache/
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ .coverage
14
+ htmlcov/
15
+
16
+ # Local environments
17
+ .venv/
18
+ venv/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,239 @@
1
+ Metadata-Version: 2.4
2
+ Name: aga-runtime
3
+ Version: 0.4.0
4
+ Summary: Durable execution for Python — typed functions that survive crashes, restarts, and month-long waits.
5
+ Project-URL: Homepage, https://coding2fun.in/aga
6
+ Project-URL: Documentation, https://coding2fun.in/aga/python
7
+ Project-URL: Source, https://github.com/vedhlabs/sdk-python
8
+ Project-URL: Issues, https://github.com/vedhlabs/sdk-python/issues
9
+ Author: Kishore Karunakaran
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: background-jobs,distributed-systems,durable-execution,orchestration,resilience,saga,workflow,workflows
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
23
+ Classifier: Topic :: System :: Distributed Computing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: cbor2>=5.6
27
+ Requires-Dist: msgspec>=0.19
28
+ Description-Content-Type: text/markdown
29
+
30
+ # Aga — durable execution for Python
31
+
32
+ Write typed functions that survive crashes, restarts, deploys, and long waits.
33
+ One `App` owns declarations, connection, Run creation, and worker lifecycle.
34
+ Aga records each durable boundary and reuses its committed result on recovery.
35
+
36
+ > **Breaking 0.4 release.** This version removes the equivalent spellings from
37
+ > 0.3 and intentionally provides one public form for each operation.
38
+
39
+ ## Install
40
+
41
+ The predecessor was published as `ogha`. Its package name and API are incompatible
42
+ with Aga 0.4, so upgrade as a hard cutover rather than installing both generations:
43
+
44
+ ```bash
45
+ pip install "aga-runtime==0.4.0"
46
+ ```
47
+
48
+ The distribution is `aga-runtime`; import it with the short, documented alias:
49
+
50
+ ```python
51
+ import aga_runtime as aga
52
+ ```
53
+
54
+ `App` reads `AGA_URL`, `AGA_TENANT`, `AGA_NAMESPACE`, and `AGA_API_KEY` by
55
+ default; constructor values override the connection location and scope.
56
+
57
+ ## Declare durable functions
58
+
59
+ Declarations belong to one App:
60
+
61
+ | Annotation | Meaning |
62
+ | :--- | :--- |
63
+ | `@app.step(...)` | typed durable work plus retry, timeout, and compensation policy |
64
+ | `@app.remote(service, ...)` | typed cross-service or cross-language boundary |
65
+ | `@app.workflow(...)` | durable control flow and worker placement |
66
+ | `@app.schedule(...)` | engine-owned cron creation of root Runs |
67
+
68
+ ```python
69
+ from dataclasses import dataclass
70
+
71
+ import aga_runtime as aga
72
+
73
+ app = aga.App("checkout")
74
+
75
+
76
+ @dataclass
77
+ class Order:
78
+ id: str
79
+ amount: int
80
+
81
+
82
+ @dataclass
83
+ class Receipt:
84
+ id: str
85
+ approved: bool
86
+
87
+
88
+ @app.step(retry=aga.RetryPolicy(max_attempts=5), pivot=True)
89
+ def charge(order: Order) -> Receipt:
90
+ return payments.charge(order)
91
+
92
+
93
+ @app.workflow()
94
+ async def checkout(order: Order) -> Receipt:
95
+ receipt = await charge(order)
96
+ if order.amount > 10_000:
97
+ await aga.signal(
98
+ aga.Approval("large-charge", evidence=receipt),
99
+ timeout=24 * 60 * 60,
100
+ )
101
+ aga.event("order.charged", {"order": order.id})
102
+ return receipt
103
+
104
+
105
+ if __name__ == "__main__":
106
+ app.serve()
107
+ ```
108
+
109
+ Aga restores supported declared Python types at durable JSON boundaries,
110
+ including dataclasses, containers, enums, dates, UUIDs, and Pydantic models.
111
+
112
+ ## Create and coordinate work
113
+
114
+ Calling a registered Step or Remote eagerly creates a typed `Handle`. Workflows
115
+ have one creation form: pass the registered Workflow to `app.start(...)`.
116
+
117
+ | Method or function | Meaning |
118
+ | :--- | :--- |
119
+ | `step(args...)` | create Step work inside the active Workflow |
120
+ | `remote(request)` | create cross-service work inside the active Workflow |
121
+ | `app.start(workflow, args...)` | create a root Run outside a Workflow or an owned child Run inside it |
122
+ | `await aga.join(*handles, count=None)` | await all, the first, or a threshold |
123
+ | `await aga.sleep(seconds)` | park until durable engine time reaches a deadline |
124
+ | `await aga.signal(name_or_approval, timeout=...)` | wait for external input or governed approval |
125
+ | `aga.event(name, value)` | record an operator-visible milestone |
126
+ | `aga.cancel(handle, reason)` | cooperatively cancel durable work |
127
+ | `aga.info()` | read immutable current-Run metadata |
128
+
129
+ Every Step, Remote, root Run, and child Run uses the same `Handle[T]`. Inside a
130
+ Workflow, await a Handle. Outside, a root Handle also supports blocking
131
+ `.result(timeout=...)`.
132
+
133
+ ```python
134
+ run = app.start(checkout.options(run_id=order.id), order)
135
+ receipt = run.result()
136
+
137
+
138
+ @app.workflow()
139
+ async def checkout_with_audit(order: Order) -> Receipt:
140
+ audit = app.start(audit_order, order) # owned child; auto-joined
141
+ receipt = await charge(order)
142
+ await audit
143
+ return receipt
144
+ ```
145
+
146
+ Only independent child work opts out of ownership:
147
+
148
+ ```python
149
+ app.start(audit_order.options(detached=True), order)
150
+ ```
151
+
152
+ `join` is the single multi-Handle combinator:
153
+
154
+ ```python
155
+ all_values = await aga.join(*handles)
156
+ first_value = await aga.join(*handles, count=1)
157
+ two_values = await aga.join(*handles, count=2)
158
+ ```
159
+
160
+ ## Sync, Async, and Async Distributed
161
+
162
+ These describe two separate choices:
163
+
164
+ - **Sync versus Async is caller behavior.** Sync waits for a root Handle's
165
+ result; Async keeps the same Handle and lets the caller continue.
166
+ - **Async versus Async Distributed is workflow placement.** Default Async keeps
167
+ ordinary Steps with the Workflow worker. Async Distributed independently
168
+ dispatches and fences each Step.
169
+
170
+ Use Sync when a request or script needs the result now. Use Async for long work
171
+ or responsive callers. Use Async Distributed when Steps need separate scaling,
172
+ isolation, placement, or leases. There is no `execution="sync"`; waiting never
173
+ changes placement.
174
+
175
+ ```python
176
+ # Sync caller
177
+ receipt = app.start(checkout, order).result()
178
+
179
+ # Async caller
180
+ run = app.start(checkout, order)
181
+ receipt = await run
182
+
183
+
184
+ # Distributed placement
185
+ @app.workflow(execution="async_distributed")
186
+ async def distributed_checkout(order: Order) -> Receipt:
187
+ return await charge(order)
188
+ ```
189
+
190
+ A caller timeout does not cancel the durable Run. Cancellation is explicit with
191
+ `aga.cancel(run, reason)`.
192
+
193
+ ## Waiting, services, and schedules
194
+
195
+ `sleep` completes through engine time. `signal` completes through external
196
+ input. `Approval` is an immutable request passed to `signal`, not a third wait
197
+ verb; it selects governed, fail-closed behavior and replay-bound evidence.
198
+
199
+ A Remote accepts one required request object so its envelope maps to Python,
200
+ Go, Java, and TypeScript without language-specific argument rules. The serving
201
+ App registers a Step with the same method name and portable request schema.
202
+
203
+ Schedules are engine-owned root-Run creation and continue while workers are
204
+ offline:
205
+
206
+ ```python
207
+ @app.schedule("0 6 * * *", input={"report": "kpi"}, revision=2)
208
+ @app.workflow(name="reports.daily")
209
+ async def reports_daily(request: dict[str, str]) -> Report:
210
+ return await build_report(request["report"])
211
+ ```
212
+
213
+ ## Migrating from 0.3
214
+
215
+ | Python 0.3 | Python 0.4 |
216
+ | :--- | :--- |
217
+ | `workflow.run(args...)` | `app.start(workflow, args...).result()` |
218
+ | root `workflow.start(args...)` | `app.start(workflow, args...)` |
219
+ | child `workflow(args...)` / `.spawn(...)` | `app.start(workflow, args...)` |
220
+ | `workflow.detach(args...)` | `app.start(workflow.options(detached=True), args...)` |
221
+ | `aga.gather/race/quorum` | `aga.join(..., count=...)` |
222
+ | `aga.approval(...)` | `aga.signal(aga.Approval(...), timeout=...)` |
223
+ | `run.cancel(reason)` | `aga.cancel(run, reason)` |
224
+ | `aga.scheduled_time()` | `aga.info().scheduled_time` |
225
+ | `aga.Client`, `aga.RunState` | `aga.client.Client`, `aga.protocol.wire.RunState` |
226
+
227
+ This generation requires the lineage-aware server and wire contract. Freeze
228
+ submission ingress and schedules for the complete database, settle or explicitly
229
+ cancel every resumable 0.3 Run, archive its resettable hot origins, revoke the old
230
+ worker credentials, and stop every old server and worker before starting the 0.4
231
+ fleet. A target or Workflow name is not a generation fence, and old and current
232
+ workers must not coexist even on different targets. Once 0.4 accepts work, do not
233
+ roll back to an older generation.
234
+
235
+ Documentation: [overview](https://coding2fun.in/aga) ·
236
+ [Python guide](https://coding2fun.in/aga/python) ·
237
+ [source](https://github.com/vedhlabs/sdk-python)
238
+
239
+ Apache License 2.0. See [`LICENSE`](LICENSE).
@@ -0,0 +1,210 @@
1
+ # Aga — durable execution for Python
2
+
3
+ Write typed functions that survive crashes, restarts, deploys, and long waits.
4
+ One `App` owns declarations, connection, Run creation, and worker lifecycle.
5
+ Aga records each durable boundary and reuses its committed result on recovery.
6
+
7
+ > **Breaking 0.4 release.** This version removes the equivalent spellings from
8
+ > 0.3 and intentionally provides one public form for each operation.
9
+
10
+ ## Install
11
+
12
+ The predecessor was published as `ogha`. Its package name and API are incompatible
13
+ with Aga 0.4, so upgrade as a hard cutover rather than installing both generations:
14
+
15
+ ```bash
16
+ pip install "aga-runtime==0.4.0"
17
+ ```
18
+
19
+ The distribution is `aga-runtime`; import it with the short, documented alias:
20
+
21
+ ```python
22
+ import aga_runtime as aga
23
+ ```
24
+
25
+ `App` reads `AGA_URL`, `AGA_TENANT`, `AGA_NAMESPACE`, and `AGA_API_KEY` by
26
+ default; constructor values override the connection location and scope.
27
+
28
+ ## Declare durable functions
29
+
30
+ Declarations belong to one App:
31
+
32
+ | Annotation | Meaning |
33
+ | :--- | :--- |
34
+ | `@app.step(...)` | typed durable work plus retry, timeout, and compensation policy |
35
+ | `@app.remote(service, ...)` | typed cross-service or cross-language boundary |
36
+ | `@app.workflow(...)` | durable control flow and worker placement |
37
+ | `@app.schedule(...)` | engine-owned cron creation of root Runs |
38
+
39
+ ```python
40
+ from dataclasses import dataclass
41
+
42
+ import aga_runtime as aga
43
+
44
+ app = aga.App("checkout")
45
+
46
+
47
+ @dataclass
48
+ class Order:
49
+ id: str
50
+ amount: int
51
+
52
+
53
+ @dataclass
54
+ class Receipt:
55
+ id: str
56
+ approved: bool
57
+
58
+
59
+ @app.step(retry=aga.RetryPolicy(max_attempts=5), pivot=True)
60
+ def charge(order: Order) -> Receipt:
61
+ return payments.charge(order)
62
+
63
+
64
+ @app.workflow()
65
+ async def checkout(order: Order) -> Receipt:
66
+ receipt = await charge(order)
67
+ if order.amount > 10_000:
68
+ await aga.signal(
69
+ aga.Approval("large-charge", evidence=receipt),
70
+ timeout=24 * 60 * 60,
71
+ )
72
+ aga.event("order.charged", {"order": order.id})
73
+ return receipt
74
+
75
+
76
+ if __name__ == "__main__":
77
+ app.serve()
78
+ ```
79
+
80
+ Aga restores supported declared Python types at durable JSON boundaries,
81
+ including dataclasses, containers, enums, dates, UUIDs, and Pydantic models.
82
+
83
+ ## Create and coordinate work
84
+
85
+ Calling a registered Step or Remote eagerly creates a typed `Handle`. Workflows
86
+ have one creation form: pass the registered Workflow to `app.start(...)`.
87
+
88
+ | Method or function | Meaning |
89
+ | :--- | :--- |
90
+ | `step(args...)` | create Step work inside the active Workflow |
91
+ | `remote(request)` | create cross-service work inside the active Workflow |
92
+ | `app.start(workflow, args...)` | create a root Run outside a Workflow or an owned child Run inside it |
93
+ | `await aga.join(*handles, count=None)` | await all, the first, or a threshold |
94
+ | `await aga.sleep(seconds)` | park until durable engine time reaches a deadline |
95
+ | `await aga.signal(name_or_approval, timeout=...)` | wait for external input or governed approval |
96
+ | `aga.event(name, value)` | record an operator-visible milestone |
97
+ | `aga.cancel(handle, reason)` | cooperatively cancel durable work |
98
+ | `aga.info()` | read immutable current-Run metadata |
99
+
100
+ Every Step, Remote, root Run, and child Run uses the same `Handle[T]`. Inside a
101
+ Workflow, await a Handle. Outside, a root Handle also supports blocking
102
+ `.result(timeout=...)`.
103
+
104
+ ```python
105
+ run = app.start(checkout.options(run_id=order.id), order)
106
+ receipt = run.result()
107
+
108
+
109
+ @app.workflow()
110
+ async def checkout_with_audit(order: Order) -> Receipt:
111
+ audit = app.start(audit_order, order) # owned child; auto-joined
112
+ receipt = await charge(order)
113
+ await audit
114
+ return receipt
115
+ ```
116
+
117
+ Only independent child work opts out of ownership:
118
+
119
+ ```python
120
+ app.start(audit_order.options(detached=True), order)
121
+ ```
122
+
123
+ `join` is the single multi-Handle combinator:
124
+
125
+ ```python
126
+ all_values = await aga.join(*handles)
127
+ first_value = await aga.join(*handles, count=1)
128
+ two_values = await aga.join(*handles, count=2)
129
+ ```
130
+
131
+ ## Sync, Async, and Async Distributed
132
+
133
+ These describe two separate choices:
134
+
135
+ - **Sync versus Async is caller behavior.** Sync waits for a root Handle's
136
+ result; Async keeps the same Handle and lets the caller continue.
137
+ - **Async versus Async Distributed is workflow placement.** Default Async keeps
138
+ ordinary Steps with the Workflow worker. Async Distributed independently
139
+ dispatches and fences each Step.
140
+
141
+ Use Sync when a request or script needs the result now. Use Async for long work
142
+ or responsive callers. Use Async Distributed when Steps need separate scaling,
143
+ isolation, placement, or leases. There is no `execution="sync"`; waiting never
144
+ changes placement.
145
+
146
+ ```python
147
+ # Sync caller
148
+ receipt = app.start(checkout, order).result()
149
+
150
+ # Async caller
151
+ run = app.start(checkout, order)
152
+ receipt = await run
153
+
154
+
155
+ # Distributed placement
156
+ @app.workflow(execution="async_distributed")
157
+ async def distributed_checkout(order: Order) -> Receipt:
158
+ return await charge(order)
159
+ ```
160
+
161
+ A caller timeout does not cancel the durable Run. Cancellation is explicit with
162
+ `aga.cancel(run, reason)`.
163
+
164
+ ## Waiting, services, and schedules
165
+
166
+ `sleep` completes through engine time. `signal` completes through external
167
+ input. `Approval` is an immutable request passed to `signal`, not a third wait
168
+ verb; it selects governed, fail-closed behavior and replay-bound evidence.
169
+
170
+ A Remote accepts one required request object so its envelope maps to Python,
171
+ Go, Java, and TypeScript without language-specific argument rules. The serving
172
+ App registers a Step with the same method name and portable request schema.
173
+
174
+ Schedules are engine-owned root-Run creation and continue while workers are
175
+ offline:
176
+
177
+ ```python
178
+ @app.schedule("0 6 * * *", input={"report": "kpi"}, revision=2)
179
+ @app.workflow(name="reports.daily")
180
+ async def reports_daily(request: dict[str, str]) -> Report:
181
+ return await build_report(request["report"])
182
+ ```
183
+
184
+ ## Migrating from 0.3
185
+
186
+ | Python 0.3 | Python 0.4 |
187
+ | :--- | :--- |
188
+ | `workflow.run(args...)` | `app.start(workflow, args...).result()` |
189
+ | root `workflow.start(args...)` | `app.start(workflow, args...)` |
190
+ | child `workflow(args...)` / `.spawn(...)` | `app.start(workflow, args...)` |
191
+ | `workflow.detach(args...)` | `app.start(workflow.options(detached=True), args...)` |
192
+ | `aga.gather/race/quorum` | `aga.join(..., count=...)` |
193
+ | `aga.approval(...)` | `aga.signal(aga.Approval(...), timeout=...)` |
194
+ | `run.cancel(reason)` | `aga.cancel(run, reason)` |
195
+ | `aga.scheduled_time()` | `aga.info().scheduled_time` |
196
+ | `aga.Client`, `aga.RunState` | `aga.client.Client`, `aga.protocol.wire.RunState` |
197
+
198
+ This generation requires the lineage-aware server and wire contract. Freeze
199
+ submission ingress and schedules for the complete database, settle or explicitly
200
+ cancel every resumable 0.3 Run, archive its resettable hot origins, revoke the old
201
+ worker credentials, and stop every old server and worker before starting the 0.4
202
+ fleet. A target or Workflow name is not a generation fence, and old and current
203
+ workers must not coexist even on different targets. Once 0.4 accepts work, do not
204
+ roll back to an older generation.
205
+
206
+ Documentation: [overview](https://coding2fun.in/aga) ·
207
+ [Python guide](https://coding2fun.in/aga/python) ·
208
+ [source](https://github.com/vedhlabs/sdk-python)
209
+
210
+ Apache License 2.0. See [`LICENSE`](LICENSE).