Workers

Long builds that outlive a reply: a second conversation with its own budget.

advanced9 min read

You ask Developer to build an app in a fresh checkout. It has to fetch dependencies, run the build, and read the result before it can tell you what happened. You might need another reply before the build finishes. Pipal can give the job a conversation of its own so Developer can come back and check the same build.

In this chapter

  • Find the conversation that keeps a build going between replies.
  • Follow a worker from the first assignment through a timed wait and a follow-up.
  • Tell which budget, stop command, and approval setting apply.

The chat owns a worker beyond the current reply

Who owns the build?
  • Parent chat

    The parent chat owns the background supervisor and can send more than one assignment through it over time.

    • Chat metadata pipal.chat

      The parent stores the worker handle, supervisor ID, profile, assignment state and any active wait record.

    • Current reply

      Stop targets this run. A later reply in the parent chat can inspect or wait on the same worker.

      • Optional wait wait_worker

        For a running assignment, the tool can sleep until the supervisor signals that it ended or the wait timer expires.

    • Background supervisor pipal.development-worker

      A Pipal task saved by Pi and owned by the chat. Its start phase admits the assignment and its collect phase records the outcome.

      • Worker conversation

        This conversation is owned by the supervisor. Its ID is the handle returned by the worker tools.

        • Assignment input

          The supervisor admits a prompt here. Follow-ups become new inputs in the same transcript.

        • Worker budget pipal.chat

          The worker’s pipal.chat carries its deadline and the location, project name and scope inherited from the parent. Its turn cap lives in pi.agent.

        • Live tools pi.live

          Open tool slots record what the worker is doing, including a call sleeping for workspace approval.

        • Saved answer

          A finished input with an answer points to the saved assistant entry. A later status or wait can read its text.

  • Chat metadata → Worker conversation · Stores the worker ID
  • Assignment input → Background supervisor · Pi signals the supervisor when the input settles
  • Background supervisor → Optional wait · Wakes a recorded waiter when the assignment ends
  • Optional wait → Saved answer · Reads the answer when available

Background supervisor

A Pipal task saved by Pi and owned by the chat. Its start phase admits the assignment and its collect phase records the outcome.

Talks to

Select the worker conversation and the current reply to trace their different paths back to the parent chat.

A top-level reply starts with a time budget of two minutes by default. The bundled Developer profile gets a cap of 50 tool roundsA model response that requests tools, together with the tool calls it requested. when you create a chat with default settings. Other bundled profiles get 20. A build may use many rounds to diagnose a failure or verify the result. A development workerA conversation that carries out development assignments for a parent chat with its own time and turn budgets. gives the job a durable ID and its own budget. index.ts developer.md

Your chat is the parent. It owns a saved background task, the supervisor, which in turn owns the worker conversation. The supervisor admits an assignment there and records how it ends. The worker inherits the parent’s locationThe place a chat uses for project tools, either the Pipal host, an account reached over SSH, or a Docker project., project name and scope, so it works in the same checkout. The development workspace shows how Pipal opens that checkout. workers.ts index.ts

A top-level chat can get the worker tools when delegation is enabled and its project is still bound at This machine or SSH machine. A Docker chat uses a volume. Worker eligibility requires a named project, regardless of web tool access. The parent’s profile must have project tools itself or be able to delegate to a profile that has them. At launch Pipal checks the requested worker profile too. That lets Chat hand a build to Developer when Developer has Bash access. index.ts workspace-locations.ts

Disabling the pinned location in Settings → Workspace interrupts the worker even if the parent is idle. Core marks the active assignment as stopping and marks the worker’s run for abort if it has started. After re-enabling the location, the parent can give the saved worker another assignment once the previous one settles, provided the project binding and profile grants still allow it and a slot is free. index.ts workers.ts

Deep diveHow the supervisor starts and collects an assignment

grants() offers pipal.workers to eligible top-level conversations and lists eligible target profiles in the model’s instructions. At assignment and again at admission by the supervisor, authorizeWorker() requires a current named project binding and a target profile that has a project tool extension. To use another profile, the parent’s profile must list it as an allowed delegate. The server enables delegation by default. If you set extensions.enabled explicitly, include pipal.delegate to keep both features available. index.ts config.ts

