Skip to content

Simplify task execution and lazy evaluation - #19

Merged
jhidding merged 4 commits into
msgspec-constructfrom
simplify-tasks
Nov 16, 2026
Merged

jhidding merged 4 commits into
msgspec-constructfrom
simplify-tasks

Conversation

@jhidding

@jhidding jhidding commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #18; merge that one first.

Simplifies the task execution and lazy evaluation code without changing the public LazyDB.run interface (it still returns Ok or a Failure).

  • One _exec helper for all commands. The one-liner and runner paths in Task.run duplicated process creation, throttling, stderr logging and exit-code checks. Both now produce a list of commands (get_commands) run by _exec. A new get_stdin context manager also closes the stdin file, which was never closed before.
  • Futures instead of lock and cached result. Each Lazy task stores the asyncio.Future that computes it, and concurrent requests await the same future. This replaces the per-task lock, the stored Result, and run_cached/run_after_deps. Inside the DB, failures are exceptions.
  • Fixes a cycle that deadlocked. The old cycle check followed the path of a single request, so a cycle reached from two branches at once (all → a, b; a ↔ b) hung forever. Cycle detection now tracks which tasks are waiting on which. Covered by test_cycle_from_two_branches.
  • Removes Template. It was a TaskProxy with a call method that only substituted its arguments. Templates are now plain TaskProxy objects. brei.Template is no longer exported.

Also includes a small commit fixing test_lazy.

🤖 Generated with Claude Code

jhidding and others added 4 commits November 16, 2026 08:23
The one-liner and runner code paths in `Task.run` duplicated process
creation, throttling, stderr logging and return-code checking. Both now
produce a list of commands (`get_commands`) that is run by `_exec`.
Standard input is handled by a `get_stdin` context manager, which also
closes the input file after use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each `Lazy` task now stores the `asyncio.Future` that computes it, so
concurrent requests await the same future. This replaces the per-task
lock, the cached `Result`, and `run_cached`/`run_after_deps`. Inside the
DB, failures propagate as exceptions; `LazyDB.run` still returns `Ok` or
a `Failure`, so its interface is unchanged.

Cycle detection now checks which tasks are waiting on which, instead of
following the path of a single request. The old check missed a cycle
reached from two branches at once (`all` needing both `a` and `b`, with
`a` and `b` needing each other), which deadlocked; there is a test for
this case now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Template` only added a `call` method that substituted its arguments.
Templates are now plain `TaskProxy` objects, and `tasks_from_call`
calls `substitute` directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jhidding
jhidding merged commit 93a483f into msgspec-construct Nov 16, 2026
@jhidding
jhidding deleted the simplify-tasks branch November 16, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant