Repository navigation
Description
Summary
Add a minimal Factory object and a nullable link from automations to a factory. A factory has a name and a slug and groups zero or more automations. Nothing else.
A factory has a name and groups zero or more automations. It is addressed by id. Nothing else.
This is the foundation for the Software Factory work. Worklogs (append-only logs scoped to a factory) are an Enterprise feature that builds on factories: OpenHands/enterprise#1297. The automation-side support for them is #726. The Factory UI is a companion issue in OpenHands/OpenHands.
Why
Today an automation is a standalone object, and nothing says which goal it serves. The closest existing mechanism is tags (migration 035), but a tag is a many-to-many label with no owner and nothing the platform can attach other data to. A factory gives a group of automations a single identity that other features, such as worklogs, can hang off.
Requirements
Data model
One Alembic migration (current head is 037), working on PostgreSQL and SQLite.
factories:id,org_id,name,slug,created_at,updated_at.factories:id,org_id,name,created_at,updated_at. Names need not be unique, like automation names.slugis lowercase and URL-safe, derived from the name when omitted, unique per org (ascustom_webhooksis unique on(org_id, source)), and immutable. Rename changes onlyname.- There is no built-in default factory. Zero factories is a valid state.
- A factory has no other attributes: no description and no settings.
idis a UUID that is never reused. Other services keep it as a plain reference, with no foreign key, because their data lives in other databases.
automations.factory_id: nullable, indexed,ON DELETE SET NULL.NULLmeans the automation belongs to no factory, so existing automations keep working with no backfill.- An automation belongs to at most one factory.
- The change appears in the existing automation change audit (
changed_fields) with no extra code, because that hook records every ORM update.
Deletion
- Deleting a factory returns
409while any live (not soft-deleted) automation belongs to it. The response states how many. - Once none do, deletion removes the factory in one transaction. Soft-deleted automations that still reference the factory get
factory_idset toNULL. Data that other services keep for a factory, such as worklogs in Enterprise, is removed by the notification that Let services outside the automation database reference factories: run token, factory lookup and delete notification #726 sends after the deletion commits.
API
All paths are under /api/automation/v1.
POST /factories,GET /factories,GET /factories/{slug},PATCH /factories/{slug}(rename),DELETE /factories/{slug}.POST /factories,GET /factories,GET /factories/{id},PATCH /factories/{id}(rename),DELETE /factories/{id}.A factory response includesid,name,slug,automation_count(live automations only),created_atandupdated_at. The UI needs the count for the factory cards.- A factory response includes
id,name,automation_count(live automations only),created_atandupdated_at. The UI needs the count for the factory cards. - Assigning an automation:
PATCH /{automation_id}acceptsfactory_id, ornullto remove it. The target factory must be in the automation's org. Every automation response includesfactory_id. - Listing a factory's automations:
GET /v1accepts afactory_idfilter, alongside the existingtag,created_byandrun_as_user_idfilters.
Authorization
| Operation | Who |
|---|---|
| Read factories, and list a factory's automations | Any org member (view_automations) |
| Create, rename or delete a factory | manage_automations (admin, owner, and the local API key) |
Assign, move or remove an automation's factory_id |
manage_automations |
Assigning factory_id is a factory-level act, not an edit of the automation: features that build on factories give a factory's automations access to the factory's data. So the creator-of-the-automation exception in _assert_can_manage does not apply to it. For example, the run token from #726 gives a factory's runs write access to the factory's worklogs.
Out of scope
- Worklogs and entries (Worklogs: license-gated append-only logs scoped to a factory enterprise#1297), and the automation-side support for them (Let services outside the automation database reference factories: run token, factory lookup and delete notification #726).
- The Factory UI (companion issue in
OpenHands/OpenHands). A description, an Overview tab, or any factory attribute beyondnameandslug.- A description, an Overview tab, or any factory attribute beyond
name. Serializing factory membership in git sync. A factory's id and slug are local to an install, so the serializer neither writes nor readsfactory_id. Factory-as-code belongs with later template work.- Serializing factory membership in git sync. A factory's id is local to an install, so the serializer neither writes nor reads
factory_id. Factory-as-code belongs with later template work. - Issues and PRs data, metrics, factory-scoped KV and tunable parameters.
Acceptance criteria
A factory can be created with a name. The slug is derived or validated for uniqueness within the org, andPATCHcannot change it. A fresh install has zero factories.- A factory can be created with a name.
PATCHchanges onlyname. A fresh install has zero factories. GET /factoriesandGET /factories/{slug}returnautomation_countfor live automations only.GET /factoriesandGET /factories/{id}returnautomation_countfor live automations only.- An automation can be assigned to a factory, moved to another, and removed from it, by a holder of
manage_automations. A member who created the automation but lacksmanage_automationsgets403. - Assigning an automation to a factory in a different org returns
404. - Existing automations are unaffected by the migration, and each
factory_idchange appears in the automation change audit. GET /v1?factory_id=...returns only that factory's live automations.- Deleting a factory with a live automation returns
409with the count. After the automations are removed from it, deletion removes the factory. A soft-deleted automation that referenced it ends withfactory_id = NULL. - A caller without
manage_automationsgets403on factory create, rename and delete. Any org member can read. The local API key can do everything. - A git-sync pull leaves an automation's
factory_idunchanged. - Behavior is the same on PostgreSQL and SQLite, with one Alembic head and a complete upgrade path from the released schema.
This issue was created by an AI agent (OpenHands) on behalf of @jpshackelford.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Scope verified against the repository and judged ready. The issue's claims match the current code: 037_add_run_triggered_by_user is the single Alembic head; custom_webhooks is unique on (org_id, source) with a 409 on duplicates; _assert_can_manage in router.py grants the creator exception the issue excludes for factory_id assignment; the before_flush audit hook records every ORM update in changed_fields; the git-sync serializer neither writes nor reads factory fields; and GET /v1 already supports tag, created_by and run_as_user_id filters, so factory_id fits the same pattern. The authorization matrix matches webhook_router.py's manage_automations (create/rename/delete) vs view_automations (read) split, which the local API key also satisfies.
Bounded scope: factory CRUD under /api/automation/v1, a nullable indexed automations.factory_id (one migration from 037, PostgreSQL and SQLite), assignment through PATCH /{automation_id}, a factory_id list filter, and change-audit visibility. Non-goals: worklogs (#724), the Factory UI (OpenHands/OpenHands), any factory attribute beyond any factory attribute beyond name and slugname, git-sync serialization of factory membership, and issues/PRs data, metrics, factory-scoped KV or tunable parameters.
Prioritized priority:low: this is a planned foundation for the Software Factory work, but no user report, support evidence, or reproduced production failure is recorded here or in the discussion.
Acceptance Criteria
- A fresh install has zero factories:
GET /factoriesreturns an empty list, and no built-in default factory exists. - One Alembic migration extends
037;alembic upgrade headapplies it with a single head on both PostgreSQL and SQLite, existing automations are unaffected (factory_idstaysNULL, no backfill), and the full existing test suite still passes. -
Creating a factory with only anamesucceeds; the storedslugis lowercase and URL-safe, derived from the name when omitted, and unique within the org — a second create that would produce the same slug in the org fails with409, matchingcustom_webhooks'(org_id, source)uniqueness. - Creating a factory with only a
namesucceeds; names need not be unique. -
POST /factories,GET /factories,GET /factories/{slug},PATCH /factories/{slug}(rename) andDELETE /factories/{slug}exist under/api/automation/v1;PATCHchanges onlyname— theslugis immutable. -
POST /factories,GET /factories,GET /factories/{id},PATCH /factories/{id}(rename) andDELETE /factories/{id}exist under/api/automation/v1;PATCHchanges onlyname. -
Factory responses includeid,name,slug,automation_count,created_atandupdated_at, andautomation_countcounts only live (non-soft-deleted) automations. - Factory responses include
id,name,automation_count,created_atandupdated_at, andautomation_countcounts only live (non-soft-deleted) automations. - Every automation response (create, get, list, patch) includes
factory_id. - A holder of
manage_automationscan assign an automation to a factory, move it to another factory in the same org, and clear it withPATCH /{automation_id}sendingfactory_id: null; omittingfactory_idin a PATCH leaves it unchanged. - A member who created the automation but lacks
manage_automationsreceives403when setting, changing or clearingfactory_id. - Assigning an automation to a factory that does not exist or belongs to a different org returns
404. - Each
factory_idchange appears in the automation change audit (changed_fieldsincludesfactory_idfor that update). -
GET /v1?factory_id=<id>returns only that factory's live automations in the caller's org and combines with the existingtag,created_byandrun_as_user_idfilters. -
DELETE /factories/{slug}returns409stating the number of live automations while any live automation belongs to the factory. -
DELETE /factories/{id}returns409stating the number of live automations while any live automation belongs to the factory. -
Once no live automation belongs to it,DELETE /factories/{slug}removes the factory in one transaction:GET /factories/{slug}then returns404, and a soft-deleted automation that referenced it ends withfactory_id = NULL. - Once no live automation belongs to it,
DELETE /factories/{id}removes the factory in one transaction:GET /factories/{id}then returns404, and a soft-deleted automation that referenced it ends withfactory_id = NULL. - Without
manage_automations: a caller gets403on factory create, rename, delete and onfactory_idassignment, while any org member can read factories and list a factory's automations; the local API key (manage_automations) can do everything. - A git-sync cycle leaves an automation's
factory_idunchanged (the serializer neither writes nor reads it).
Revised in #751 review: the slug is dropped. Factories are addressed by id; struck-through text above is superseded. factory_id is also accepted on the create endpoints, and factories is advertised in /v1/capabilities features.
Activity
feat(factories): add Factories sidebar entry with list and drill-in v…
feat(factories): add the Factory model and automation link (OpenHands…