The first start creates the supervisor and the worker conversation in the same commit as the worker record and its slot reservation. This is the ownership boundary that matters when the parent run is stopped.

packages/core/src/workers.ts
const owner = await tx.createTask(Supervisor, null, {
conversationId: api.conversationId,
ownership: { kind: 'conversation' },
background: true
});
const { id: child } = await tx.createConversation({
ownership: { kind: 'task', taskId: owner }
});
await options.prepare(tx, api.conversationId, child, profile, prompt);

The assigning tool records its own task ID as the assignment’s generation. In start, the supervisor rechecks authorization, then admits the prompt with request ID worker:<generation>. If authorization or admission fails, it records the failure and releases the slot. On successful admission it saves the submission ID, sets the deadline and parks in collect on Pi’s SubmissionSettled signal. In collect, a submission with status done counts as completed. Otherwise the supervisor records stopped if a stop was requested, or failed if it was not.

When the assignment ends, the supervisor releases its slot, signals a recorded waiter and sleeps on next-<generation>. A follow-up changes the generation and signals that sleeping task on the previous key. Replaying an assigning call for the current generation returns its status. If the supervisor itself is aborted, its abort handler marks its own worker stopped, releases the slot and ends the task. workers.ts

The parent chooses when to wait

Two waits for one build
  • Parent reply
  • Supervisor workers.ts
  • Worker chat
  1. Parent reply → Parent reply · Start worker

    The parent calls start_worker

    The tool creates the chat’s supervisor and its worker conversation, records the assignment, and returns the worker conversation ID.

  2. Supervisor → Worker chat · Admit input

    The supervisor submits the assignment

    The supervisor sets the worker’s deadline in the admission commit. Here it does so before the parent starts waiting.

  3. Supervisor → Supervisor · Park

    The supervisor waits for the worker input to settle

    The supervisor saves the input ID and parks on its settlement signal.

  4. Parent reply → Parent reply · Wait 1

    The parent parks for a short wait

    wait_worker sets a wake time and listens for a change to this assignment.

  5. Parent reply → Parent reply · Wait expires

    The parent gets control back

    The wait returns the current status. In this example the assignment is still active. The elapsed wait, capped at the requested duration, is credited to the parent’s deadline.

  6. Parent reply → Parent reply · Wait again

    The parent asks to wait again

    It uses the same worker ID. This can happen in the same reply or in a later one.

  7. Worker chat → Supervisor · Input settles

    The worker answers

    Pi sends the supervisor a settlement signal for this assignment.

  8. Supervisor → Parent reply · Wake waiter

    The supervisor completes the assignment

    It records completion, releases the worker’s slot and signals the parent’s waiting tool task in the same commit.

  9. Parent reply → Parent reply · Read answer

    The parent collects the saved answer

    wait_worker reads the worker’s saved answer and returns it to the parent model. It credits the time spent on this wait.

Parent reply
Supervisor workers.ts
Worker chat

Parent reply → Parent reply

The parent calls start_worker

The tool creates the chat’s supervisor and its worker conversation, records the assignment, and returns the worker conversation ID.

The first wait expires while the build continues. The second ends early when the worker reports completion.

start_worker takes a profile and an assignment. It returns the worker ID once the assignment is recorded. The supervisor admits the input separately. The model can ask worker_status to see the open tools and up to the last 1,024 UTF-16 code units of retained output per tool, or read the saved answer text when available. You can open the worker transcript from the parent chat to see what it tried. workers.ts App.svelte

wait_worker lets the parent put its reply to sleep while the worker makes progress. If the assignment is already over, the tool returns its status immediately. Otherwise the wait defaults to five minutes and ends early if the assignment ends. When it expires, the parent gets the current status and can wait again using the same ID. Pipal credits the time spent waiting back to the parent’s deadline, up to the requested wait. workers.ts

Once an assignment ends, the parent can call continue_worker with another prompt, perhaps to check the service after a successful build. The new assignment lands in the same transcript. Calling start_worker again with an authorized profile returns the existing worker’s status. workers.ts

