tractor/ai/prompt-io/claude/20260702T154255Z_65bf9df5_p...

80 lines
2.7 KiB
Markdown
Raw Normal View History

Add `tractor.to_actor` one-shot task API subpkg First cut at the `to_thread`/`to_process`-style "run it over there" wrapper layer from issue #477: a single-remote-task invocation API decoupled from the `ActorNursery` spawn machinery, composed purely from the lower level daemon-actor + portal primitives, - `to_actor.run(fn, **fn_kwargs)` spawns a subactor via `ActorNursery.start_actor()`, schedules `fn` as its lone task with `Portal.run()` and ALWAYS reaps it via a `finally`-scoped `Portal.cancel_actor()` (whose bounded cancel-req wait is internally shielded so the reap also runs under caller-scope cancellation). - remote errors raise directly in the caller's task as boxed `RemoteActorError`s, moving error collection/propagation up into whatever local `trio` scope encloses the call. - "placement" opts: `portal=` reuses a running actor (no spawn/reap), `an=` spawns from a caller-managed actor-nursery, neither opens a private call-scoped `open_nursery()` (implicitly booting the runtime, tunable via pass-through `runtime_kwargs`). - fail-fast validation BEFORE any spawn: non-streaming async fn only (same constraint as `Portal.run()`), `portal=`/`an=` mutual exclusion and no `runtime_kwargs` alongside a placement opt. Also, - x-ref the successor API from `.run_in_actor()`'s deprecation TODO + docstring; emitting a formal `DeprecationWarning` waits on migrating in-repo usage. - log prompt-io provenance per NLNet policy incl. the driver prompt file. Prompt-IO: ai/prompt-io/claude/20260702T154255Z_65bf9df5_prompt_io.md (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
2026-07-02 16:10:19 +00:00
---
model: claude-fable-5
service: claude
session: f6c84722-471a-4458-9a80-e453fea9029f
timestamp: 2026-07-02T15:42:55Z
git_ref: 65bf9df5
scope: code
substantive: true
raw_file: 20260702T154255Z_65bf9df5_prompt_io.raw.md
---
## Prompt
Driver prompt file `ai/prompt-io/prompts/issue_477.md`:
> attempt to resolve
> https://github.com/goodboy/tractor/issues/477
> do it with /open-wkt.
(plus a hard stop-for-human-review deadline of 12:50PM
EST the same day)
Issue #477 asks to factor `ActorNursery.run_in_actor()`
(and possibly `Portal.run()`) out of the nursery
internals into a new `tractor.to_actor` wrapper
subpackage of "higher level one shot" single-remote-task
APIs, adopting the `trio.to_thread`/`anyio.to_process`
parlance, so that error collection/propagation moves up
into the caller's local `trio` scope and the nursery's
spawn machinery can eventually drop the
`._ria_nursery` coupling.
## Response summary
First-cut `tractor.to_actor` subpkg delivering the
one-shot API composed purely from the existing
daemon-spawn + portal primitives (`start_actor()` +
`Portal.run()` + `Portal.cancel_actor()`), leaving the
legacy `.run_in_actor()` machinery untouched (formal
deprecation deferred until in-repo usage migrates):
- `to_actor.run(fn, **fn_kwargs) -> Any`: spawn a
subactor, schedule `fn` as its lone remote task, wait
on and return its result, ALWAYS reaping the subactor
(shield-safe `finally`). Remote errors raise in the
caller's task as boxed `RemoteActorError`s.
- placement variants: `portal=` reuses a running actor
(no spawn/reap), `an=` spawns from a caller-managed
actor-nursery, neither opens a call-scoped private
`open_nursery()` (implicitly booting the runtime,
configurable via `runtime_kwargs`).
- fail-fast validation before any spawn: non-streaming
async fn required; `portal=`/`an=` mutually
exclusive; `runtime_kwargs` rejected alongside any
placement opt.
- `run_in_actor()` TODO/docstring now cross-reference
the successor API.
## Files changed
- `tractor/to_actor/__init__.py` — new subpkg,
re-exports `run`
- `tractor/to_actor/_api.py``run()` +
`_invoke_in_subactor()` + `_validate_one_shot_fn()`
- `tractor/__init__.py` — top-level `to_actor`
re-export
- `tractor/runtime/_supervise.py` — comment/docstring
pointers from `run_in_actor()` to the successor
- `tests/test_to_actor.py` — 11-test suite covering
all placement variants, error relay, the concurrent
worker-pool-ish pattern and arg validation
- `examples/parallelism/to_actor_one_shots.py`
runnable demo (auto-collected by
`test_docs_examples.py`)
## Human edits
None yet — pending human review (work paused before the
12:50PM EST deadline per the driver prompt).