Repository navigation
Description
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: theopenhands/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.logalone: application logs, run logs and OTEL logs. Always say "worklog".runstays an automation run.conversationstays an agent conversation.orchestratorandworkerare 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.slugandnameare each unique within the factory. The slug is the identifier in URLs and is immutable, like the factory slug. Rename changes onlyname.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
defaultfor every factory that already exists and sets itsdefault_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 /factoriesalso creates the factory'sdefaultworklog and sets it as the default, in the same transaction.- Deleting a factory removes its worklogs and entries through the foreign keys. The
409rule for live automations from Factories: a named group that automations can belong to #725 is unchanged.
Default worklog
- Every factory has one worklog named
defaultfrom 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}/worklogsreturns, for each worklog,entry_count,json_entry_countandlast_entry_at. The UI needs these for the worklog picker, the "Show JSON entries (N hidden)" toggle and the factory cards.GET /factoriesandGET /factories/{slug}additionally returnlast_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-Typeistext/markdownorapplication/json. Any other type returns415. - 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
422with 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 returns413. - Response is
201with the entryidandcreated_at.
- The body is the raw request body, not a field in a JSON envelope.
GET /factories/{slug}/worklogs/{worklog}/entries?since=&limit=&content_type=- Returns
id,created_at,content_type,title,author({kind, id, name}),run_idandbody(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_typefilters tomarkdownorjson.
- Returns
- 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.GETandPOST /worklog/entries: the default worklog.GETandPOST /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 mergesgives the titleINSTRUCTION: 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-Titleheader 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_automationsbecause an entry such asINSTRUCTION:can steer an orchestrator. Which automations a factory's runs can write for is controlled byfactory_id, which Factories: a named group that automations can belong to #725 restricts tomanage_automationsfor the same reason. - Run token. The dispatcher already injects
AUTOMATION_KV_TOKENinto every run whenAUTOMATION_KV_SECRETis set. It is a signed JWT withautomation_idandrun_idclaims and a 24-hour expiry. The/worklog/...routes accept it the same waykv_routerdoes, 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. WhenAUTOMATION_KV_SECRETis unset,/worklog/...returns503, 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 therun_id. A user recordsauthor_kind = userandauthor_id= the user id, withauthor_namenull. 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_routerandwebhook_routerboth 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
defaultworklog and adefault_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 .../worklogsreturnsentry_count,json_entry_countandlast_entry_atfor each worklog.GET /factoriesreturns the factory-levellast_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
422with the parse error. An unsupported content type returns415, invalid UTF-8 returns422, and a body over the limit returns413. - A markdown entry beginning
## INSTRUCTION: ...gets the titleINSTRUCTION: ....X-Worklog-Titleoverrides the derived title. - Entries list in
(created_at, id)order with working paging, including pages that cross entries with identical timestamps.content_typefilters 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_automationsgets403on 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 gets404when its automation has no factory, and401on/factories/...routes. A user-auth caller gets an error on/worklog/.... - With
AUTOMATION_KV_SECRETunset,/worklog/...returns503and the user-auth routes still work. authorcannot be set by the caller. An entry written with a run token records the automation's id and name and therun_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.pyandutils/kv.py, the permission model inrouter.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_idON DELETE CASCADE,slug,name,created_at,updated_at) andworklog_entries(id,worklog_idON DELETE CASCADE, server-assignedcreated_at,content_type, nullabletitle,author_kind,author_id, nullableauthor_name, nullablerun_id, opaquebody) with the(worklog_id, created_at, id)index, and addsfactories.default_worklog_id(deferrable or initially nullable);alembic upgrade headcompletes 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
defaultanddefault_worklog_idpointing at it. -
POST /factoriescreates the factory'sdefaultworklog and sets it asdefault_worklog_idin the same transaction, so a new factory has exactly one worklog nameddefaultas its default. -
POST /factories/{slug}/worklogsadds worklogs withslugandnameeach unique within the factory (duplicate returns409); worklog slugs are immutable andPATCH .../worklogs/{worklog}changes onlynameand can set the default; renaming the default worklog leavesdefault_worklog_idpointing 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's409rule for live automations) removes its worklogs and entries through the foreign keys; the rows are gone after deletion. -
GET /factories/{slug}/worklogsreturnsentry_count,json_entry_countandlast_entry_atfor each worklog;GET /factoriesandGET /factories/{slug}return the factory-levellast_entry_at, the most recent entry across the factory's worklogs. -
POST /factories/{slug}/worklogs/{worklog}/entrieswithContent-Type: text/markdownreturns201with the server-assignedidandcreated_at, and a markdown body containing fenced JSON, CRLF line endings and non-ASCII text reads back byte-identical. - A valid
application/jsonentry is stored and read back as the received string (not re-serialized); invalid JSON returns422with the parse error and position; any otherContent-Typereturns415; invalid UTF-8 returns422; a body over the configurable 64 KiB default limit (AUTOMATION_WORKLOG_MAX_ENTRY_SIZE) returns413. - A markdown entry beginning
## INSTRUCTION: ...has titleINSTRUCTION: ...; an entry with no heading has its first non-empty line as title truncated to 120 characters; theX-Worklog-Titleheader overrides the derived title for both content types; JSON entries have no derived title. - A write or read to
/factories/{slug}/entriestargets the default worklog, and the same request to/factories/{slug}/worklogs/unknown/entriesreturns404(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 acreated_at;content_type=markdownandcontent_type=jsonfilter the list; each entry returnsauthoras{kind, id, name}andrun_id. - No route updates or deletes an entry.
- Any org member can read worklogs and entries; a caller without
manage_automationsgets403on writing entries and on worklog management; the local API key can do everything. - The run-token routes
GET /worklog,GET/POST /worklog/entriesandGET/POST /worklog/{worklog}/entriesaccept a run token only, resolve the factory through the run's automation, and return404when the automation has no factory; a run token on/factories/...returns401; 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); withAUTOMATION_KV_SECRETunset,/worklog/...returns503while the user-auth routes still work. -
authorcannot be supplied by the caller. A run-token entry recordsauthor_kind = automation,author_id= the automation id,author_name= the automation's name at write time andrun_id; a user entry recordsauthor_kind = user,author_id= the user id and a nullauthor_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
[-]Factories and worklogs: append-only, agent-writable logs scoped to a factory[/-][+]Worklogs: append-only logs scoped to a factory[/+]jpshackelford commentedon Nov 10, 2026
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.