Skip to content

Factories: a named group that automations can belong to #725

Closed

Description

@jpshackelford

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.
    • slug is lowercase and URL-safe, derived from the name when omitted, unique per org (as custom_webhooks is unique on (org_id, source)), and immutable. Rename changes only name.
    • There is no built-in default factory. Zero factories is a valid state.
    • A factory has no other attributes: no description and no settings.
    • id is 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.
    • NULL means 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

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 includes id, name, slug, automation_count (live automations only), created_at and updated_at. The UI needs the count for the factory cards.
  • A factory response includes id, name, automation_count (live automations only), created_at and updated_at. The UI needs the count for the factory cards.
  • Assigning an automation: PATCH /{automation_id} accepts factory_id, or null to remove it. The target factory must be in the automation's org. Every automation response includes factory_id.
  • Listing a factory's automations: GET /v1 accepts a factory_id filter, alongside the existing tag, created_by and run_as_user_id filters.

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

Acceptance criteria

  • A factory can be created with a name. The slug is derived or validated for uniqueness within the org, and PATCH cannot change it. A fresh install has zero factories.
  • A factory can be created with a name. PATCH changes only name. A fresh install has zero factories.
  • GET /factories and GET /factories/{slug} return automation_count for live automations only.
  • GET /factories and GET /factories/{id} return automation_count for 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 lacks manage_automations gets 403.
  • Assigning an automation to a factory in a different org returns 404.
  • Existing automations are unaffected by the migration, and each factory_id change 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 409 with the count. After the automations are removed from it, deletion removes the factory. A soft-deleted automation that referenced it ends with factory_id = NULL.
  • A caller without manage_automations gets 403 on 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_id unchanged.
  • 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 name and slug any factory attribute beyond name, 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 /factories returns an empty list, and no built-in default factory exists.
  • One Alembic migration extends 037; alembic upgrade head applies it with a single head on both PostgreSQL and SQLite, existing automations are unaffected (factory_id stays NULL, no backfill), and the full existing test suite still passes.
  • Creating a factory with only a name succeeds; the stored slug is 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 with 409, matching custom_webhooks' (org_id, source) uniqueness.
  • Creating a factory with only a name succeeds; names need not be unique.
  • POST /factories, GET /factories, GET /factories/{slug}, PATCH /factories/{slug} (rename) and DELETE /factories/{slug} exist under /api/automation/v1; PATCH changes only name — the slug is immutable.
  • POST /factories, GET /factories, GET /factories/{id}, PATCH /factories/{id} (rename) and DELETE /factories/{id} exist under /api/automation/v1; PATCH changes only name.
  • Factory responses include id, name, slug, automation_count, created_at and updated_at, and automation_count counts only live (non-soft-deleted) automations.
  • Factory responses include id, name, automation_count, created_at and updated_at, and automation_count counts only live (non-soft-deleted) automations.
  • Every automation response (create, get, list, patch) includes factory_id.
  • A holder of manage_automations can assign an automation to a factory, move it to another factory in the same org, and clear it with PATCH /{automation_id} sending factory_id: null; omitting factory_id in a PATCH leaves it unchanged.
  • A member who created the automation but lacks manage_automations receives 403 when setting, changing or clearing factory_id.
  • Assigning an automation to a factory that does not exist or belongs to a different org returns 404.
  • Each factory_id change appears in the automation change audit (changed_fields includes factory_id for that update).
  • GET /v1?factory_id=<id> returns only that factory's live automations in the caller's org and combines with the existing tag, created_by and run_as_user_id filters.
  • DELETE /factories/{slug} returns 409 stating the number of live automations while any live automation belongs to the factory.
  • DELETE /factories/{id} returns 409 stating 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 returns 404, and a soft-deleted automation that referenced it ends with factory_id = NULL.
  • Once no live automation belongs to it, DELETE /factories/{id} removes the factory in one transaction: GET /factories/{id} then returns 404, and a soft-deleted automation that referenced it ends with factory_id = NULL.
  • Without manage_automations: a caller gets 403 on factory create, rename, delete and on factory_id assignment, 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_id unchanged (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

  1. added
    enhancement
    on Nov 9, 2026
  2. added
    ready-for-dev
    on Nov 9, 2026
  3. added a commit that references this issue on Nov 25, 2026
    03823b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:lowready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions