Skip to content

RFC: Worker Lifecycle - #632

Open
johnthecat wants to merge 2 commits into
rfc/subscription-typed-interrupt-payloadfrom
rfc/worker-lifecycle
Open

RFC: Worker Lifecycle#632
johnthecat wants to merge 2 commits into
rfc/subscription-typed-interrupt-payloadfrom
rfc/worker-lifecycle

Conversation

@johnthecat

@johnthecat johnthecat commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

RFC: docs/rfcs/worker-lifecycle.md.

Second of a four-PR stack: Subscription Typed Interrupt Payload (#631) → Worker Lifecycle (#632) → Unified Renderer (#633) → Input Modality (#634). Based on the typed-interrupt branch.

Why this RFC exists

The Product Manifest Format defines the worker as the product's single background process and does not say when it runs. A worker that runs for the life of the host is a signing-capable process per product running unobserved. A worker that runs only with the app view cannot serve a chat room while the view is closed. Every modality that calls a worker needs one rule, and the Unified Renderer and Input Modality RFCs both name what holds a worker in terms defined here.

What it defines

  • A product has one worker. The host keeps one reference count per worker: the first reference starts it, and at zero the host may stop it. Products never ask for a worker to run.
  • A reference is held exactly while its work is on screen or in flight. Each modality names its holders in its own RFC; this one tabulates Chat, Pocket, Funding and Input.
  • An acknowledgement grant: pinning or adding a product takes one time-limited reference so the worker can set up before anything calls it.
  • Product rules: a worker tolerates being stopped whenever unreferenced, does not read a start as user intent, and does no background work of its own.
  • Nothing crosses the wire.

Implementation

Part of this PR. The reference-counted worker manager lives in truapi-server and hosts implement the start/stop hook; no worker executable is started by this repo today, so the manager and the platform hook are both new.

  • truapi-platform: worker start/stop hook
  • truapi-server: per-product reference count, acknowledgement grant, chat holders on ChatConnection
  • Stub in test_support.rs and runtime tests

Comment thread docs/rfcs/worker-lifecycle.md Outdated
The [Product Manifest Format](product-manifest.md) defines the worker as the product's single background process and
does not say when it runs. A worker that runs for the life of the host is a signing-capable process per product running
unobserved. A worker that runs only with the product's app view cannot serve a chat room while the view is closed. Every
modality that calls a worker needs the same rule.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same rule

You mean follow the requirements below ?

1. **Single.** A product has one worker process, however many modalities call it.
2. **Demand-driven.** The worker runs only while the host has work that only the worker can do.
3. **Stoppable.** The host may stop an unreferenced worker at any time and the product keeps working.
4. **Setup.** An acknowledged product gets a run before anything calls its worker.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is an acknowledged product

Comment thread docs/rfcs/worker-lifecycle.md Outdated
2. **Demand-driven.** The worker runs only while the host has work that only the worker can do.
3. **Stoppable.** The host may stop an unreferenced worker at any time and the product keeps working.
4. **Setup.** An acknowledged product gets a run before anything calls its worker.
5. **Additive.** No wire change; the host starts and stops the worker executable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No wire change

not sure what this refer to


### References

A reference is held for exactly as long as its work is on screen or in flight. Several references of one product hold

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reference is held for exactly as long as its work is on screen or in flight. Several references of one product

Can you give an example where we have several references of one product?
I guess this can happen with input modalities & pocket for example both referencing the same product?

Comment thread docs/rfcs/worker-lifecycle.md Outdated
Comment on lines +58 to +61
When the host acknowledges a product, it takes a time-limited reference on the worker. Acknowledgement may be a pin, an
addition to widgets or pocket, or the adoption of a new deployment of an acknowledged product. Nothing calls the worker
during the grant. The window is host policy, and the host releases the reference whether or not the worker is done, so
setup is idempotent and resumes on the next start.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having a concrete use case as an example would help here.

Comment thread docs/rfcs/worker-lifecycle.md Outdated

### Product rules

- A worker tolerates being stopped whenever nothing references it, including mid-setup and while its output is on

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the worker does not have to tolerate anything, it's more that the host will kill / unload it when it's refcount drops to 0

Comment thread docs/rfcs/worker-lifecycle.md Outdated
- A worker tolerates being stopped whenever nothing references it, including mid-setup and while its output is on
screen. State that must survive goes through host storage.
- A worker does not read being started as user intent.
- A worker does no background work of its own. Proactive wakeups are the host's to schedule and are a separate RFC.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not and it can't

@johnthecat

Copy link
Copy Markdown
Contributor Author

Issue: #663

@johnthecat
johnthecat requested a review from a team September 9, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants