Skip to content

Worklogs: append-only logs scoped to a factory #724

Closed as not planned
Closed as not planned

Description

@jpshackelford

Summary

Add worklogs: named, append-only logs inside a factory that automations and humans write to with a raw-body POST. This is the data model and API underneath the Worklogs tab of the Factory UI described in the "Software Factory M1" proposal.

Depends on #725, which adds the Factory object, automations.factory_id, and the factory API and permissions. This issue assumes all of that exists.

The Factory UI is a companion issue in OpenHands/OpenHands; this issue only specifies what the API must return for it.

Why

Orchestration setups that coordinate several automations currently keep their coordination state in a WORKLOG.md committed to the target repository: an append-only record of what was launched and why, plus ## INSTRUCTION: entries that a human leaves for the orchestrator to read on its next wake-up. It has to be truncated by hand once it grows, and it pollutes the repository history.

The service has no equivalent home for this:

Existing What it is Why it does not fit
automation_runs Per-run status Says whether a run finished, not what the factory is doing
KV store (/v1/kv) Per-automation key/value state Not narrative, not shared across automations, no ordering or paging
tags (migration 035) Many-to-many labels No ownership, no place to write to
OTEL / telemetry System-generated, very granular Describes the agent's inner workings, not the state of the factory's work

Terminology

