Delegate work from GitHub to Factory Droid through the Sessions API.
- Task delegation. Comment
@factory <anything>on an issue or PR and Droid does it: implement, fix, explain, run skills and commands such assecurity-revieworverify. Follow-up comments continue the same session. - CI jobs. Automatic code review, diff security review (
security-reviewskill) and opt-in QA (qaskill) on every PR push. After a push, the same session reviews only the new commits. - Isolated Environment mode. Use a Factory Environment to provision one unlisted computer per issue/PR and lane, reused for follow-ups and deleted when the thread closes.
- Fire-and-forget. The action creates or reuses a session, sends one message and exits within seconds. Droid runs on your Droid Computer and writes results (PRs, comments, reviews) to GitHub itself.
- Quiet for outsiders. Authorization uses
author_association, so mentions from outside users don't start the job.
Factory's official droid-action is a good fit for reviewing PRs on the runner. This action exists because we needed four things it does not do:
| droid-action | factory-action |
|---|---|
Runs on the runner. It installs the Droid CLI and runs droid exec inside the job. The runner is busy until Droid finishes, and the job needs the repo's tooling. |
Calls the Sessions API and exits within seconds. Droid works on a persistent Droid Computer that already has the repo, its dependencies and tools (browser, ffmpeg). |
Review only. @droid supports fill, review, security and security --full. A bare @droid also starts a review. You cannot ask it to implement or fix something. |
@factory <anything> delegates any task: implement an issue, fix a review comment, explain code, run a skill or a plugin command. |
No session reuse. Every run starts a new droid exec. A follow-up instruction or a re-review after new commits starts from zero. |
One session per (repository, issue/PR, lane). Follow-up comments continue that session, and a re-review after a push looks only at the new commits. |
| Authorization is a permission check only. It checks write permission after the job has already started, so a mention from an outside user still starts a run and shows noise. | Uses author_association in the workflow's if: (the job never starts) and in the action, then falls back to the permission API for private org members. |
- Filter before the job starts. The example workflows check
author_associationand the trigger phrase in the job'sif:, so noise from outside users never starts a runner. - Parse and authorize. The action normalizes the webhook event into a trigger, skips bots, drafts and fork PRs, and authorizes the sender by
author_association, with the permission API as a fallback for private org members. Skips are quiet and reported through theskippedoutput. - Find the lane's session. Sessions are keyed by (repository, issue/PR number, lane), and the lane defaults to the mode (
taskfor mentions), so a human task, the code review and the security review on one PR each keep their own context. The mapping lives in a hidden marker inside a tracking comment the action writes; only comments written by the action's own token identity are trusted. - Reuse or create. With
computer-id, the action reuses the lane's session on that computer, or creates one. Withenvironment-id, it first finds the lane's Environment computer by its deterministic name (or creates it and waits for it to become active), then reuses or creates the session on it. - Send one message and exit. The action adds a reaction to the triggering comment, posts a single prompt (the mention text, or the mode's prompt with the diff and thread context), updates the tracking comment and finishes within seconds. The workflow run does not wait for Droid, so the check status never reflects the result.
- Droid does the work. Droid runs the task on the computer with its skills and tools, and writes results back to GitHub (PRs, comments, reviews) with the computer's own
ghandgitcredentials. Follow-up comments go to the same session.
- The Sessions API is enabled for your Factory organization. The API reference marks every Sessions endpoint as "enabled for selected organizations only", so confirm this before adopting the action.
- A Factory API key. Prefer a service account key, so sessions and billing belong to the service account. Store it as the secret
FACTORY_API_KEY. - A Droid Computer or Factory Environment with the repository cloned. Store the computer ID as
FACTORY_COMPUTER_ID, or the Environment ID asFACTORY_ENVIRONMENT_ID. See Computer setup and Environment setup.
.github/workflows/factory.yml, for @factory mentions:
name: Factory
on:
issue_comment: { types: [created] }
pull_request_review_comment: { types: [created] }
pull_request_review: { types: [submitted] }
issues: { types: [opened] }
permissions: {}
jobs:
delegate:
if: >-
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'),
github.event.comment.author_association ||
github.event.review.author_association || github.event.issue.author_association) && contains(github.event.comment.body || github.event.review.body || github.event.issue.body, '@factory')
runs-on: ubuntu-latest
permissions: { issues: write, pull-requests: write }
concurrency:
group: factory-${{ github.event.issue.number || github.event.pull_request.number }}
cancel-in-progress: false
steps:
- uses: knanao/factory-action@v0.1.0
with:
factory-api-key: ${{ secrets.FACTORY_API_KEY }}
computer-id: ${{ vars.FACTORY_COMPUTER_ID }}More workflows are in examples/: automatic PR review and security review, opt-in QA, a weekly full-repository security audit, a weekly wiki refresh and cleanup for closed threads.
To isolate each issue/PR lane on its own computer, replace computer-id with:
environment-id: ${{ vars.FACTORY_ENVIRONMENT_ID }}Use the same environment-id in every workflow, including cleanup. See Environment setup for snapshot, build-script and cleanup details.
Any text after @factory goes to Droid unchanged. To run a skill or plugin command, name it right after @factory, without a slash: @factory verify ... runs /verify. The names that work this way are set by the commands input (default: security-review, deep-security-review, qa, wiki, verify, qa-test, demo). Any other first word is just part of the request. review is left out on purpose: /review opens an interactive menu, so @factory review this PR is sent as a plain request.
@factory implement this issue
@factory the tests in this PR are flaky, fix them
@factory security-review this PR
@factory verify 123 -- clicking Save keeps the form values
- On an issue, Droid creates a branch and opens a PR that references the issue.
- On a PR, Droid checks out the PR and pushes to its head branch. If that push is rejected (e.g. a fork that does not allow edits from maintainers), Droid pushes its own branch and opens a PR against the PR's base branch instead.
- On a review comment, the file, line and diff hunk are included, and Droid replies in that review thread.
- Mentions in quoted replies (
> ...) and in code are ignored. - If Droid needs a decision, it posts the question as a comment and stops. Your
@factory ...reply goes to the same session.
| mode | Event | What Droid does |
|---|---|---|
review |
pull_request |
Code review of the diff, posted as one review with up to max-comments inline comments labeled [P0]–[P2] |
security |
pull_request |
/security-review on the diff. Inline [P0]–[P2] [security] findings; P3 findings go only in the summary |
deep-security |
schedule, workflow_dispatch |
/deep-security-review on the whole repository (see below) |
wiki |
schedule, workflow_dispatch |
/wiki on the whole repository (see below) |
qa |
pull_request |
/qa on the changed flows, posted as a pass/fail/blocked report. Opt-in, see QA |
cleanup |
issues / pull_request_target (closed) |
With computer-id, asks tracked sessions to remove their worktrees and local branches. With environment-id, deletes the thread's Environment computers |
custom |
any (e.g. schedule) |
Sends the prompt input with the repository/thread context |
- Drafts are skipped.
- PRs from forks are skipped, because secrets are not available to them.
- On
synchronize, a running session in that lane is interrupted, and Droid is told to review only<previous head>...<new head>and not to repeat findings. - Repository-specific rules are picked up from
.factory/skills/review-guidelines,.factory/skills/security-review-guidelinesand.factory/threat-model.md.
A full audit with the deep-security-review skill can take hours, so it runs on a schedule, not on every PR. Each run starts a new session.
- The skill normally asks about scope and options. Droid is told to audit the whole repository and pick the most thorough options itself, and to record its choices in the report.
- Findings can be unfixed vulnerabilities, so Droid never posts them publicly. Each P0–P2 finding becomes a draft repository security advisory, which only admins and security managers can read. Drafts that already exist are skipped. P3 findings stay in the report.
- The full report is written on the computer under
~/security-audits/<repo>-<YYYYMMDD>/. - The computer's GitHub credentials must be allowed to create security advisories (admin or security manager on the repository). If that fails, Droid opens one issue with only the finding counts, the reason and the report path, with no details.
See examples/factory-security-audit.yml.
The wiki skill generates comprehensive documentation for the whole repository, so it runs on a schedule, not on every push. Each run starts a new session and regenerates the wiki from scratch.
- The skill asks about scope and options. Droid is told to document the whole repository at the default branch and pick the skill's standard options itself.
- The wiki is uploaded to the Factory app, and the same pages are pushed to
droid-wiki/directly on the default branch, with no PR. If that push is rejected (for example branch protection), Droid opens one pull request titled "docs: refresh droid-wiki" instead. - The narrated video overview (
wiki-video-gen) is skipped by default; ask for it through thepromptinput. - The session removes its own worktree when it finishes: scheduled runs have no issue or PR whose close would trigger
cleanup. - The computer's push credentials must be allowed to push to the default branch.
See examples/factory-wiki.yml.
When Droid opens or updates a PR that changes what people see rendered (app screens, or output GitHub renders such as comments and summaries), it captures the same view before and after, uploads the evidence with the computer's gh credentials and embeds it in the PR body or a comment: PNG screenshots for static changes, MP4 (under 10 MB) plus GIF for interactions. If the evidence cannot be captured, it leaves the PR as a draft and explains why.
This is enforced through the session's system prompt and needs the Droid Control tools on the computer, see Computer setup.
action.yml is the reference for every input and output: its name, whether it is required, its default and what it does. This README does not repeat them.
Most workflows set only factory-api-key and exactly one of computer-id or environment-id. Usage and examples/ show the other inputs in context.
Every record the action writes to the run log is one structured line in logfmt, e.g. level=info event=session.created session_id=sid-1. Records stay readable in the Actions UI but remain machine-parseable when the run log is exported (Loki logfmt, Vector, grep).
| Level | Emitted for | Actions UI |
|---|---|---|
debug |
Diagnostics, e.g. the tracking comment a lane reuses | Hidden unless enabled below |
info |
Skips, authorization, session and Environment computer lifecycle, cleanup | Plain log line |
notice |
An outside user is denied | Notice annotation |
warning |
Recoverable problems (reaction, tracking comment, message timeout) | Warning annotation |
error |
The run failed, with the stack | Error annotation |
FACTORY_ACTION_LOG_LEVEL (debug | info | notice | warning | error) filters records; by default everything from info up is emitted. GitHub's own ACTIONS_STEP_DEBUG flag also turns on debug.
Tracing stays inside the workflow run. The action uses W3C Trace Context IDs and OpenTelemetry's conventions to tie its log records together, without bundling an OpenTelemetry SDK, exporting anything, or sending trace headers to the Factory or GitHub API:
- Trace context. If the step's environment has
TRACEPARENT, as defined by OpenTelemetry's environment variable carrier, the run joins that trace. Otherwise it starts a new one. - Correlation. Every log record ends with
trace_id=... span_id=..., therun.startedrecord adds the OpenTelemetry CI/CD attributes (cicd.pipeline.name,cicd.pipeline.run.id,cicd.pipeline.run.url.full,cicd.pipeline.task.name,vcs.repository.url.full,vcs.ref.head.revision), and thetrace-idoutput and job summary show the trace ID.
To see the run as spans in an OpenTelemetry backend, export the workflow run after it completes with a workflow_run exporter such as otel-cicd-action, and correlate it with the action's records through cicd.pipeline.run.id. A workflow that already traces its jobs can pass the job's span context to the step in TRACEPARENT.
GITHUB_TOKEN expires when the job ends, so Droid writes to GitHub with credentials on the computer, not with the workflow token.
-
GitHub write access. Factory sets up the computer's GitHub credentials, and the computer's owner decides whose name Droid's comments, reviews, commits and PRs appear under:
- Computer owned by a person: Factory uses that person's personal GitHub integration (a user-to-server
ghu_token). Droid contributes as that user account. Installing the Factory Droid GitHub App on the repository does not change this: the app installation only decides which repositories the token can reach. - Computer owned by a service account (unverified): according to Identity & Access, a service account's Git access uses the organization's GitHub App installation. Droid would then contribute as the app's bot account. Whether these credentials also authenticate
gh, and whether they refresh in sessions longer than an hour, has not been verified.
Check it with
gh auth statusandgh pr liston the computer. - Computer owned by a person: Factory uses that person's personal GitHub integration (a user-to-server
-
Repository clone. The action resolves
cwdfrom the computer's cloned repositories by name (e.g./home/factory-user/repos/<repo>). If that is ambiguous, setcwd. Sessions share that clone, so each session is told to create and use its own git worktree at<cwd>.worktrees/<lane>-<number>on branchfactory/<lane>-<number>. The shared clone's checkout is never changed. (The API'ssessionSettings.worktreesetting has no effect, so the action does not rely on it.) Addexamples/factory-cleanup.ymlso worktrees and local branches are removed when an issue or PR closes. A session is reused only on the computer it runs on: ifcomputer-idchanges, the next request starts a new session. -
Droid Control and QA tools. Needed for UI evidence,
verify,qa-testandqamode:droid plugin marketplace add https://github.com/Factory-AI/factory-plugins droid plugin install droid-control@factory-plugins --scope user # plus the runtime tools you need: agent-browser (Chromium), tuistory, ffmpegThe app under test must be startable on the computer or reachable, e.g. a staging URL.
Use an organization Environment, especially when the workflow uses a service-account API key. Clone the target repository and install its dependencies in the Environment setup steps. If the workflow uses UI evidence, verify, qa-test or qa, install the Droid Control tools there as well (see Computer setup).
Build scripts should leave tracked files unchanged. For example, use the repository's lockfile-based install (npm ci, bun install --frozen-lockfile, or the equivalent), not commands that rewrite package.json or the lockfile. Environment build steps do not receive Runtime secrets. The Environment is a snapshot: computers created from it keep their own state, and rebuilding the Environment does not update existing computers. New issues/PRs use the newer snapshot.
The action creates one persistent, unlisted computer per issue/PR and lane, found again by its deterministic name. Follow-ups reuse that computer; closing the issue/PR deletes it (see examples/factory-environment-cleanup.yml). Runs without an issue/PR, such as scheduled deep-security audits and workflow_dispatch, are not covered by cleanup; delete those computers manually from Factory until an automatic sweep mode is available.
The first run waits for the computer to become active, up to provision-timeout-sec (300 seconds by default). If a run is cancelled during provisioning, the next run finds the same computer and resumes waiting instead of creating a duplicate.
Skills and Droid Control commands run through mentions, named without a slash (see Mentions). CI modes cover the ones that need no conversation.
| Feature | What it does | How to use | Notes |
|---|---|---|---|
| Code review (built-in skill) | Reviews the diff for bugs, security problems and breaking changes. Run it on every PR | mode: review, or @factory review this PR |
Prompt-based; review is not a commands name (see Mentions) |
security-review (built-in skill) |
Security review of the diff (data flows, authn/authz, injection, …). Run it on every PR | mode: security, or @factory security-review |
Static analysis; no special requirements |
deep-security-review (built-in skill) |
Multi-phase audit of the whole repository, for periodic audits | mode: deep-security (scheduled), or @factory deep-security-review |
Can take hours. Findings go to draft security advisories, see CI modes. In a mention, its questions come back as comments |
wiki (built-in skill) |
Comprehensive documentation of the whole repository, uploaded to the Factory app | mode: wiki (scheduled), or @factory wiki |
The pages are also pushed to droid-wiki/ on the default branch, see CI modes |
qa (repository skill) |
Runs the repository's own QA flows (created by /install-qa) against what the PR changed |
mode: qa (opt-in), or @factory qa |
Run /install-qa once and commit .factory/skills/qa*. The app must be reachable from the computer. Without the skill, Droid posts setup steps and stops |
verify (Droid Control) |
Checks one claim by running the app, and reports CONFIRMED / REFUTED / INCONCLUSIVE with evidence | @factory verify 1234 -- saving keeps the form values |
For "is this bug really fixed?" and "does this report reproduce?". A refuted claim is a valid result |
qa-test (Droid Control) |
Plans and runs test steps against a URL, CLI or Electron app, with a pass/fail table per step | @factory qa-test https://staging.example.com -- log in, create a project |
Broader than verify. Droid designs the steps if none are given. Questions come back as comments |
demo (Droid Control) |
Records a demo video of a feature or PR, side by side for before/after changes | @factory demo 1234 |
Experimental. It waits for plan approval: reply @factory approve to continue |
In short: verify checks one point, qa-test walks through a flow, qa runs the repository's QA on every PR, and demo makes a video to show.
Droid also picks a matching skill on its own when the request fits the skill's description, so plain requests such as "check this for security issues" often work. Name the skill (@factory security-review) when it must run every time, and in CI, where the modes always name it.
Droid Control commands need the plugin and its tools on the computer (see Computer setup). To use another skill or plugin command this way, add its name to the commands input.
- Authorization. The workflow
if:filters byauthor_associationbefore the job starts. The action checks again, falls back to the permission API for private org members, and denies quietly. - Loops. Bots are ignored unless listed in
allowed-bots. Droid's own posts carry<!-- factory-droid -->and are ignored. Droid is told never to write the trigger phrase. - Forks. CI modes skip fork PRs. Do not use
pull_request_target. A maintainer can still ask for a review explicitly with@factory review this. - Prompt injection. GitHub content is passed as clearly delimited untrusted data, and the system prompt tells Droid not to follow instructions in it. Use a dedicated computer and least-privilege GitHub credentials. Remember that
autonomy-level: highlets Droid run commands and push. - Why
autonomy-level: high. Belowhigh, a command Droid rates as high-risk (e.g.git push,git branch -D) waits for an approval that never comes, and the session staysrunninguntil it is interrupted. Autonomy is fixed when the session is created; changing it later does not affect a reused session. - No secrets to Droid. The workflow token is used only for the reaction and the tracking comment.
- Data handling. The action sends the thread's title and URL, the triggering text and the requester's login (mentions) or the PR description (
review,security,qa) to the Factory API and nowhere else; the tracking comment stores only IDs and SHAs. Do not put secrets or personal data in requests to Droid. See Data handling and personal data for the details, retention and deletion.
- CI status does not reflect results. The run ends before Droid finishes, so the check cannot be used as a merge gate.
- Tracking with GitHub App tokens. The tracking comment is recognized when it was written by
github-actions[bot](the defaultGITHUB_TOKEN) or by a PAT user. If you pass a GitHub App token asgithub-token, sessions are not reused. - Messages to a running session are merged into the current turn. Droid receives a follow-up sent while it is working as "steering" for the current task, not as a new turn. CI lanes therefore interrupt a running session before sending the new push.
Development uses Bun (version in .bun-version) as the package manager, test runner and bundler. The action itself still runs on GitHub's node24 runtime: bun build --target=node bundles it into dist/index.js. To develop without installing anything locally, open the repository in the dev container (.devcontainer/): it provides the pinned Bun, Node.js 24 and installed dependencies, and works with VS Code Dev Containers, GitHub Codespaces and the Dev Containers CLI.
bun install # also enables the pre-commit hook in .githooks/
bun run all # format, lint, typecheck, static checks, test, bundle dist/
bun run check # every check (lint, knip, dependency-cruiser, jscpd, size budgets), no testsTo run the action against a local (simulated) event, copy .env.example to .env, fill in the required values (Factory API key, a Droid Computer id or Environment id, a GitHub PAT and a webhook payload file) and run bun run local-action. .env is gitignored; never commit real keys.
To run the action end to end offline, against a local mock of the Factory Sessions API and the GitHub REST API, use bun run qa:mock and bun run qa:run <event-file>. See .factory/skills/qa/SKILL.md for the scenarios and what to check.
Unit tests live in __tests__/ and mock the GitHub and Factory boundaries. bun run ci-test enforces at least 90% line and function coverage for every file under src/. __tests__/integration/ goes further: it builds the bundle, runs it as a subprocess against localhost stubs of both APIs and checks the full path a runner takes (inputs, event parsing, authorization, session reuse, prompts, tracking state and outputs). Run it alone with bun run test:integration.
dist/ is committed. The Check Transpiled JavaScript workflow fails if it is stale. Releases are cut with the Release workflow (Actions tab > Release > Run workflow on main): it tags vX.Y.Z, publishes a GitHub release with generated notes and moves the corresponding major tag (for v0.3.0, that is v0).
Procedures for failed or skipped runs, Environment computers, API key rotation, repository CI failures and release rollback are in docs/runbooks/.
See CONTRIBUTING.md. To report a security vulnerability, see SECURITY.md.