feat: add workspace automations with scheduled daemon sessions - #98
Open
CompN3rd wants to merge 5 commits into
Open
feat: add workspace automations with scheduled daemon sessions#98CompN3rd wants to merge 5 commits into
CompN3rd wants to merge 5 commits into
Conversation
added 3 commits
July 25, 2026 12:09
…ssions Manual, one-shot, interval, and timezone-aware cron triggers per workspace on local and federated machines. Each machine stores and runs its own schedules in fresh daemon-owned Pi sessions with fixed model/thinking settings, configurable timeouts, durable cancellation, immutable run history, and duration/token/cost reporting. Thinking-level selection in the automations editor is scoped to the levels the selected model actually supports.
CompN3rd
marked this pull request as ready for review
July 25, 2026 10:40
added 2 commits
July 26, 2026 20:47
…tomations # Conflicts: # src/server/sessiond.ts # src/shared/apiTypes.ts
…tomations # Conflicts: # src/client/src/api.ts # src/server/sessiond.ts # src/server/sessions/piSessionService.ts # src/shared/capabilities.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a machine-owned Automations tab for running prompts in fresh Pi sessions—on demand or on durable schedules—without requiring the browser or autoreloading web/API process to remain connected.
It includes the complete workflow: authoring and testing jobs, schedule validation, durable dispatch, cancellation and timeout handling, session inspection, usage/cost reporting, remote-machine routing, and an operations dashboard.
What users can do
Create and schedule automations
Operate and inspect jobs
The Automations tab is also an operations dashboard with:
The panel refreshes more aggressively while runs are active and backs off while idle, pauses refreshes while hidden, and rejects stale responses after switching machine or workspace.
Core design decisions
Sessiond owns execution
Scheduling, persistence, and automation-created Pi sessions live in
pi-web-sessiond, not the browser or web/API process. This follows PI WEB's split-runtime model: browser disconnects and UI/API autoreloads do not interrupt active automation runs.The API remains thin and machine-aware. Local and federated requests are forwarded to the selected machine's daemon, where definitions and execution remain machine-local.
Durable state with immutable run snapshots
Definitions, revisions, scheduled occurrences, attempts, cancellation intent, deadlines, actual model/thinking settings, errors, and terminal usage are stored in a WAL-enabled SQLite database under
$PI_WEB_DATA_DIR.Each claimed run freezes the relevant automation name, prompt, workspace, and configuration. Editing a job therefore changes future runs without rewriting historical records. A single-owner fence prevents multiple daemons from concurrently scheduling against the same database.
Test before unattended execution
New jobs are created disabled. A successful manual run records the exact tested revision; enabling is permitted only for that revision. Editing a job increments its optimistic revision, pauses it, and invalidates the previous test result.
This is intentional friction: users must validate the current prompt and settings before allowing unattended execution, and concurrent/stale edits receive a conflict rather than silently overwriting newer changes.
Prefer avoiding duplicate side effects
starting,running, orcancellingattempts becomeunknown; they are not blindly replayed.These choices favor avoiding duplicate filesystem, network, or tool side effects over guaranteed at-least-once execution.
Fresh sessions, not an OS sandbox
Every run starts a fresh Pi session and reapplies the resolved model and thinking policy at dispatch. The daemon reauthorizes the stable
projectId/workspaceIdimmediately before execution; callers cannot provide an arbitrarycwd. Fixed models are validated when saved and again when dispatched, with no silent fallback.A fresh conversation is intentionally not presented as a security sandbox. Automations still inherit the selected machine user's filesystem, network, credentials, processes, and available Pi tools. The UI/docs make unattended execution and its external side effects explicit.
Bounded cancellation and honest recovery states
Cancellation intent is persisted before contacting the running session. PI WEB first requests a soft abort, then uses a bounded force-stop path after a grace period. Confirmed aborts become
cancelledortimed_out; if termination cannot be proven, the run becomesunknownrather than falsely claiming success.Completed sessions remain available for inspection. While an automation owns an active session, normal interactive mutations are rejected so user actions, idle cleanup, and automation lifecycle management cannot race each other.
Telemetry reports what is actually known
Terminal runs freeze root-session input/output/cache token counts and estimated cost in integer micros, together with the actual model and thinking level used. Partial or unavailable accounting is represented as unknown and excluded from numeric totals instead of being displayed as zero.
This intentionally reports the root automation session only. Untracked subagents, detached children, and external paid tools are not claimed as part of the estimate until explicit lineage/accounting exists.
Capability-gated federation
The tab appears only when both the web/API runtime and target session daemon advertise the
automationscapability. All definition, model, run, and cancellation routes participate in the existing federation layer, so the same UI works against local and registered remote machines without replicating automation state between them.Implementation outline
AutomationsPanelprovides the editor, dashboard, polling lifecycle, controls, and session links.AutomationServicecoordinates revision policy, scheduling, concurrency, lifecycle, recovery, realtime events, and telemetry.AutomationStoreowns durable SQLite state, claiming, immutable snapshots, ownership fencing, and restart recovery.AutomationSessionRunnercreates fresh sessions and applies exact model/thinking/timeout settings.PiSessionServicetracks automation ownership and provides awaitable prompt, abort, and force-stop lifecycle operations.Validation
npx tsc --noEmit— passednpm run build— passedsessionController.tree.test.tsassertion fails identically with the relevant files replaced by their exactjmfederico/mainversions; it is unrelated to this feature.Coverage includes schedule/timezone/rate and timeout validation, missed-run coalescing, revision/test-before-enable behavior, optimistic edit conflicts, workspace authorization, ownership fencing, immutable run snapshots, overlap and cancellation races, usage freezing, restart recovery, force-stop behavior, model-specific thinking choices, API parsing/URL encoding, federated forwarding, capability negotiation, and Automation panel behavior.
Operational note
This PR changes
src/server/sessiond.tsand daemon-only session lifecycle paths. Testing or deployment requires a manual restart ofpi-web-sessiond.service(or the environment-specific sessiond service), not only a web/API reload.