Concept Name in API, DB and UI Replaces
Grouping of automations Factory (#725) unchanged
Named append-only log inside a factory Worklog "event stream", "work stream", streams
One record in a worklog Entry "event"
Who wrote an entry author "author or source label"
Entry heading shown in lists title "title"
Payload format content_type = markdown | json unchanged
First worklog every factory gets default (displayed "Default")

Do not use these words for worklog data in code, routes, tables or UI strings, because they already mean something else here:

  • stream: the openhands/automation/streams/ package, i.e. long-lived inbound source connections (Slack Socket Mode).
  • event: inbound webhook events (/v1/events/{org_id}/{source}, IntegrationEvent, AcceptedEvent), AutomationChangeEvent, AutomationDisableEvent, SDK conversation events, and OTEL events.
  • log alone: application logs, run logs and OTEL logs. Always say "worklog".
  • run stays an automation run. conversation stays an agent conversation. orchestrator and worker are conventions of particular plugins, not platform nouns, so they do not appear in schemas.

Requirements

Data model

One Alembic migration that follows the migration from #725, working on PostgreSQL and SQLite.

  • worklogs: id, factory_id (ON DELETE CASCADE), slug, name, created_at, updated_at. slug and name are each unique within the factory. The slug is the identifier in URLs and is immutable, like the factory slug. Rename changes only name.
  • worklog_entries: id, worklog_id (ON DELETE CASCADE), created_at (server-assigned), content_type, title (nullable), author_kind (user | automation), author_id, author_name (nullable), run_id (nullable), body (text, opaque). Index on (worklog_id, created_at, id).
  • factories.default_worklog_id: a new column pointing at the factory's default worklog. It is set in the same transaction that creates the worklog, so the circular reference needs a deferrable or initially nullable column.
  • The migration creates a worklog named default for every factory that already exists and sets its default_worklog_id, so every factory has a default from the moment the migration completes.

Entries are append-only. There is no update or delete route. Entry bodies are stored as plaintext and independent of AUTOMATION_KV_SECRET, like run error_detail and prompts. Worklogs are narrative and are not a place for secrets; the API documentation says so.

Changes to factory behavior

  • POST /factories also creates the factory's default worklog and sets it as the default, in the same transaction.
  • Deleting a factory removes its worklogs and entries through the foreign keys. The 409 rule for live automations from Factories: a named group that automations can belong to #725 is unchanged.

Default worklog

  • Every factory has one worklog named default from creation. It is an ordinary worklog and can be renamed.
  • The factory points at its default worklog by id, not by slug, so renaming it breaks nothing.
  • The current default cannot be deleted. To delete it, first make another worklog the default. A default always exists, so a factory always has at least one worklog.
  • When no worklog is named, the request targets the default worklog. When a worklog is named but unknown, the request returns 404. A mistyped name never falls back to the default.

API

All paths are under /api/automation/v1.

Worklogs (user auth):

  • POST /factories/{slug}/worklogs, PATCH .../worklogs/{worklog} (rename, make default), DELETE .../worklogs/{worklog}.
  • GET /factories/{slug}/worklogs returns, for each worklog, entry_count, json_entry_count and last_entry_at. The UI needs these for the worklog picker, the "Show JSON entries (N hidden)" toggle and the factory cards.
  • GET /factories and GET /factories/{slug} additionally return last_entry_at, the most recent entry across the factory's worklogs, for the factory cards.

Entries (user auth):

  • POST /factories/{slug}/worklogs/{worklog}/entries
    • The body is the raw request body, not a field in a JSON envelope. Content-Type is text/markdown or application/json. Any other type returns 415.
    • The server assigns created_at. The caller sends no wrapper and no escaping.
    • Markdown is stored verbatim. Markdown that contains JSON in code fences is safe because nothing parses it.
    • JSON is validated on write and stored as the received string, not re-serialized. Invalid JSON returns 422 with the parse error and position, so a writer can fix it in one retry.
    • Invalid UTF-8 returns 422. A body over the size limit returns 413.
    • Response is 201 with the entry id and created_at.
  • GET /factories/{slug}/worklogs/{worklog}/entries?since=&limit=&content_type=
    • Returns id, created_at, content_type, title, author ({kind, id, name}), run_id and body (a string).
    • Order is (created_at, id). The paging cursor encodes both values so entries that share a timestamp are neither skipped nor repeated.
    • content_type filters to markdown or json.
  • The default-worklog forms of both routes omit /worklogs/{worklog}: /factories/{slug}/entries.

Run-token routes. A run does not know its factory slug, so these resolve the factory through the run's automation (factory_id from #725). They accept a run token only and return 404 when the automation has no factory:

  • GET /worklog: the worklogs of the run's factory.
  • GET and POST /worklog/entries: the default worklog.
  • GET and POST /worklog/{worklog}/entries: a named worklog.

They behave like the user-auth entry routes in every other respect.

Title

Derived on write and stored, so reads never re-parse:

  • Markdown: the first ATX heading with the # characters stripped. ## INSTRUCTION: pause merges gives the title INSTRUCTION: pause merges. With no heading, use the first non-empty line, truncated to 120 characters.
  • JSON: no derived title. The body is opaque and parsing it would couple the platform to a schema.
  • An optional X-Worklog-Title header overrides the derived title for both content types.

A human instruction for an orchestrator is a convention, an entry whose title starts with INSTRUCTION:. It is not a separate type. Acknowledging an instruction would be a later entry that references it, and is out of scope here.

Authorization

Operation Who
Read worklogs and entries Any org member (view_automations)
Write entries; create, rename or delete worklogs; change the default worklog manage_automations (admin, owner, and the local API key)
Read and write the run's own factory through /worklog/... A run token
  • Writing entries needs manage_automations because an entry such as INSTRUCTION: can steer an orchestrator. Which automations a factory's runs can write for is controlled by factory_id, which Factories: a named group that automations can belong to #725 restricts to manage_automations for the same reason.
  • Run token. The dispatcher already injects AUTOMATION_KV_TOKEN into every run when AUTOMATION_KV_SECRET is set. It is a signed JWT with automation_id and run_id claims and a 24-hour expiry. The /worklog/... routes accept it the same way kv_router does, resolve the automation, then the automation's factory. The token reaches that one factory's worklogs and nothing else. It is not accepted on the /factories/... routes, so it cannot enumerate factories. When AUTOMATION_KV_SECRET is unset, /worklog/... returns 503, as KV does. User-auth routes work regardless.
  • Author is set by the server and cannot be supplied by the caller. A run token records author_kind = automation, author_id = the automation id, author_name = the automation's name at write time, and the run_id. A user records author_kind = user and author_id = the user id, with author_name null. The service holds no user display names, and its audit records already store ids only, so Canvas resolves user names.

Who writes in M1

  • Entrypoint scripts, using the run token. This is the same pattern the catalog bundles use for KV today: for example an orchestrator script records what it launched and each worker's final response.
  • Humans and other callers holding user credentials.

Agent conversations do not hold the run token. They start in their own sandbox with their own credentials, so writing from inside a conversation needs a conversation-scoped credential or tool in the SDK or app server. That is separate work, tracked in its own issue, and out of scope here. A conversation that writes with a human's key is attributed to that human.

Limits

  • Maximum entry size is 64 KiB by default, equal to the KV value limit, and configurable, for example AUTOMATION_WORKLOG_MAX_ENTRY_SIZE.
  • M1 adds no application-level rate limiting and no retention or TTL. The service treats rate limiting as an infrastructure concern (event_router and webhook_router both say so), and the (worklog_id, created_at, id) index and paged reads keep growth from hurting read performance.

Out of scope

  • The Factory object, factory_id, and the factory API and permissions (Factories: a named group that automations can belong to #725).
  • The Factory UI (companion issue in OpenHands/OpenHands).
  • Editing or deleting entries, instruction acknowledgement, and cross-factory queries.
  • Writing from inside an agent conversation (see "Who writes in M1").
  • Serializing worklogs in git sync.

Acceptance criteria

Worklogs

  • A new factory has one worklog named default, and it is the factory's default. More worklogs can be added. A worklog's slug cannot be changed.
  • After the migration, every factory that existed before it has a default worklog and a default_worklog_id.
  • The default worklog cannot be deleted until another worklog is made the default. Renaming the default does not change which worklog is the default.
  • GET .../worklogs returns entry_count, json_entry_count and last_entry_at for each worklog. GET /factories returns the factory-level last_entry_at.
  • Deleting a factory that has no live automations removes its worklogs and entries.

Entries

  • Posting raw markdown that contains fenced JSON succeeds on the first try, and the body reads back byte-identical, including CRLF line endings and non-ASCII text.
  • Posting valid JSON succeeds and reads back as the same string. Invalid JSON returns 422 with the parse error. An unsupported content type returns 415, invalid UTF-8 returns 422, and a body over the limit returns 413.
  • A markdown entry beginning ## INSTRUCTION: ... gets the title INSTRUCTION: .... X-Worklog-Title overrides the derived title.
  • Entries list in (created_at, id) order with working paging, including pages that cross entries with identical timestamps. content_type filters the list.
  • A request without a worklog name uses the default worklog. A request with an unknown worklog name returns 404.
  • No route updates or deletes an entry.

Authorization

  • Any org member can read. A caller without manage_automations gets 403 on writing entries and on worklog management. The local API key can do everything.
  • A run token can read and write only the worklogs of its own automation's factory, through /worklog/.... It gets 404 when its automation has no factory, and 401 on /factories/... routes. A user-auth caller gets an error on /worklog/....
  • With AUTOMATION_KV_SECRET unset, /worklog/... returns 503 and the user-auth routes still work.
  • author cannot be set by the caller. An entry written with a run token records the automation's id and name and the run_id. An entry written by a user records the user id and a null name.

Other

  • Behavior is the same on PostgreSQL and SQLite, with one Alembic head and a complete upgrade path from the released schema.

Notes for implementation

  • Producers and consumers: this service, Canvas (OpenHands/OpenHands) for the UI, and the SDK or app server for the follow-up that lets agent conversations write.
  • Related existing work: the run token and dual auth in kv_router.py and utils/kv.py, the permission model in router.py (_assert_can_manage), and persisted accepted events in Persist accepted events to deduplicate redeliveries and expose events that matched nothing #361, which is an example of the "event" term this proposal avoids reusing.

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

This issue is a fully specified requirements document: the former open questions were resolved when the maintainer split the worklogs scope out of the factories proposal, so no decision is needed. It depends on #725, which adds the Factory object, automations.factory_id, the factory API and permissions, and which is itself labeled ready-for-dev; the GitHub blocked-by relationship on this issue records the ordering, and the one new Alembic revision here follows #725's migration. The acceptance criteria below restate the issue's own criteria as observable checks without changing them. Adjacent implementations verified against main: the run token with automation_id/run_id claims and 24-hour expiry in utils/kv.py, injected by dispatcher.py only when AUTOMATION_KV_SECRET is set; the token-then-user auth pattern and org-membership check in kv_router.py; the view_automations/manage_automations permission model in router.py; per-factory uniqueness returning 409 on duplicates as webhook_router.py does for (org_id, source); and the (worklog_id, created_at, id) index shape with an id tie-breaker, matching the review guide's pagination rule.

Non-goals, restated for review: the Factory object, factory_id, and the factory API and permissions (#725); the Factory UI (companion issue in OpenHands/OpenHands); editing or deleting entries; instruction acknowledgement; cross-factory queries; writing from inside an agent conversation (separate SDK/app-server follow-up); serializing worklogs in git sync; application-level rate limiting or retention; and entry bodies stored as plaintext, independent of AUTOMATION_KV_SECRET.

Acceptance Criteria

  • One Alembic revision, following Factories: a named group that automations can belong to #725's migration, creates worklogs (id, factory_id ON DELETE CASCADE, slug, name, created_at, updated_at) and worklog_entries (id, worklog_id ON DELETE CASCADE, server-assigned created_at, content_type, nullable title, author_kind, author_id, nullable author_name, nullable run_id, opaque body) with the (worklog_id, created_at, id) index, and adds factories.default_worklog_id (deferrable or initially nullable); alembic upgrade head completes on both PostgreSQL and SQLite with a single head and a complete upgrade path from the released schema.
  • The migration backfills, in one transaction: every factory that existed before it ends with a worklog named default and default_worklog_id pointing at it.
  • POST /factories creates the factory's default worklog and sets it as default_worklog_id in the same transaction, so a new factory has exactly one worklog named default as its default.
  • POST /factories/{slug}/worklogs adds worklogs with slug and name each unique within the factory (duplicate returns 409); worklog slugs are immutable and PATCH .../worklogs/{worklog} changes only name and can set the default; renaming the default worklog leaves default_worklog_id pointing at the same worklog.
  • Deleting the current default worklog fails until another worklog is made the default, after which it succeeds; every factory always has at least one worklog.
  • DELETE /factories/{slug} (subject to Factories: a named group that automations can belong to #725's 409 rule for live automations) removes its worklogs and entries through the foreign keys; the rows are gone after deletion.
  • GET /factories/{slug}/worklogs returns entry_count, json_entry_count and last_entry_at for each worklog; GET /factories and GET /factories/{slug} return the factory-level last_entry_at, the most recent entry across the factory's worklogs.
  • POST /factories/{slug}/worklogs/{worklog}/entries with Content-Type: text/markdown returns 201 with the server-assigned id and created_at, and a markdown body containing fenced JSON, CRLF line endings and non-ASCII text reads back byte-identical.
  • A valid application/json entry is stored and read back as the received string (not re-serialized); invalid JSON returns 422 with the parse error and position; any other Content-Type returns 415; invalid UTF-8 returns 422; a body over the configurable 64 KiB default limit (AUTOMATION_WORKLOG_MAX_ENTRY_SIZE) returns 413.
  • A markdown entry beginning ## INSTRUCTION: ... has title INSTRUCTION: ...; an entry with no heading has its first non-empty line as title truncated to 120 characters; the X-Worklog-Title header overrides the derived title for both content types; JSON entries have no derived title.
  • A write or read to /factories/{slug}/entries targets the default worklog, and the same request to /factories/{slug}/worklogs/unknown/entries returns 404 (a mistyped name never falls back to the default).
  • GET .../entries?since=&limit=&content_type= returns entries in (created_at, id) order and paging neither skips nor repeats entries when consecutive entries share a created_at; content_type=markdown and content_type=json filter the list; each entry returns author as {kind, id, name} and run_id.
  • No route updates or deletes an entry.
  • Any org member can read worklogs and entries; a caller without manage_automations gets 403 on writing entries and on worklog management; the local API key can do everything.
  • The run-token routes GET /worklog, GET/POST /worklog/entries and GET/POST /worklog/{worklog}/entries accept a run token only, resolve the factory through the run's automation, and return 404 when the automation has no factory; a run token on /factories/... returns 401; a user-auth caller on /worklog/... gets an error.
  • A run token reads and writes only the worklogs of its own automation's factory (any other factory's worklog returns 404); with AUTOMATION_KV_SECRET unset, /worklog/... returns 503 while the user-auth routes still work.
  • author cannot be supplied by the caller. A run-token entry records author_kind = automation, author_id = the automation id, author_name = the automation's name at write time and run_id; a user entry records author_kind = user, author_id = the user id and a null author_name.
  • The new routes are covered by tests running against both the SQLite and PostgreSQL fixtures (including the migration backfill, default-worklog, paging-tie, permission and run-token cases above), and uv run python -m pytest tests/ passes.

Activity

  1. added
    ready-for-dev
    on Nov 9, 2026
  2. removed
    ready-for-dev
    on Nov 9, 2026
  3. added
    ready-for-dev
    on Nov 9, 2026
  4. changed the title [-]Factories and worklogs: append-only, agent-writable logs scoped to a factory[/-] [+]Worklogs: append-only logs scoped to a factory[/+] on Nov 9, 2026
  5. removed
    ready-for-dev
    on Nov 9, 2026
  6. added
    ready-for-dev
    on Nov 9, 2026
  7. jpshackelford commented on Nov 10, 2026

    @jpshackelford
    MemberAuthor

    Closing this in favor of OpenHands/enterprise#1297. @DevinVinson suggests worklogs should be an Enterprise feature, and that is where we are taking them.

    This comment was created by an AI agent (OpenHands) on behalf of @jpshackelford.

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