diff --git a/.claude/skills/post-review/scripts/post-audit.mjs b/.claude/skills/post-review/scripts/post-audit.mjs index 7f04145..c094aeb 100644 --- a/.claude/skills/post-review/scripts/post-audit.mjs +++ b/.claude/skills/post-review/scripts/post-audit.mjs @@ -63,6 +63,8 @@ const note = (id, text) => findings[id].notes.push(text); // ---------------------------------------------------------------- source pass const plain = (s) => s + // A bilingual note's translation (
) is not read in the same pass; same rule as reading.ts. + .replace(/]*\bdata-alt-lang\b[^>]*>[\s\S]*?<\/section>/gi, ' ') .replace(/||/gi, ' ') .replace(/```[\s\S]*?```/g, ' ') .replace(/<[^>]+>/g, ' ') diff --git a/public/_redirects b/public/_redirects index b4c600a..aa6f924 100644 --- a/public/_redirects +++ b/public/_redirects @@ -1 +1,5 @@ /rss.xml /feed.xml 301 +/posts/kiln-automation-flow-en /posts/kiln-automation-flow/#en 301 +/posts/kiln-automation-flow-en/ /posts/kiln-automation-flow/#en 301 +/posts/kiln-orca-connector-en /posts/kiln-orca-connector/#en 301 +/posts/kiln-orca-connector-en/ /posts/kiln-orca-connector/#en 301 diff --git a/src/content/posts/kiln-automation-flow-en.md b/src/content/posts/kiln-automation-flow-en.md deleted file mode 100644 index 8ac47cd..0000000 --- a/src/content/posts/kiln-automation-flow-en.md +++ /dev/null @@ -1,173 +0,0 @@ ---- -title: "How Kiln turns an issue into a release" -description: "Reading the source of Kiln (kilnflow.dev): how an issue labelled kiln:ready goes through AI development, an independent review by a second agent, Kiln's own merge queue and auto-tagging, and is published by the server with no human step." -growth: seedling -planted: 2026-11-23T01:41:38+08:00 -lastTended: 2026-11-23T01:41:38+08:00 -draft: false -lang: "en" -tags: - - "ai-agents" - - "workflow" - - "code-review" - - "self-hosting" - - "open-source" ---- - - - -
-

中文版:Kiln 怎么把一个 Issue 自动变成一次发布 · Companion post: How kiln-orca runs Kiln's work through agents in Orca

-

Kiln is a self-hosted CI. One small server keeps all state in Postgres; build machines and AI machines connect out to it to pick up work. With the optional AI nodes attached, a GitHub issue labelled kiln:ready is designed and coded by an AI, reviewed by a different agent, then merged, tagged and released, with no human clicking anything in between.

-

This post follows that path through the code. I read commit e3bff51, source only: nothing was built or run. File paths are relative to internal/server/ unless stated otherwise.

- -

In one sentence: GitHub only sends events and receives results; deciding, scheduling, merging, tagging and publishing all happen in Kiln's server, chained together by one habit: every state change commits in the same transaction as the message it causes.

- -

Who talks to whom

-
GitHubApp on your own account
webhook
kiln-serverPostgres is the only state · only it writes to GitHub
hands out work to machines that poll for it; publishes artifacts
kiln-runner × NCI: host / Docker / BuildKit
kiln-orca × NAI: Orca + Codex / Claude Code
Release targetsRelease · npm · images · HTTP
Build and AI machines connect outward, so they can sit at home or behind NAT; the GitHub App key and release credentials live only on the server, and only the server writes to GitHub.
-

Inside the server, CI and AI are separate domains with different tables, schedulers and wire protocols (runner.v1 and airunner.v2). They meet only in the assembly file server.go, through narrow interfaces, or through events in a shared outbox table. internal/archtest fails the tests if one domain imports another or queries its tables, so the boundary is checked by a machine, not just described in a doc.

- -

One real pass through the loop

-

Kiln builds itself with Kiln. On 22 November 2026, the day after it was open-sourced, three i18n issues labelled kiln:ready went through the whole chain. Times are UTC, from commit and tag metadata; review outcomes are from the PR pages.

-
- - - - - - - - - -
TimeWhat happenedWho
09:44Pushed to kiln/dev-6 for issue #2; PR #9 openedClaude Code writes; server opens the PR
after 09:4419 checks run. AI review fails: one medium finding, a test that could not catch the bug it claimed to coverCodex, as a PR review
10:07Repair round 1: test rewritten, disposition comment postedClaude Code
before 10:19Second review passes; kiln:merge addedCodex; server
10:19Squash-merged as 11deef3; tag v1.0.3 created on itkiln-runner[bot]
10:20Release v1.0.3 published (12 assets); issue #2 closedserver
-

PR #10 also took one repair round (merged 11:41, v1.0.4); PR #11 passed review first time (merged 12:32, v1.0.5). From first commit to public release: 36, 45 and 13 minutes.

- -

The CI part: from webhook to a green Check Run

-
Intakeverify · store · reply 202
processed in background
Planwhole job graph fixed
dependencies done
Action keyfingerprint of all inputs
no cache hit
Acquireone tx: epoch+1 · lease
heartbeats
Runner executessees only its inputs
Complete
Outboxwrites Check Run
✓ cache hit: job succeeds without a runner
The action key is where this chain saves time: a job whose inputs have not changed does not run again.
-

1. Intake: verify, store, answer

-

GitHub posts the event to /webhook. The handler checks the HMAC-SHA256 signature with a constant-time comparison, stores the event in events keyed by delivery id, and returns 202. Nothing else happens in the request.

-

A background loop then processes stored events one by one. Installations from accounts outside KILN_ALLOWED_ACCOUNTS are rejected and uninstalled; pull requests from forks are always dropped, with no switch to allow them; an event already superseded by a newer one for the same ref is skipped.

-

ingest/webhook.go:35 · ingest/event.go:159 · ingest/push.go:308

-

2. Plan: the job graph is fixed before anything runs

-