A worker that writes a final answer on its reserved request can show completed. If Pi’s hard cap ends the run, the worker row shows failed, and worker_status reports the reason turn_limit. workers.ts TranscriptView.svelte

Resume response is for a main chat. To continue a settled worker, ask in the parent chat for a follow-up assignment. The parent can use continue_worker to give the worker a fresh deadline and round count. view.ts workers.ts

To end an active assignment, the model can call stop_worker. It records the stop request and asks Pi to abort the worker’s run. The supervisor records the outcome when the input settles. A separately managed service can keep running. workers.ts

The worker has a separate budget and slot

Delegation follows a specialist call from assignment to answer. Use the comparison to see what changes when the work is owned by a background supervisor.

A specialist and a worker
FeatureDelegated specialist delegateDevelopment worker pipal.workers
Parent resumesWhen the specialist’s input settles.After launch. A later wait can end on completion or on its own timer.
Time and turnsShares the parent’s deadline. Has its own count under the ordinary runtime cap (20 by default) and its profile limit.Has its own deadline and separate runtime cap (100 by default), lowered by its profile when applicable.
Stop the replyThe stop reaches the specialist through the delegate call.The current assignment survives. Use stop_worker to end it.
CapacityThe parent runs tool calls one at a time. A specialist uses its parent’s admission.One worker per eligible chat. Active assignments count against a separate pool shared by the runtime.
Follow-upAnother call opens another specialist conversation.continue_worker submits an input to the same conversation in the same project, with a fresh deadline and round count.

Choose up to two columns

FeatureDelegated specialist delegateDevelopment worker pipal.workers
Parent resumesWhen the specialist’s input settles.After launch. A later wait can end on completion or on its own timer.
Time and turnsShares the parent’s deadline. Has its own count under the ordinary runtime cap (20 by default) and its profile limit.Has its own deadline and separate runtime cap (100 by default), lowered by its profile when applicable.
Stop the replyThe stop reaches the specialist through the delegate call.The current assignment survives. Use stop_worker to end it.
CapacityThe parent runs tool calls one at a time. A specialist uses its parent’s admission.One worker per eligible chat. Active assignments count against a separate pool shared by the runtime.
Follow-upAnother call opens another specialist conversation.continue_worker submits an input to the same conversation in the same project, with a fresh deadline and round count.
Compare the lifetime of one delegated call with the lifetime of an assignment in a reusable worker conversation.

Each worker assignment starts with 20 minutes by default. The worker conversation saves a cap of 100 tool rounds by default, including when the worker uses Developer. Pipal takes the lower of runtime.worker_max_turns and the worker profile’s max_turns when it creates the worker. index.ts

Development Bash has a separate command timeout. It must start before the worker’s deadline. Pipal credits the elapsed command time up to the tool limit when the call finishes without being aborted, preserving the worker’s remaining budget for work such as inspecting the result. development-workspace.ts index.ts

One worker can use a worker slot for a build while you ask another chat for help. A slot stays reserved while the assignment is running, including a wait for your approval. The supervisor releases it when the assignment ends, including when admission fails. This is why a chat can still hold its worker handle after the worker has released its slot. workers.ts

Deep diveHow the two deadlines account for a wait

runtime.worker_timeout_ms accepts 1,000 to 3,600,000 milliseconds, and runtime.worker_max_turns accepts 1 to 500 tool rounds. continue_worker reuses the worker’s saved agent settings, including its cap and extension selection. A worker saved before the turn-budget extension was attached keeps its saved selection on follow-ups. The supervisor admits directly into that conversation and uses beginBudget() to set the deadline from the current timeout. config.ts index.ts workers.ts

On startup, Pipal checks pending worker deadlines separately from their parents’ deadlines. While a Bash command is active, the deadline check allows the full tool timeout. When the tool finishes without being aborted, Pipal credits the elapsed tool time up to that limit. Startup accounts for a saved tool clock before checking the deadline. index.ts

wait_worker accepts 1 to 300 seconds. It stores the waiter’s task ID and a start and end time in the parent’s saved state. While the wait is active, expiry checks include its full possible duration. When the tool wakes, it adds the actual time spent waiting, capped at that end time, clears the wait record, and asks core to check the new deadline. If the worker needs a human decision while the parent is parked in wait_worker, the parent is also exempt from the ordinary run limit and deadline expiry for as long as both waits hold. The parent’s own wait timer can still wake it on schedule. workers.ts index.ts

Worker capacity lives in the session document pipal.worker-slots. Its owners list contains the supervisor task IDs that have reserved a slot. Starting or continuing checks capacity and reserves a slot in the same commit. With every slot taken, an attempt to reserve a new slot returns a tool error. workers.ts

The parent chat shows the worker’s approval card

A worker may stop at the workspace gate before it starts a command. Its transcript row in the parent chat then shows waiting for approval, and you can decide from there. Approvals and YOLO explains what the card covers and why each decision names a specific wait. view.ts App.svelte

For gated project tools, the worker uses the parent’s current YOLOA saved permission to skip the approval prompt for actions in a matching workspace scope. grant. This matters between replies. You can turn YOLO off while a worker assignment is active and the parent chat is idle. When the worker next proposes a gated action, the wrapper reads the parent’s current setting. Turning YOLO on leaves an existing card waiting for a decision or a stop. index.ts

Deep diveWhere the worker’s request and decision go

For a bound project call, the wrapper detects independentWorker, follows the child conversation’s owner to the parent, rechecks that it can use this worker profile, and takes the parent’s yoloScope for comparison with the worker’s bound scope. If an approval wakes the call after the parent has lost permission to use that profile, the call ends in a tool error. If disabling the location has already marked the approval task for abort, approveWorkspace() rejects the decision. A delivered decision credits the worker’s own budget because budgetOwner() returns the worker ID for an independent worker. The parent gets the separate, capped credit for its own wait_worker. index.ts workers.ts

The parent stream watches the running worker’s live tool slots for changes to approvals. snapshot() attaches those requests at worker.approvals. With the transcript collapsed, the markup in App.svelte passes the worker’s conversation ID to WorkspaceApproval, so the card sends the decision to the conversation where the command was proposed. index.ts view.ts App.svelte WorkspaceApproval.svelte

The runtime test reopens the store after the first wait expires. The parent waits again on the saved worker ID, and the approval still reaches that worker. When Pi recovers a development Bash call interrupted by a process crash, it returns an interrupted tool error with the output committed so far. The shared bashDefinition marks Bash replay-unsafe. runtime.test.ts project-tool-definitions.ts README.md

When a build takes longer than the default budget, where do you set limits for the next assignment? Configuration, annotated follows the settings from config.toml into the runtime.

Recap

  • The chat owns a background supervisor, which owns a reusable worker conversation pinned to the parent’s location and project.
  • A wait or parent reply can end while the worker continues. Disabling the pinned location interrupts its assignment.
  • Each assignment reserves a slot and starts a new deadline and round count against the worker’s saved cap. Gated project calls check the parent’s current YOLO grant.
Check yourself
  1. A wait returns while the worker is still running. You want the answer from that build. What can the parent do?
    • Wait again using the worker’s ID
    • Start a second worker in the same chat
    • Continue the worker with a new assignment immediately
    Answer and explanation

    Wait again using the worker’s ID

    The wait ended on its own timer. The same assignment remains active, so the parent can wait again.

  2. You stop a parent reply while a worker is compiling. What can a later reply in that chat do?
    • Only start over in a different checkout
    • Inspect or wait on the same worker
    • Read only the output that arrived before Stop
    Answer and explanation

    Inspect or wait on the same worker

    The supervisor belongs to the chat. It and its worker conversation survive stopping a single reply.

  3. A worker settles with turn_limit during verification. How can the parent give it more rounds in the same transcript?
    • Wait again for the settled assignment
    • Call start_worker with the same profile
    • Call continue_worker with a follow-up assignment
    Answer and explanation

    Call continue_worker with a follow-up assignment

    A follow-up starts a fresh run in the same worker conversation, using its saved cap and the previous tool results.

  1. A wait returns while the worker is still running. You want the answer from that build. What can the parent do?

  2. You stop a parent reply while a worker is compiling. What can a later reply in that chat do?

  3. A worker settles with turn_limit during verification. How can the parent give it more rounds in the same transcript?

In the source

Book contents

Search the book