The planner reads .kiln/workflows/*.yml at the commit being built. For a PR that is the head commit, not a merge with the target branch. The syntax follows GitHub Actions minus uses:; expressions can only reference values known at planning time, so matrices, if: and needs are fully expanded here.

-

The run, its jobs, concurrency-group membership and the first Check Run records are written in one transaction. A broken workflow still produces a run, marked failed immediately, so the commit shows a red check carrying the error.

-

ci/planner/planner.go:234,342 · internal/workflow/

-

3. Don't build what was already built

-

When a job's dependencies finish, the engine hashes everything that can affect it into an action key: the digest of its input files, env, steps, image digest, runtime digests, upstream output digests. Secrets count by name only.

-

If action_cache has the key, the job succeeds without touching a runner; if an identical job is already running, this one follows its result. That is why Kiln's own workflow keeps the version-stamped build in a separate job: after merge, the tests keep the same key and are not rerun.

-

ci/engine/engine.go:205,372

-

4. Acquire: claim, epoch+1 and lease in one transaction

-

Runners hold a long-poll Acquire open. The scheduler locks the runner's row, takes up to 300 candidate jobs with FOR UPDATE SKIP LOCKED in priority-then-age order, and filters by platform, pool, executor, declared CPU and memory (against that machine's free capacity) and per-repo concurrency limits.

-

The chosen job becomes running, its epoch increments, an attempt row is inserted and a lease is set, in that same transaction. Every later write from the runner must carry the matching epoch, so a runner that lost its lease can never overwrite a newer attempt.

-

ci/scheduler/reserve.go:211,730 · ci/runnerapi/scheduler.go:140

-

5. Execute on the runner

-

The runner checks out only the files the job's inputs match, with no .git; installs Go, Node and pnpm verified against digests in .kiln/runtimes.lock; pulls upstream outputs from the content-addressed store; and runs steps on the host or in a container. Container jobs default to --network none.

-

Source is fetched with a token the server issues for that one fetch, scoped to that one repository, and revokes afterwards. Secrets arrive over RPC, live only in step environment variables, and are masked in logs in raw, base64 and URL-encoded form.

-

Heartbeats every few seconds renew the lease and carry cancellation back. Outputs go to presigned upload URLs, and Complete ends the attempt and writes the cache entry.

-

internal/runner/execute.go:61 · internal/runner/source.go:178 · ci/runnerapi/runnerapi.go:392

-

6. Report through the outbox

-

Each state change writes an outbox row in the same transaction. The row holds only an id, so several changes collapse into one pending delivery. A worker turns rows into Check Runs, looking up by external id before creating, with exponential backoff and a dead-letter state after 20 tries.

-

When the last job of a PR's run finishes, the engine emits pr.verified. The merge queue and AI development both wait on that one event.

-

outbox/worker.go:86 · ci/cicheck/checkrun.go:40 · server.go:390

- -

From green checks to a release

-
CI + AI reviewon the PR head
pr.verified: all required pass
Merge queueone executor per repo
merges; tag recorded in same tx
Auto-tagnext vX.Y.Z
plans the tag's run directly
Publish jobruns on the server
↺ behind the target branch: queue updates it, new head is verified again
The only loop is the branch update: a PR that fell behind is updated by the queue and must pass again on the new head before it merges.
-

Merge queue

-

Kiln uses neither GitHub's merge queue nor branch protection. A PR enters the queue when someone adds kiln:merge, or automatically once every entry under required has passed, if .kiln/merge.yml on the default branch sets auto: true. That config is read only from the default branch, so a PR cannot lower its own bar.

-

Each repository has one executor, holding a Postgres advisory lock. Every pass re-reads the PR from GitHub and decides from scratch: wait, update the branch, merge, or remove it with a reason. The merge request carries the head SHA it verified, and GitHub refuses if the head has moved.

-

mergequeue/process.go:46,894 · mergequeue/decide.go:208 · mergequeue/autoenqueue.go:85

-

Auto-tag and publish

-

The merge, the queue-entry update and a tag record commit together. The tag worker reads existing tags, picks the next version (patch by default; release:minor, release:major and release:skip labels change that), creates the ref, then calls the CI planner directly to plan a push run for the tag.

-

A job with a release: block has no steps and never reaches a runner. The server stages every target first (npm integrity check, image layers pushed by digest, a draft GitHub Release), passes a last cancel point, then commits in the order npm, image tags, HTTP uploads, GitHub Release. On a rerun, identical content already on a target counts as success.

-

autotag/autotag.go:315,684,932 · ci/publish/job.go:52 · ci/publish/targets.go:44

- -

The AI loop on top

-

An AI node is a machine with the Orca desktop app and the kiln-orca connector. Its role, review or development, is fixed by its enrolment token. The connector takes a task, starts a coding agent in a fresh Orca worktree, and hands the result back. The agent's only way to talk to Kiln is the kiln-orca task command; the companion post covers that side.

-

Independent review

-

Opening or pushing to a PR plans a review request alongside the CI runs. The review brief, .kiln/agent/review.md, is read from the PR's base, so a PR cannot rewrite its own review standard. The agent must return a strict JSON report; only "no issues" passes. The result is posted as a PR review and as the ai-review check.

-

The server records which agents worked on each development item and refuses to give the review to any of them: checked once when planning and again when a node tries to take the task. Kiln's own config has Claude Code developing and Codex reviewing.

-

The review brief requires mutation checks: break the changed logic in a scratch copy and confirm a test fails. Both failed reviews in the table above were of that kind.

-

ai/review/plan.go:135,568 · ai/review/tasktype.go:104,178 · ai/review/publish.go:124

-

Development from an issue

-
developingclaimed from the pool
agent delivers
deliveringserver checks it
server pushes, opens PR
pr_openwaits for CI · review · merge
merge queue merges
merged
↺ findings / CI red / conflict: fixing, same PRrounds used up: blocked, waits for a person
Work-item states in dev_work_items (terminal states stopped and no_change omitted). A repository runs one unfinished item at a time; waiting in pr_open holds no node capacity.
-
    -
  • Pool. Open issues carrying kiln:ready are mirrored into dev_pool from Issues webhooks.
  • -
  • Select and claim. A development node is offered the candidates, picks a batch that fits one PR, and claims it; the server re-reads each issue from GitHub before accepting.
  • -
  • Deliver. The agent designs and implements in one run and pushes to a throwaway kiln/attempt-<id> branch. If it judges one PR is not enough, it first delivers a Markdown-only design PR; the server starts implementation automatically once that merges.
  • -
  • Promote. The server checks the delivery, fast-forwards the formal branch kiln/dev-<item> with a short-lived token of its own, and opens the PR itself. Agent-written titles and bodies are defused so they cannot mention people or close unrelated issues.
  • -
  • Hold. Deliveries that touch .kiln/, .github/, AGENTS.md, CLAUDE.md, .claude/ or .codex/, exceed 300 files or 100 commits, or declare a change to one of the project's 23 confirmed decisions get kiln:hold and wait for a person.
  • -
  • Repair. Review findings, real CI failures and merge conflicts each send the same item back for another round on the same PR, up to max_fix_rounds (10 in Kiln's own config).
  • -
-

ai/aidev/pool.go:49 · ai/aidev/claim.go:84 · ai/aidev/executor.go:224,627 · ai/aidev/fix.go:162 · ai/aidev/state.go:14

- -

Four rules that keep it consistent

-
- - - - - - - -
RuleWhat it preventsWhere
A state change and its outbound message commit togetherA green job with no Check Run; a merge with no tag recordoutbox/, shared by all domains
Every job and task write carries the epochA runner that lost its lease overwriting a newer attemptci/engine/engine.go:569, ai/lease.go:21
One executor per object, deciding from fresh stateTwo processes merging or tagging the same thing; acting on stale readsmergequeue/process.go:43, autotag/autotag.go:315
Writes without an idempotency key record intent first and are never blindly retriedDuplicate comments, reviews or issue closures after a lost responsemergequeue/closeissues.go:180, ai/review/publish.go:124
-

A fifth, narrower rule: no build or AI machine stores a git credential. Each clone, fetch or push asks the server for a token scoped to one repository, and the server revokes it when the operation or the attempt ends (gitcred/).

- -

What you configure

-
- - - - - - - - - - - -
File or labelControlsRead from
.kiln/workflows/*.ymlJobs, matrices, containers, services, release targetsThe commit being built
.kiln/runtimes.lockGo, Node, pnpm, Bun versions and per-platform digestsThe commit being built
.kiln/merge.ymlMerge method, required checks, auto-enqueue, tag rule, allowed target branchesDefault branch only
.kiln/agent/config.ymlWho reviews, who develops, platforms, timeouts, repair roundsReview: PR head; development: default branch
review.md / development.mdThe briefs given to the two agentsPR base / default branch
kiln:ready / kiln:skipPut an issue into / keep it out of the AI task poolIssue
kiln:merge / kiln:holdEnter the merge queue / block auto-enqueuePR
release:minor / major / skipVersion bump for the tag created after mergePR, frozen at merge
-

Secrets, variables and environments are stored in Kiln, encrypted with the server's master key, not in GitHub settings. Logs, artifacts and caches are kept for 12 hours; only results are kept long-term.

- -

What I took away

-

I read six subsystems in depth and found no high-severity defects; what is worth fixing clusters around the things the design assumes are friendly. For example: when a missed webhook is recovered by reconciliation, the push loses its "was this a bot" flag, so a third-party bot's tag can still publish; the write token a development node can get covers the whole repository; and kiln:ready approves an issue number, not its text, so an edited issue body is what the agent builds. Each of these only matters once the trust boundary widens: a third-party bot with push access, a prompt-injected agent, a malicious dependency.

-

The bigger risks are not in the code: there is a single human maintainer, the design docs live in a private Outline, and CI logs are not public.

-
diff --git a/src/content/posts/kiln-automation-flow.md b/src/content/posts/kiln-automation-flow.md index edcbfaa..773446e 100644 --- a/src/content/posts/kiln-automation-flow.md +++ b/src/content/posts/kiln-automation-flow.md @@ -52,10 +52,20 @@ tags: .html-embed .fr .fa i::after{right:auto;top:auto;left:-4px;bottom:-2px;border-top:8px solid currentColor;border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:0} .html-embed .fr .fa span{width:12em;text-align:left} } +.html-embed .lsr{position:absolute;opacity:0;width:1px;height:1px;margin:0;pointer-events:none} +.html-embed .lsw{display:inline-flex;gap:2px;background:var(--muted);border-radius:999px;padding:3px;margin:0 0 20px} +.html-embed .lsw label{padding:4px 16px;border-radius:999px;font-size:14px;line-height:1.5;cursor:pointer;color:var(--foreground);user-select:none} +.html-embed #lang-zh:checked ~ .lsw label[for="lang-zh"],.html-embed #lang-en:checked ~ .lsw label[for="lang-en"]{background:var(--foreground);color:var(--background)} +.html-embed #lang-zh:focus-visible ~ .lsw label[for="lang-zh"],.html-embed #lang-en:focus-visible ~ .lsw label[for="lang-en"]{outline:2px solid var(--accent);outline-offset:2px} +.html-embed #lang-zh:checked ~ .le,.html-embed #lang-en:checked ~ .lz{display:none} +.html-embed .alt-title{font-size:1.35em;font-weight:600;line-height:1.35;margin:0 0 12px}
-

English version: How Kiln turns an issue into a release · 姊妹篇:kiln-orca 怎么让 Orca 里的 Agent 干 Kiln 的活

+ + +
+

Kiln 是一套自托管的 CI:一台小 Server 把全部状态放在 Postgres 里,构建机和 AI 执行机都从自己那边连过来领活。接上可选的 AI 节点之后,一个打了 kiln:ready 标签的 GitHub Issue 会被 AI 设计、写代码、由另一个 Agent 审计,然后合并、打 tag、发布,中间不需要人点任何按钮。

这篇顺着这条路读它的代码。我读的是 commit e3bff51,只读源码,没有构建,也没有运行。下文的文件路径如无说明,都相对于 internal/server/。

@@ -120,7 +130,7 @@ tags:

autotag/autotag.go:315,684,932 · ci/publish/job.go:52 · ci/publish/targets.go:44

叠在上面的 AI 循环

-

AI 执行节点是一台装了 Orca 桌面版和连接器 kiln-orca 的机器,角色(审计或开发)在注册时由令牌决定。连接器领一个任务,在新的 Orca 工作区里启动编程 Agent,再把结果交回。Agent 和 Kiln 打交道只有一个入口:kiln-orca task 命令。

+

AI 执行节点是一台装了 Orca 桌面版和连接器 kiln-orca 的机器,角色(审计或开发)在注册时由令牌决定。连接器领一个任务,在新的 Orca 工作区里启动编程 Agent,再把结果交回。Agent 和 Kiln 打交道只有一个入口:kiln-orca task 命令;这一侧的细节见姊妹篇。

独立审计

PR 打开或推送时,和 CI run 一起规划一个审计请求。审计说明 .kiln/agent/review.md 从 PR 的 base 读,PR 改不了自己的审计标准。Agent 必须交回格式严格的 JSON 报告,只有「没有问题」才算通过;结果发为 PR review 和 ai-review 检查。

Server 记下每个开发工作项用过哪些 Agent,审计时拒绝派给其中任何一个:规划时检查一次,节点来领任务时再检查一次。Kiln 自己的配置是 Claude Code 开发、Codex 审计。

@@ -169,4 +179,131 @@ tags:

读完的几点看法

我把六个子系统各读了一遍,没有找到高危问题;值得改的地方集中在设计上默认可信的那些对象。例如:漏掉 webhook 后补对账时,push 不再带「是不是 Bot」的标记,第三方 Bot 推的 tag 可能照常发布;开发节点拿到的写权限 token 覆盖整个仓库;kiln:ready 批准的是 Issue 编号而不是正文,之后改了正文,Agent 照新内容做。这些都只在信任边界被拉宽时才要紧(第三方 Bot 有推送权限、Agent 被提示注入、依赖里混进恶意代码)。

更大的风险不在代码里:只有一位人类维护者,设计文档在私有的 Outline 里,CI 日志不对外公开。

+
+
+

How Kiln turns an issue into a release

+

Kiln is a self-hosted CI. One small server keeps all state in Postgres; build machines and AI machines connect out to it to pick up work. With the optional AI nodes attached, a GitHub issue labelled kiln:ready is designed and coded by an AI, reviewed by a different agent, then merged, tagged and released, with no human clicking anything in between.

+

This post follows that path through the code. I read commit e3bff51, source only: nothing was built or run. File paths are relative to internal/server/ unless stated otherwise.

+ +

In one sentence: GitHub only sends events and receives results; deciding, scheduling, merging, tagging and publishing all happen in Kiln's server, chained together by one habit: every state change commits in the same transaction as the message it causes.

+ +

Who talks to whom

+
GitHubApp on your own account
webhook
kiln-serverPostgres is the only state · only it writes to GitHub
hands out work to machines that poll for it; publishes artifacts
kiln-runner × NCI: host / Docker / BuildKit
kiln-orca × NAI: Orca + Codex / Claude Code
Release targetsRelease · npm · images · HTTP
Build and AI machines connect outward, so they can sit at home or behind NAT; the GitHub App key and release credentials live only on the server, and only the server writes to GitHub.
+

Inside the server, CI and AI are separate domains with different tables, schedulers and wire protocols (runner.v1 and airunner.v2). They meet only in the assembly file server.go, through narrow interfaces, or through events in a shared outbox table. internal/archtest fails the tests if one domain imports another or queries its tables, so the boundary is checked by a machine, not just described in a doc.

+ +

One real pass through the loop

+

Kiln builds itself with Kiln. On 22 November 2026, the day after it was open-sourced, three i18n issues labelled kiln:ready went through the whole chain. Times are UTC, from commit and tag metadata; review outcomes are from the PR pages.

+
+ + + + + + + + + +
TimeWhat happenedWho
09:44Pushed to kiln/dev-6 for issue #2; PR #9 openedClaude Code writes; server opens the PR
after 09:4419 checks run. AI review fails: one medium finding, a test that could not catch the bug it claimed to coverCodex, as a PR review
10:07Repair round 1: test rewritten, disposition comment postedClaude Code
before 10:19Second review passes; kiln:merge addedCodex; server
10:19Squash-merged as 11deef3; tag v1.0.3 created on itkiln-runner[bot]
10:20Release v1.0.3 published (12 assets); issue #2 closedserver
+

PR #10 also took one repair round (merged 11:41, v1.0.4); PR #11 passed review first time (merged 12:32, v1.0.5). From first commit to public release: 36, 45 and 13 minutes.

+ +

The CI part: from webhook to a green Check Run

+
Intakeverify · store · reply 202
processed in background
Planwhole job graph fixed
dependencies done
Action keyfingerprint of all inputs
no cache hit
Acquireone tx: epoch+1 · lease
heartbeats
Runner executessees only its inputs
Complete
Outboxwrites Check Run
✓ cache hit: job succeeds without a runner
The action key is where this chain saves time: a job whose inputs have not changed does not run again.
+

1. Intake: verify, store, answer

+

GitHub posts the event to /webhook. The handler checks the HMAC-SHA256 signature with a constant-time comparison, stores the event in events keyed by delivery id, and returns 202. Nothing else happens in the request.

+

A background loop then processes stored events one by one. Installations from accounts outside KILN_ALLOWED_ACCOUNTS are rejected and uninstalled; pull requests from forks are always dropped, with no switch to allow them; an event already superseded by a newer one for the same ref is skipped.

+

ingest/webhook.go:35 · ingest/event.go:159 · ingest/push.go:308

+

2. Plan: the job graph is fixed before anything runs

+

The planner reads .kiln/workflows/*.yml at the commit being built. For a PR that is the head commit, not a merge with the target branch. The syntax follows GitHub Actions minus uses:; expressions can only reference values known at planning time, so matrices, if: and needs are fully expanded here.

+

The run, its jobs, concurrency-group membership and the first Check Run records are written in one transaction. A broken workflow still produces a run, marked failed immediately, so the commit shows a red check carrying the error.

+

ci/planner/planner.go:234,342 · internal/workflow/

+

3. Don't build what was already built

+

When a job's dependencies finish, the engine hashes everything that can affect it into an action key: the digest of its input files, env, steps, image digest, runtime digests, upstream output digests. Secrets count by name only.

+

If action_cache has the key, the job succeeds without touching a runner; if an identical job is already running, this one follows its result. That is why Kiln's own workflow keeps the version-stamped build in a separate job: after merge, the tests keep the same key and are not rerun.

+

ci/engine/engine.go:205,372

+

4. Acquire: claim, epoch+1 and lease in one transaction

+

Runners hold a long-poll Acquire open. The scheduler locks the runner's row, takes up to 300 candidate jobs with FOR UPDATE SKIP LOCKED in priority-then-age order, and filters by platform, pool, executor, declared CPU and memory (against that machine's free capacity) and per-repo concurrency limits.

+

The chosen job becomes running, its epoch increments, an attempt row is inserted and a lease is set, in that same transaction. Every later write from the runner must carry the matching epoch, so a runner that lost its lease can never overwrite a newer attempt.

+

ci/scheduler/reserve.go:211,730 · ci/runnerapi/scheduler.go:140

+

5. Execute on the runner

+

The runner checks out only the files the job's inputs match, with no .git; installs Go, Node and pnpm verified against digests in .kiln/runtimes.lock; pulls upstream outputs from the content-addressed store; and runs steps on the host or in a container. Container jobs default to --network none.

+

Source is fetched with a token the server issues for that one fetch, scoped to that one repository, and revokes afterwards. Secrets arrive over RPC, live only in step environment variables, and are masked in logs in raw, base64 and URL-encoded form.

+

Heartbeats every few seconds renew the lease and carry cancellation back. Outputs go to presigned upload URLs, and Complete ends the attempt and writes the cache entry.

+

internal/runner/execute.go:61 · internal/runner/source.go:178 · ci/runnerapi/runnerapi.go:392

+

6. Report through the outbox

+

Each state change writes an outbox row in the same transaction. The row holds only an id, so several changes collapse into one pending delivery. A worker turns rows into Check Runs, looking up by external id before creating, with exponential backoff and a dead-letter state after 20 tries.

+

When the last job of a PR's run finishes, the engine emits pr.verified. The merge queue and AI development both wait on that one event.

+

outbox/worker.go:86 · ci/cicheck/checkrun.go:40 · server.go:390

+ +

From green checks to a release

+
CI + AI reviewon the PR head
pr.verified: all required pass
Merge queueone executor per repo
merges; tag recorded in same tx
Auto-tagnext vX.Y.Z
plans the tag's run directly
Publish jobruns on the server
↺ behind the target branch: queue updates it, new head is verified again
The only loop is the branch update: a PR that fell behind is updated by the queue and must pass again on the new head before it merges.
+

Merge queue

+

Kiln uses neither GitHub's merge queue nor branch protection. A PR enters the queue when someone adds kiln:merge, or automatically once every entry under required has passed, if .kiln/merge.yml on the default branch sets auto: true. That config is read only from the default branch, so a PR cannot lower its own bar.

+

Each repository has one executor, holding a Postgres advisory lock. Every pass re-reads the PR from GitHub and decides from scratch: wait, update the branch, merge, or remove it with a reason. The merge request carries the head SHA it verified, and GitHub refuses if the head has moved.

+

mergequeue/process.go:46,894 · mergequeue/decide.go:208 · mergequeue/autoenqueue.go:85

+

Auto-tag and publish

+

The merge, the queue-entry update and a tag record commit together. The tag worker reads existing tags, picks the next version (patch by default; release:minor, release:major and release:skip labels change that), creates the ref, then calls the CI planner directly to plan a push run for the tag.

+

A job with a release: block has no steps and never reaches a runner. The server stages every target first (npm integrity check, image layers pushed by digest, a draft GitHub Release), passes a last cancel point, then commits in the order npm, image tags, HTTP uploads, GitHub Release. On a rerun, identical content already on a target counts as success.

+

autotag/autotag.go:315,684,932 · ci/publish/job.go:52 · ci/publish/targets.go:44

+ +

The AI loop on top

+

An AI node is a machine with the Orca desktop app and the kiln-orca connector. Its role, review or development, is fixed by its enrolment token. The connector takes a task, starts a coding agent in a fresh Orca worktree, and hands the result back. The agent's only way to talk to Kiln is the kiln-orca task command; the companion post covers that side.

+

Independent review

+

Opening or pushing to a PR plans a review request alongside the CI runs. The review brief, .kiln/agent/review.md, is read from the PR's base, so a PR cannot rewrite its own review standard. The agent must return a strict JSON report; only "no issues" passes. The result is posted as a PR review and as the ai-review check.

+

The server records which agents worked on each development item and refuses to give the review to any of them: checked once when planning and again when a node tries to take the task. Kiln's own config has Claude Code developing and Codex reviewing.

+

The review brief requires mutation checks: break the changed logic in a scratch copy and confirm a test fails. Both failed reviews in the table above were of that kind.

+

ai/review/plan.go:135,568 · ai/review/tasktype.go:104,178 · ai/review/publish.go:124

+

Development from an issue

+
developingclaimed from the pool
agent delivers
deliveringserver checks it
server pushes, opens PR
pr_openwaits for CI · review · merge
merge queue merges
merged
↺ findings / CI red / conflict: fixing, same PRrounds used up: blocked, waits for a person
Work-item states in dev_work_items (terminal states stopped and no_change omitted). A repository runs one unfinished item at a time; waiting in pr_open holds no node capacity.
+
    +
  • Pool. Open issues carrying kiln:ready are mirrored into dev_pool from Issues webhooks.
  • +
  • Select and claim. A development node is offered the candidates, picks a batch that fits one PR, and claims it; the server re-reads each issue from GitHub before accepting.
  • +
  • Deliver. The agent designs and implements in one run and pushes to a throwaway kiln/attempt-<id> branch. If it judges one PR is not enough, it first delivers a Markdown-only design PR; the server starts implementation automatically once that merges.
  • +
  • Promote. The server checks the delivery, fast-forwards the formal branch kiln/dev-<item> with a short-lived token of its own, and opens the PR itself. Agent-written titles and bodies are defused so they cannot mention people or close unrelated issues.
  • +
  • Hold. Deliveries that touch .kiln/, .github/, AGENTS.md, CLAUDE.md, .claude/ or .codex/, exceed 300 files or 100 commits, or declare a change to one of the project's 23 confirmed decisions get kiln:hold and wait for a person.
  • +
  • Repair. Review findings, real CI failures and merge conflicts each send the same item back for another round on the same PR, up to max_fix_rounds (10 in Kiln's own config).
  • +
+

ai/aidev/pool.go:49 · ai/aidev/claim.go:84 · ai/aidev/executor.go:224,627 · ai/aidev/fix.go:162 · ai/aidev/state.go:14

+ +

Four rules that keep it consistent

+
+ + + + + + + +
RuleWhat it preventsWhere
A state change and its outbound message commit togetherA green job with no Check Run; a merge with no tag recordoutbox/, shared by all domains
Every job and task write carries the epochA runner that lost its lease overwriting a newer attemptci/engine/engine.go:569, ai/lease.go:21
One executor per object, deciding from fresh stateTwo processes merging or tagging the same thing; acting on stale readsmergequeue/process.go:43, autotag/autotag.go:315
Writes without an idempotency key record intent first and are never blindly retriedDuplicate comments, reviews or issue closures after a lost responsemergequeue/closeissues.go:180, ai/review/publish.go:124
+

A fifth, narrower rule: no build or AI machine stores a git credential. Each clone, fetch or push asks the server for a token scoped to one repository, and the server revokes it when the operation or the attempt ends (gitcred/).

+ +

What you configure

+
+ + + + + + + + + + + +
File or labelControlsRead from
.kiln/workflows/*.ymlJobs, matrices, containers, services, release targetsThe commit being built
.kiln/runtimes.lockGo, Node, pnpm, Bun versions and per-platform digestsThe commit being built
.kiln/merge.ymlMerge method, required checks, auto-enqueue, tag rule, allowed target branchesDefault branch only
.kiln/agent/config.ymlWho reviews, who develops, platforms, timeouts, repair roundsReview: PR head; development: default branch
review.md / development.mdThe briefs given to the two agentsPR base / default branch
kiln:ready / kiln:skipPut an issue into / keep it out of the AI task poolIssue
kiln:merge / kiln:holdEnter the merge queue / block auto-enqueuePR
release:minor / major / skipVersion bump for the tag created after mergePR, frozen at merge
+

Secrets, variables and environments are stored in Kiln, encrypted with the server's master key, not in GitHub settings. Logs, artifacts and caches are kept for 12 hours; only results are kept long-term.

+ +

What I took away

+

I read six subsystems in depth and found no high-severity defects; what is worth fixing clusters around the things the design assumes are friendly. For example: when a missed webhook is recovered by reconciliation, the push loses its "was this a bot" flag, so a third-party bot's tag can still publish; the write token a development node can get covers the whole repository; and kiln:ready approves an issue number, not its text, so an edited issue body is what the agent builds. Each of these only matters once the trust boundary widens: a third-party bot with push access, a prompt-injected agent, a malicious dependency.

+

The bigger risks are not in the code: there is a single human maintainer, the design docs live in a private Outline, and CI logs are not public.

+
+
diff --git a/src/content/posts/kiln-orca-connector-en.md b/src/content/posts/kiln-orca-connector-en.md deleted file mode 100644 index 0c9684d..0000000 --- a/src/content/posts/kiln-orca-connector-en.md +++ /dev/null @@ -1,148 +0,0 @@ ---- -title: "How kiln-orca runs Kiln's work through agents in Orca" -description: "Reading the source of kiln-orca, Kiln's AI node connector: how it takes tasks from the server, starts Codex or Claude Code inside Orca, requests and revokes a git credential per transfer, and resumes from a journal after a crash." -growth: seedling -planted: 2026-11-23T01:41:38+08:00 -lastTended: 2026-11-23T01:41:38+08:00 -draft: false -lang: "en" -tags: - - "ai-agents" - - "workflow" - - "claude-code" - - "codex" - - "security" ---- - - - -
-

中文版:kiln-orca 怎么让 Orca 里的 Agent 干 Kiln 的活 · Previous post: How Kiln turns an issue into a release

-

The previous post covered Kiln's whole automation chain: an issue is developed by an AI, reviewed by another agent, then merged, tagged and released. On the AI side it stopped at "the server hands the task to an AI execution node". This post goes one level down: what happens on that node, how Kiln gets a coding agent inside Orca to do its work, and how it keeps the agent from doing anything else.

-

I read the kiln-orca/ directory of kilnflow.dev (TypeScript, about 11.5k lines of source) at commit e3bff51. Source and tests only: nothing was installed or run. Orca itself is not open source; I only looked at how the connector calls its command line and at Orca output recorded in the tests. Paths are relative to kiln-orca/src/.

- -

In one sentence: kiln-orca is a resident user service between the Kiln server and Orca. It takes tasks from the server, starts an agent in a one-shot Orca worktree, and writes each step to a local journal so it can carry on after a crash; the agent can only act by asking it through the kiln-orca task command, and git credentials are fetched from the server per transfer and handed back when done.

- -

Who does what

-
Kiln servertasks · credentials · results
airunner.v2 long-poll
kiln-orcaresident user service
Orca CLI
Orcaworktrees · terminals · orchestration
Orca starts the agent
Codex / Claude Codeworks in a one-shot worktree
↺ the agent reaches back only through kiln-orca task (local unix socket)
The connector does not run the agent itself, and the agent never talks to the server directly: every outbound request goes through the connector.
-

Orca is a desktop app that manages agents' worktrees, terminals and orchestration (runs, dispatches, workers). How Orca divides work inside, and whether it spawns sub-agents, is its own business; Kiln does not care.

-

kiln-orca runs as a macOS LaunchAgent or a Linux systemd --user service, and one data directory is one node. The token a node enrols with decides whether it is a review node or a development node; a machine with both Codex and Claude Code installed can enrol one of each, each with its own data directory.

- -

The life of one task on a node

-
prepareclone · worktree · toolchain · services
request id recorded first
startorca worker-start
agent works
runningwaits for worker_done · 5s heartbeat
agent sends worker_done
finishingpush attempt branch · Complete
result committed
stopping / releasingstop agent · free terminal
both confirmed
reclaimingdelete worktree · journal
These stage names are the values of the stage field in a journal record; the connector writes the journal before each step and resumes from it after a restart.
- -

1. Startup: check it can work before asking for work

-

On start, the connector reads its enrolment and private key, takes a single-instance lock, opens a socket at run/kiln-orca.sock in the data directory, then checks each dependency: Orca is open and at least version 1.4.258; Docker and Compose work; the bundled kiln-runner can prepare toolchains; the journal is writable; each agent answers --version; and the kiln-task skill is synced into each agent's skills directory.

-

This status, plus the protocol version (currently 10), goes to the server with every Acquire. When capacity is full (default max_tasks: 2), local drain is on, Orca is not ready, or the journal or skill has a problem, the node stays connected but declares it takes no new work. An unreadable journal record counts as one slot of capacity, because it may describe an agent still running in Orca that the connector cannot identify.

-

host/run.ts:132 · core/node.ts:176,473,728 · core/orca.ts:306

- -

2. Prepare: clone, worktree, toolchain, test services

-

After taking a task, the connector prepares the repository's clone under repos/<repo id>/<name>. It asks the server for a read token (IssueCredential with an op_id), passes it to git as http.<url>.extraHeader through environment variables so it never appears in argv, and calls RevokeCredential as soon as the clone is done. The connector's own git ignores the global and system git config.

-

It then registers the repository with Orca, writes task files under tasks/<attempt>/ (work.json, candidates.json for development selection, and so on), runs kiln-runner toolchain ensure to prepare Go, Node and pnpm from the repository's .kiln/runtimes.lock, and, if the repository declares test services, brings up Postgres or Redis with docker compose up -d --wait.

-

core/attempt.ts:459,746 · core/git.ts:171,410 · core/credentials.ts:77 · core/toolchain.ts:167 · core/services.ts:305

- -

3. Start the agent, never twice

-

Before starting, the connector writes this start's request id to the journal, and only then calls:

-

orca orchestration worker-start --worktree new-top-level --name kiln-a<attempt>-e<epoch> --base-branch <commit> --comment kiln:attempt=…;epoch=…;task=…;kind=… --agent <agent> --spec <prompt>

-

Orca creates a new top-level worktree and starts the agent in it. If the call's outcome is unclear (timeout, dropped connection), the connector does not retry; it asks request-show with the same request id whether Orca actually started it. If that cannot be settled, the task ends as infra.lost: failing is better than one task running two agents. The worktree's name and comment carry the attempt and epoch, which is how cleanup later proves "I created this".

-

core/attempt.ts:864,958 · core/orca.ts:611

- -

4. Tracking: mailbox, heartbeat, timeouts

-

When the agent finishes it sends a worker_done message. The connector keeps a "mailbox" terminal of its own in Orca running orchestration check --types worker_done,escalation,question and writes each message to a file; if the agent asks a question mid-task, it gets a fixed reply telling it to decide according to its brief.

-

While a task runs, the connector checks the mailbox every 2 seconds, falls back to worker-show every 30 seconds, and sends the server a heartbeat with the current stage every 5 seconds. The heartbeat reply can carry a cancel request; exceeding the task's time limit, losing the server for 10 minutes, a stale epoch, or the node being revoked all make the connector stop the agent. When the connector itself restarts it simply stops tracking; the agent keeps running in Orca and is picked up again from the journal.

-

core/mailbox.ts:585 · core/attempt.ts:118-123,1000,1358

- -

5. The agent's only door: kiln-orca task

-

The agent's brief contains a command of the form node cli.js task --home <data dir> --attempt <id>; its usage is documented in the kiln-task skill, which ships with the package and is synced into the agent's directory by the connector. The command hands each request over the unix socket to the running connector, which calls the server on its behalf.

-
- - - - - - - - - - - -
SubcommandWhat it doesWho validates
infoBasic task informationLocal
check-reportReview: validate report.json before finishingServer ValidateReport; locally only file type and a 1 MiB cap
claimDevelopment: claim the selected issuesServer ValidateReport + ClaimDevIssues
deliverDevelopment: submit the delivery reportServer validates the report; locally: clean tree, HEAD contains the delivered commit, design phase Markdown-only
ciLatest CI result for a PR or commitServer GetVerification
docRead the frozen external design docsServer, authorised from task relations
execRun a command with the managed toolchain; git gets credentials via the connectorSee the next section
doneEnd the round: validate once more, then send worker_done to Orca from the agent's own processConnector
-

One detail in that last row: worker_done is sent by the agent's process, using the identity Orca set in that session's environment; the connector never impersonates the agent to report completion.

-

host/socket.ts:295 · core/attempt.ts:1412-1649 · core/done.ts:138

- -

6. task exec: one token per git transfer

-
Agent's gitrun through task exec
git-remote-https swapped for a wrapper
Transport wrapperchecks for other credentials first
opens a read operation
Connector → servertoken for this one repo
✓ transfer ends, connection closes: revoked at oncenetrc, extraHeader or password in URL found: transfer refused
Neither the agent nor the worktree holds a lasting git credential; every fetch is requested and revoked on its own.
-

task exec -- <command> puts the toolchain first on PATH, points GIT_EXEC_PATH at a mirror directory where git-remote-http(s) is replaced by the connector's wrapper, and configures the connector's credential helper for the task repository's host.

-

Each time git goes over HTTP(S), the wrapper first checks whether the transfer would carry some other credential: a user or password in the URL, an http.extraHeader effective for that URL, netrc mentioning the host or default, or any of these being unreadable. Any one of them refuses the transfer. Otherwise it opens a read operation with the connector over the socket, and the connector asks the server for a token only if the URL is exactly the task repository or a declared dependency; when the connection closes, the token is revoked.

-

Write access is used only for delivery: the connector requests a separate write token for its own push of the attempt branch and returns it right after. The agent never gets a write credential.

-

host/cli.ts:306,365 · core/gitexec.ts:45,109 · core/credentials.ts:246,362 · core/attempt.ts:1468,1490

- -

7. Finishing: confirm the result, then delete things

-

When the agent finishes, the connector first records the verdict in the journal (stage finishing). For a development task that delivered, it pushes the delivered commit to kiln/attempt-<id> with a write token and confirms with ls-remote; if nothing was delivered, it pushes the current changes to the same branch as a checkpoint, so the next round can continue on a different machine. Then it sends Complete, retrying for up to 30 minutes.

-

Only after the result is confirmed does cleanup start: stop test services, confirm the agent has stopped and its terminal is released, delete the worktree, checkout and local branch through Orca, verify that Orca, git and the disk no longer have them, and finally delete the journal record. Before deleting, it checks name, comment, path and git registration; anything the connector did not create is left alone. Unfinished reclaim is retried every minute and abandoned after 12 hours with a log entry explaining the manual fix.

-

core/attempt.ts:1159,1223,1256,1297 · core/git.ts:558 · core/reclaim.ts:185-411

- -

What happens after a crash

-

This is the core of the design. Before every action that changes something outside the process, the connector records what it is about to do in journal/<attempt>.json: the start request id, the verdict, whether to push, the content of Complete. On restart it reads each record:

-
    -
  • a recorded Complete is sent again;
  • -
  • a verdict without a confirmed push redoes the push;
  • -
  • records stuck in stopping, releasing or reclaiming are retried every minute;
  • -
  • an unreadable record is neither skipped nor deleted: the node stops taking new work and reports the file and the reason in the log, doctor and the dashboard until a person deals with it.
  • -
-

The tests follow the same idea: about 580 cases using real git, a local git HTTP server, a real unix socket and multi-process lock races, plus many "epoch goes stale / process crashes in the middle of step X" cases.

- -

Problems I found

-

No high-severity defects. Most of what is worth fixing only matters if "the agent and the connector run as the same user" is treated as a security boundary; Kiln's own docs call these guard rails, not a boundary.

-
- - - - - - - - - -
ProblemEffectWhere
The socket identifies callers by attempt id aloneWith two tasks running, one agent can act as the other: get its credentials, claim issues, read docs. A random per-task secret in the task command would fix ithost/run.ts:202
Fixed 10-minute git timeout on a full cloneOn a large repo or slow link the clone times out, the next task starts from zero, and it can fail with infra.fetch indefinitelycore/git.ts:50,412
The shared clone's own .git/config and hooks still applyA proxy or hook left by an earlier development agent affects later tasks' token-carrying gitcore/git.ts:183
Journal and state files are not fsyncedAfter power loss a record can be empty; an empty journal stops the node taking work until someone deletes itcore/journal.ts:215
The clone path is built from the server-supplied repo name with no containment check before deletionOnly reachable if the server is buggy or compromised; the reclaim code already has this check, this path does notcore/attempt.ts:428
A report file over 1 MiB is reported to the agent as "retry later"The agent may keep retrying until the task times outcore/attempt.ts:1534
-

What is done well is just as clear: every child process is started with an argv array, never shell: true; tokens never appear in argv, the journal or logs, which record only fingerprints; external input is parsed as unknown and then validated, with not one as any in the source; and every external command has a timeout.

-
diff --git a/src/content/posts/kiln-orca-connector.md b/src/content/posts/kiln-orca-connector.md index 679ccf1..decdc63 100644 --- a/src/content/posts/kiln-orca-connector.md +++ b/src/content/posts/kiln-orca-connector.md @@ -52,10 +52,20 @@ tags: .html-embed .fr .fa i::after{right:auto;top:auto;left:-4px;bottom:-2px;border-top:8px solid currentColor;border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:0} .html-embed .fr .fa span{width:12em;text-align:left} } +.html-embed .lsr{position:absolute;opacity:0;width:1px;height:1px;margin:0;pointer-events:none} +.html-embed .lsw{display:inline-flex;gap:2px;background:var(--muted);border-radius:999px;padding:3px;margin:0 0 20px} +.html-embed .lsw label{padding:4px 16px;border-radius:999px;font-size:14px;line-height:1.5;cursor:pointer;color:var(--foreground);user-select:none} +.html-embed #lang-zh:checked ~ .lsw label[for="lang-zh"],.html-embed #lang-en:checked ~ .lsw label[for="lang-en"]{background:var(--foreground);color:var(--background)} +.html-embed #lang-zh:focus-visible ~ .lsw label[for="lang-zh"],.html-embed #lang-en:focus-visible ~ .lsw label[for="lang-en"]{outline:2px solid var(--accent);outline-offset:2px} +.html-embed #lang-zh:checked ~ .le,.html-embed #lang-en:checked ~ .lz{display:none} +.html-embed .alt-title{font-size:1.35em;font-weight:600;line-height:1.35;margin:0 0 12px}
-

English version: How kiln-orca runs Kiln's work through agents in Orca · 前一篇:Kiln 怎么把一个 Issue 自动变成一次发布

+ + +
+

上一篇讲了 Kiln 的整条自动化链:Issue 被 AI 开发、被另一个 Agent 审计,然后合并、打 tag、发布。那篇里 AI 的部分只说到「Server 把任务派给 AI 执行节点」。这篇往下看一层:执行节点上发生了什么,Kiln 怎么让 Orca 里的编程 Agent 替它干活,又怎么防它乱来。

读的是 kilnflow.dev 的 kiln-orca/ 目录(TypeScript,约 1.15 万行源码),commit e3bff51。只读源码和测试,没有安装,也没有运行;Orca 本身不开源,我只看了连接器怎么调用它的命令行,以及测试里录下的 Orca 输出。下文路径都相对于 kiln-orca/src/。

@@ -144,4 +154,106 @@ tags:

做得好的地方也很明显:所有子进程都用参数数组启动,没有 shell: true;token 不出现在命令行参数、journal 和日志里,日志只记指纹;外部输入都按 unknown 解析再校验,源码里没有一处 as any;每个外部命令都有超时。

+
+
+

How kiln-orca runs Kiln's work through agents in Orca

+

The previous post covered Kiln's whole automation chain: an issue is developed by an AI, reviewed by another agent, then merged, tagged and released. On the AI side it stopped at "the server hands the task to an AI execution node". This post goes one level down: what happens on that node, how Kiln gets a coding agent inside Orca to do its work, and how it keeps the agent from doing anything else.

+

I read the kiln-orca/ directory of kilnflow.dev (TypeScript, about 11.5k lines of source) at commit e3bff51. Source and tests only: nothing was installed or run. Orca itself is not open source; I only looked at how the connector calls its command line and at Orca output recorded in the tests. Paths are relative to kiln-orca/src/.

+ +

In one sentence: kiln-orca is a resident user service between the Kiln server and Orca. It takes tasks from the server, starts an agent in a one-shot Orca worktree, and writes each step to a local journal so it can carry on after a crash; the agent can only act by asking it through the kiln-orca task command, and git credentials are fetched from the server per transfer and handed back when done.

+ +

Who does what

+
Kiln servertasks · credentials · results
airunner.v2 long-poll
kiln-orcaresident user service
Orca CLI
Orcaworktrees · terminals · orchestration
Orca starts the agent
Codex / Claude Codeworks in a one-shot worktree
↺ the agent reaches back only through kiln-orca task (local unix socket)
The connector does not run the agent itself, and the agent never talks to the server directly: every outbound request goes through the connector.
+

Orca is a desktop app that manages agents' worktrees, terminals and orchestration (runs, dispatches, workers). How Orca divides work inside, and whether it spawns sub-agents, is its own business; Kiln does not care.

+

kiln-orca runs as a macOS LaunchAgent or a Linux systemd --user service, and one data directory is one node. The token a node enrols with decides whether it is a review node or a development node; a machine with both Codex and Claude Code installed can enrol one of each, each with its own data directory.

+ +

The life of one task on a node

+
prepareclone · worktree · toolchain · services
request id recorded first
startorca worker-start
agent works
runningwaits for worker_done · 5s heartbeat
agent sends worker_done
finishingpush attempt branch · Complete
result committed
stopping / releasingstop agent · free terminal
both confirmed
reclaimingdelete worktree · journal
These stage names are the values of the stage field in a journal record; the connector writes the journal before each step and resumes from it after a restart.
+ +

1. Startup: check it can work before asking for work

+

On start, the connector reads its enrolment and private key, takes a single-instance lock, opens a socket at run/kiln-orca.sock in the data directory, then checks each dependency: Orca is open and at least version 1.4.258; Docker and Compose work; the bundled kiln-runner can prepare toolchains; the journal is writable; each agent answers --version; and the kiln-task skill is synced into each agent's skills directory.

+

This status, plus the protocol version (currently 10), goes to the server with every Acquire. When capacity is full (default max_tasks: 2), local drain is on, Orca is not ready, or the journal or skill has a problem, the node stays connected but declares it takes no new work. An unreadable journal record counts as one slot of capacity, because it may describe an agent still running in Orca that the connector cannot identify.

+

host/run.ts:132 · core/node.ts:176,473,728 · core/orca.ts:306

+ +

2. Prepare: clone, worktree, toolchain, test services

+

After taking a task, the connector prepares the repository's clone under repos/<repo id>/<name>. It asks the server for a read token (IssueCredential with an op_id), passes it to git as http.<url>.extraHeader through environment variables so it never appears in argv, and calls RevokeCredential as soon as the clone is done. The connector's own git ignores the global and system git config.

+

It then registers the repository with Orca, writes task files under tasks/<attempt>/ (work.json, candidates.json for development selection, and so on), runs kiln-runner toolchain ensure to prepare Go, Node and pnpm from the repository's .kiln/runtimes.lock, and, if the repository declares test services, brings up Postgres or Redis with docker compose up -d --wait.

+

core/attempt.ts:459,746 · core/git.ts:171,410 · core/credentials.ts:77 · core/toolchain.ts:167 · core/services.ts:305

+ +

3. Start the agent, never twice

+

Before starting, the connector writes this start's request id to the journal, and only then calls:

+

orca orchestration worker-start --worktree new-top-level --name kiln-a<attempt>-e<epoch> --base-branch <commit> --comment kiln:attempt=…;epoch=…;task=…;kind=… --agent <agent> --spec <prompt>

+

Orca creates a new top-level worktree and starts the agent in it. If the call's outcome is unclear (timeout, dropped connection), the connector does not retry; it asks request-show with the same request id whether Orca actually started it. If that cannot be settled, the task ends as infra.lost: failing is better than one task running two agents. The worktree's name and comment carry the attempt and epoch, which is how cleanup later proves "I created this".

+

core/attempt.ts:864,958 · core/orca.ts:611

+ +

4. Tracking: mailbox, heartbeat, timeouts

+

When the agent finishes it sends a worker_done message. The connector keeps a "mailbox" terminal of its own in Orca running orchestration check --types worker_done,escalation,question and writes each message to a file; if the agent asks a question mid-task, it gets a fixed reply telling it to decide according to its brief.

+

While a task runs, the connector checks the mailbox every 2 seconds, falls back to worker-show every 30 seconds, and sends the server a heartbeat with the current stage every 5 seconds. The heartbeat reply can carry a cancel request; exceeding the task's time limit, losing the server for 10 minutes, a stale epoch, or the node being revoked all make the connector stop the agent. When the connector itself restarts it simply stops tracking; the agent keeps running in Orca and is picked up again from the journal.

+

core/mailbox.ts:585 · core/attempt.ts:118-123,1000,1358

+ +

5. The agent's only door: kiln-orca task

+

The agent's brief contains a command of the form node cli.js task --home <data dir> --attempt <id>; its usage is documented in the kiln-task skill, which ships with the package and is synced into the agent's directory by the connector. The command hands each request over the unix socket to the running connector, which calls the server on its behalf.

+
+ + + + + + + + + + + +
SubcommandWhat it doesWho validates
infoBasic task informationLocal
check-reportReview: validate report.json before finishingServer ValidateReport; locally only file type and a 1 MiB cap
claimDevelopment: claim the selected issuesServer ValidateReport + ClaimDevIssues
deliverDevelopment: submit the delivery reportServer validates the report; locally: clean tree, HEAD contains the delivered commit, design phase Markdown-only
ciLatest CI result for a PR or commitServer GetVerification
docRead the frozen external design docsServer, authorised from task relations
execRun a command with the managed toolchain; git gets credentials via the connectorSee the next section
doneEnd the round: validate once more, then send worker_done to Orca from the agent's own processConnector
+

One detail in that last row: worker_done is sent by the agent's process, using the identity Orca set in that session's environment; the connector never impersonates the agent to report completion.

+

host/socket.ts:295 · core/attempt.ts:1412-1649 · core/done.ts:138

+ +

6. task exec: one token per git transfer

+
Agent's gitrun through task exec
git-remote-https swapped for a wrapper
Transport wrapperchecks for other credentials first
opens a read operation
Connector → servertoken for this one repo
✓ transfer ends, connection closes: revoked at oncenetrc, extraHeader or password in URL found: transfer refused
Neither the agent nor the worktree holds a lasting git credential; every fetch is requested and revoked on its own.
+

task exec -- <command> puts the toolchain first on PATH, points GIT_EXEC_PATH at a mirror directory where git-remote-http(s) is replaced by the connector's wrapper, and configures the connector's credential helper for the task repository's host.

+

Each time git goes over HTTP(S), the wrapper first checks whether the transfer would carry some other credential: a user or password in the URL, an http.extraHeader effective for that URL, netrc mentioning the host or default, or any of these being unreadable. Any one of them refuses the transfer. Otherwise it opens a read operation with the connector over the socket, and the connector asks the server for a token only if the URL is exactly the task repository or a declared dependency; when the connection closes, the token is revoked.

+

Write access is used only for delivery: the connector requests a separate write token for its own push of the attempt branch and returns it right after. The agent never gets a write credential.

+

host/cli.ts:306,365 · core/gitexec.ts:45,109 · core/credentials.ts:246,362 · core/attempt.ts:1468,1490

+ +

7. Finishing: confirm the result, then delete things

+

When the agent finishes, the connector first records the verdict in the journal (stage finishing). For a development task that delivered, it pushes the delivered commit to kiln/attempt-<id> with a write token and confirms with ls-remote; if nothing was delivered, it pushes the current changes to the same branch as a checkpoint, so the next round can continue on a different machine. Then it sends Complete, retrying for up to 30 minutes.

+

Only after the result is confirmed does cleanup start: stop test services, confirm the agent has stopped and its terminal is released, delete the worktree, checkout and local branch through Orca, verify that Orca, git and the disk no longer have them, and finally delete the journal record. Before deleting, it checks name, comment, path and git registration; anything the connector did not create is left alone. Unfinished reclaim is retried every minute and abandoned after 12 hours with a log entry explaining the manual fix.

+

core/attempt.ts:1159,1223,1256,1297 · core/git.ts:558 · core/reclaim.ts:185-411

+ +

What happens after a crash

+

This is the core of the design. Before every action that changes something outside the process, the connector records what it is about to do in journal/<attempt>.json: the start request id, the verdict, whether to push, the content of Complete. On restart it reads each record:

+ +

The tests follow the same idea: about 580 cases using real git, a local git HTTP server, a real unix socket and multi-process lock races, plus many "epoch goes stale / process crashes in the middle of step X" cases.

+ +

Problems I found

+

No high-severity defects. Most of what is worth fixing only matters if "the agent and the connector run as the same user" is treated as a security boundary; Kiln's own docs call these guard rails, not a boundary.

+
+ + + + + + + + + +
ProblemEffectWhere
The socket identifies callers by attempt id aloneWith two tasks running, one agent can act as the other: get its credentials, claim issues, read docs. A random per-task secret in the task command would fix ithost/run.ts:202
Fixed 10-minute git timeout on a full cloneOn a large repo or slow link the clone times out, the next task starts from zero, and it can fail with infra.fetch indefinitelycore/git.ts:50,412
The shared clone's own .git/config and hooks still applyA proxy or hook left by an earlier development agent affects later tasks' token-carrying gitcore/git.ts:183
Journal and state files are not fsyncedAfter power loss a record can be empty; an empty journal stops the node taking work until someone deletes itcore/journal.ts:215
The clone path is built from the server-supplied repo name with no containment check before deletionOnly reachable if the server is buggy or compromised; the reclaim code already has this check, this path does notcore/attempt.ts:428
A report file over 1 MiB is reported to the agent as "retry later"The agent may keep retrying until the task times outcore/attempt.ts:1534
+

What is done well is just as clear: every child process is started with an argv array, never shell: true; tokens never appear in argv, the journal or logs, which record only fingerprints; external input is parsed as unknown and then validated, with not one as any in the source; and every external command has a timeout.

+
+ diff --git a/src/utils/reading.ts b/src/utils/reading.ts index 91bdbac..41fc3c7 100644 --- a/src/utils/reading.ts +++ b/src/utils/reading.ts @@ -7,10 +7,17 @@ * a widget's script has many. */ +/** + * A bilingual note marks the translation a reader switches to with + * `
`. Only one language is read, so it is not counted. + */ +const ALT_LANG = /]*\bdata-alt-lang\b[^>]*>[\s\S]*?<\/section>/gi; + /** The note's prose with markup, code, styles, scripts and data URIs removed. */ export function readableText(body: string): string { return body .replace(/^---\n[\s\S]*?\n---\n/, '') + .replace(ALT_LANG, ' ') .replace(/<(style|script|svg|textarea)\b[\s\S]*?<\/\1>/gi, ' ') .replace(/```[\s\S]*?```/g, ' ') .replace(/<[^>]+>/g, ' ')