From d0a515a2ca3ad933c056c8b481caac7754389d47 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 17:50:01 +0000 Subject: [PATCH] Add Kiln automation flow and kiln-orca posts in Chinese and English Two notes from a source read of hewenyu/kilnflow.dev at e3bff51, each in zh-CN and en with links between the versions: - how an issue labelled kiln:ready becomes a release (CI, merge queue, auto-tag, publish, AI review and development) - how the kiln-orca connector runs agents inside Orca (task lifecycle, per-transfer git credentials, journal recovery, findings) post-audit and figure measurements are clean for all four. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NzupDBSP7FkrPA5FsJbeYs --- src/content/posts/kiln-automation-flow-en.md | 173 +++++++++++++++++++ src/content/posts/kiln-automation-flow.md | 172 ++++++++++++++++++ src/content/posts/kiln-orca-connector-en.md | 148 ++++++++++++++++ src/content/posts/kiln-orca-connector.md | 147 ++++++++++++++++ 4 files changed, 640 insertions(+) create mode 100644 src/content/posts/kiln-automation-flow-en.md create mode 100644 src/content/posts/kiln-automation-flow.md create mode 100644 src/content/posts/kiln-orca-connector-en.md create mode 100644 src/content/posts/kiln-orca-connector.md diff --git a/src/content/posts/kiln-automation-flow-en.md b/src/content/posts/kiln-automation-flow-en.md new file mode 100644 index 0000000..8ac47cd --- /dev/null +++ b/src/content/posts/kiln-automation-flow-en.md @@ -0,0 +1,173 @@ +--- +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 new file mode 100644 index 0000000..edcbfaa --- /dev/null +++ b/src/content/posts/kiln-automation-flow.md @@ -0,0 +1,172 @@ +--- +title: "Kiln 怎么把一个 Issue 自动变成一次发布" +description: "读 Kiln(kilnflow.dev)的源码:一个打了 kiln:ready 的 Issue,怎样经过 AI 开发、另一个 Agent 的独立审计、自建的合并队列、自动打 tag,最后由 Server 发布,中间没有人参与。" +growth: seedling +planted: 2026-11-23T01:41:38+08:00 +lastTended: 2026-11-23T01:41:38+08:00 +draft: false +tags: + - "ai-agents" + - "workflow" + - "code-review" + - "self-hosting" + - "open-source" +--- + + + +
+

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/。

+ +

一句话:GitHub 只管发事件和收结果;判断、调度、合并、打 tag、发布全在 Kiln 的 Server 里,靠「状态变更和外发消息同一个事务提交」把这些步骤串成一条不会丢步的链。

+ +

谁和谁说话

+
GitHub装在自己账号上的 App
webhook
kiln-serverPostgres 是唯一状态 · 只有它回写 GitHub
派活给主动来领的机器;发布产物
kiln-runner × NCI:主机 / Docker / BuildKit
kiln-orca × NAI:Orca + Codex / Claude Code
发布目标Release · npm · 镜像 · HTTP
构建机和 AI 机器都是主动连出去,所以可以放在家里或内网;GitHub App 私钥和发布凭据只在 Server 上,回写 GitHub 的也只有 Server。
+

Server 里 CI 和 AI 是两个分开的领域:表、调度器、通信协议(runner.v1 和 airunner.v2)都不同。它们只在组装文件 server.go 里通过窄接口接线,或者经由共用的 outbox 表传事件。internal/archtest 会在一个领域直接 import 另一个领域、或查询别人的表时让测试失败,这条边界是机器检查的,不只是写在文档里。

+ +

一次真实的流转

+

Kiln 用 Kiln 构建自己。2026 年 11 月 22 日,也就是开源后的第二天,三个打了 kiln:ready 的 i18n Issue 走完了整条链。下面的时间是 UTC,取自 commit 和 tag 的元数据;审计结果来自 PR 页面。

+
+ + + + + + + + + +
时间发生了什么谁做的
09:44为 Issue #2 推到 kiln/dev-6,开出 PR #9Claude Code 写代码;Server 开 PR
09:44 之后19 个检查运行。AI 审计不通过:1 个中等问题,一个测试测不出它声称覆盖的错误Codex,发为 PR review
10:07第 1 轮返修:重写测试,贴出处置说明Claude Code
10:19 之前第二次审计通过;加上 kiln:mergeCodex;Server
10:19squash 合并为 11deef3,在它上面打 v1.0.3kiln-runner[bot]
10:20发布 Release v1.0.3(12 个 asset),关闭 Issue #2Server
+

PR #10 也是一轮返修(11:41 合并,v1.0.4);PR #11 一次通过审计(12:32 合并,v1.0.5)。从第一个 commit 到公开发布,三个分别用了 36、45 和 13 分钟。

+ +

CI 这一段:从 webhook 到绿色的 Check Run

+
接收验签 · 存事件 · 回 202
后台逐条处理
规划整个 job 图一次定好
依赖完成
算 action key所有输入的指纹
没命中缓存
领取同一事务:epoch+1 · 租约
心跳续约
Runner 执行只看得到 inputs 的文件
Complete
outbox写 Check Run
✓ 命中缓存:job 直接成功,不占 Runner
action key 是这条链上省时间的地方:输入没变的 job 不再执行。
+

1. 接收:验签、存下、立刻回

+

GitHub 把事件 POST 到 /webhook。处理函数用常数时间比较校验 HMAC-SHA256 签名,按 delivery id 去重存进 events 表,然后返回 202,请求里不做别的事。

+

一个后台循环再逐条处理存下的事件:不在 KILN_ALLOWED_ACCOUNTS 里的账号的安装会被拒绝并卸载;来自 fork 的 PR 一律丢弃,没有开关;同一个 ref 已经有更新事件的旧事件直接跳过。

+

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

+

2. 规划:执行之前,job 图就全定了

+

Planner 按要构建的那个 commit 读 .kiln/workflows/*.yml。PR 构建的是 head commit,不是和目标分支的合并提交。语法沿用 GitHub Actions,但不支持 uses:;表达式只能引用规划时就知道的值,所以矩阵、if:、needs 在这一步全部展开。

+

run、job、并发组和第一批 Check Run 记录在同一个事务里写入。workflow 写错了也会建出 run,只是直接标为失败,commit 上会出现一个带错误信息的红色检查。

+

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

+

3. 已经构建过的不再构建

+

一个 job 的依赖全部完成时,engine 把会影响它的一切算成 action key:inputs 文件的摘要、env、steps、镜像 digest、runtime digest、上游输出的摘要。secret 只以名字计入。

+

action_cache 里有这个 key,job 就直接成功,不碰 Runner;有一个 key 相同、正在执行的 job,这个 job 就跟着它的结果走。所以 Kiln 自己的 workflow 把带版本号的构建单独放成一个 job:合并之后测试的 key 不变,不用重跑。

+

ci/engine/engine.go:205,372

+

4. 领取:选中、epoch+1、租约,一个事务

+

Runner 保持一个长轮询的 Acquire。调度器锁住这台 Runner 的行,用 FOR UPDATE SKIP LOCKED 按优先级和先后取最多 300 个候选 job,再按平台、pool、执行器、声明的 CPU 和内存(对照这台机器的剩余容量)以及仓库的并发上限筛选。

+

选中的 job 在同一个事务里变成 running、epoch 加一、插入 attempt、设好租约。Runner 之后的每次写入都要带上匹配的 epoch,所以一台丢了租约的 Runner 不可能覆盖新一次 attempt 的结果。

+

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

+

5. 在 Runner 上执行

+

Runner 只检出 job 的 inputs 匹配到的文件,没有 .git;按 .kiln/runtimes.lock 的摘要安装并校验 Go、Node、pnpm;从内容寻址存储取上游 job 的输出;在主机上或容器里运行 steps。容器 job 默认 --network none。

+

拉源码用的 token 是 Server 为这一次 fetch 单独签发的、只覆盖这一个仓库,fetch 完就吊销。secret 经 RPC 下发,只放在 step 的环境变量里,日志中的原文、base64 和 URL 编码形式都会被遮掉。

+

每隔几秒的心跳续租约,也把取消请求带回来。输出上传到预签名的地址,最后 Complete 结束 attempt 并写缓存。

+

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

+

6. 经 outbox 回报

+

每次状态变更都在同一个事务里写一条 outbox 记录。记录里只有一个 id,所以连续几次变更会合成一次待投递。worker 把它变成 Check Run:先按 external id 查找再创建,指数退避,失败 20 次进死信。

+

一个 PR 的 run 最后一个 job 结束时,engine 发出 pr.verified。合并队列和 AI 开发都在等这一个事件。

+

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

+ +

从全部通过到发布

+
CI + AI 审计在 PR head 上
pr.verified:必需项全过
合并队列每个仓库一个执行者
合并,同一事务记下 tag
自动打 tag下一个 vX.Y.Z
直接规划这个 tag 的 run
发布 job在 Server 上执行
↺ 落后于目标分支:队列先更新分支,新 head 重新验证
唯一的回路是更新分支:落后的 PR 被队列更新后,必须在新 head 上再验证一遍才合并。
+

合并队列

+

Kiln 不用 GitHub 的 merge queue,也不需要分支保护。PR 有人加上 kiln:merge 就入队;默认分支上的 .kiln/merge.yml 写了 auto: true 时,required 里的每一项都通过后自动入队。这个配置只从默认分支读,PR 改不了自己的合并门槛。

+

每个仓库只有一个执行者,持有 Postgres 的 advisory lock。每一轮都重新从 GitHub 读 PR,从头判断:等、更新分支、合并,或者带着原因移出队列。合并请求带上它验证过的 head SHA,head 变了 GitHub 会拒绝。

+

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

+

自动打 tag 与发布

+

合并、队列条目的更新和一条 tag 记录在同一个事务里提交。tag worker 读出已有的 tag,算出下一个版本(默认升补丁号;release:minor、release:major、release:skip 标签改变规则),创建 ref,然后直接调用 CI 的 planner 为这个 tag 规划一次 push run。

+

写了 release: 的 job 没有 steps,不会到 Runner 上。Server 先把所有目标暂存好(npm 核对 integrity、镜像按 digest 推层、GitHub Release 建成草稿),过了最后一个可取消点后,按 npm、镜像 tag、HTTP 上传、GitHub Release 的顺序正式发布。重跑时,目标上已有相同内容就算成功。

+

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 命令。

+

独立审计

+

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

+

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

+

审计说明要求做变异验证:在临时副本里把改动的关键逻辑改坏,确认测试会失败。上面表格里两次审计不通过,都是这一类问题。

+

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

+

从 Issue 开发

+
developing从任务池领取
Agent 交付
deliveringServer 核对
Server 推分支、开 PR
pr_open等 CI · 审计 · 合并
合并队列合入
merged
↺ 审计有问题 / CI 失败 / 冲突:fixing,同一个 PR 返修返修轮数用完:blocked,等人
工作项在 dev_work_items 里的状态(省略了终态 stopped 和 no_change)。同一个仓库一次只跑一个未结束的工作项;停在 pr_open 等待时不占节点容量。
+
    +
  • 任务池。打开的、带 kiln:ready 的 Issue 经 Issues webhook 同步进 dev_pool。
  • +
  • 选题和领取。开发节点拿到候选,挑一批适合放进一个 PR 的领取;Server 在接受前从 GitHub 重新读一遍每个 Issue。
  • +
  • 交付。Agent 在一次执行里先设计再实现,推到一次性的 kiln/attempt-<id> 分支。判断一个 PR 做不完时,先交付只改 Markdown 的设计 PR,合并后 Server 自动开始实现。
  • +
  • 推进。Server 核对交付,用自己签发的短期 token 把正式分支 kiln/dev-<工作项> 快进过去,由自己开 PR。Agent 写的标题和正文会被处理,不能 @ 人,也不能顺手关掉别的 Issue。
  • +
  • 暂停。改动了 .kiln/、.github/、AGENTS.md、CLAUDE.md、.claude/、.codex/,超过 300 个文件或 100 个 commit,或者声明要改项目 23 条已确认决定之一的交付,加 kiln:hold 等人确认。
  • +
  • 返修。审计 finding、真实的 CI 失败、合并冲突,都把同一个工作项送回再做一轮,在同一个 PR 上,最多 max_fix_rounds 轮(Kiln 自己配的是 10)。
  • +
+

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

+ +

让它不出错的四条规则

+
+ + + + + + + +
规则防的是什么在哪
状态变更和外发消息同一个事务提交job 绿了却没有 Check Run;合并了却没记下 tagoutbox/,各领域共用
job 和任务的每次写入都带 epoch丢了租约的 Runner 覆盖新一次 attempt 的结果ci/engine/engine.go:569、ai/lease.go:21
每个对象一个执行者,每次按最新状态判断两个进程合并、打 tag 同一个东西;按过期的读结果行事mergequeue/process.go:43、autotag/autotag.go:315
没有幂等键的写操作先记意图,绝不盲目重试响应丢失后重复评论、重复 review、重复关 Issuemergequeue/closeissues.go:180、ai/review/publish.go:124
+

还有一条范围更窄的:构建机和 AI 机器上都不存 git 凭据。每次 clone、fetch、push 都向 Server 要一枚只覆盖一个仓库的 token,操作结束或 attempt 结束时由 Server 吊销(gitcred/)。

+ +

你要配置的东西

+
+ + + + + + + + + + + +
文件或标签管什么从哪读
.kiln/workflows/*.ymljob、矩阵、容器、services、发布目标正在构建的 commit
.kiln/runtimes.lockGo、Node、pnpm、Bun 的版本和各平台摘要正在构建的 commit
.kiln/merge.yml合并方式、必需检查、自动入队、打 tag 规则、允许的目标分支只从默认分支
.kiln/agent/config.yml谁审计、谁开发、平台、超时、返修轮数审计:PR head;开发:默认分支
review.md / development.md给两个 Agent 的说明PR base / 默认分支
kiln:ready / kiln:skip把 Issue 放进 / 排除出 AI 任务池Issue
kiln:merge / kiln:hold进入合并队列 / 不自动入队PR
release:minor / major / skip合并后打 tag 时怎么升版本PR,合并时冻结
+

secret、变量和 environment 都存在 Kiln 里,用 Server 的主密钥加密,不放在 GitHub Settings。日志、产物和缓存只保留 12 小时,长期只留结果。

+ +

读完的几点看法

+

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

+

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

+
diff --git a/src/content/posts/kiln-orca-connector-en.md b/src/content/posts/kiln-orca-connector-en.md new file mode 100644 index 0000000..0c9684d --- /dev/null +++ b/src/content/posts/kiln-orca-connector-en.md @@ -0,0 +1,148 @@ +--- +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 new file mode 100644 index 0000000..679ccf1 --- /dev/null +++ b/src/content/posts/kiln-orca-connector.md @@ -0,0 +1,147 @@ +--- +title: "kiln-orca 怎么让 Orca 里的 Agent 干 Kiln 的活" +description: "读 Kiln 的 AI 执行节点连接器 kiln-orca 的源码:它怎样从 Server 领任务、在 Orca 里启动 Codex 或 Claude Code、按每次 git 传输申请和吊销凭据,以及怎样靠 journal 在崩溃后接着做。" +growth: seedling +planted: 2026-11-23T01:41:38+08:00 +lastTended: 2026-11-23T01:41:38+08:00 +draft: false +tags: + - "ai-agents" + - "workflow" + - "claude-code" + - "codex" + - "security" +--- + + + +
+

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/。

+ +

一句话:kiln-orca 是一个常驻的用户服务,夹在 Kiln Server 和 Orca 之间。它从 Server 领任务、在 Orca 里开一个一次性的工作区启动 Agent、把每一步写进本地 journal 以便崩溃后接着做;Agent 能做的事只有通过 kiln-orca task 命令问它,git 凭据也是它按每一次传输向 Server 要来、用完就还。

+ +

三方各管什么

+
Kiln Server派任务 · 发凭据 · 收结果
airunner.v2 长轮询
kiln-orca常驻用户服务
Orca 命令行
Orca工作区 · 终端 · 编排
Orca 启动 Agent
Codex / Claude Code在一次性的工作区里干活
↺ Agent 只经 kiln-orca task 回头找连接器(本机 unix socket)
连接器不自己跑 Agent,也不让 Agent 直接联系 Server:所有往外的请求都经过它。
+

Orca 是一个桌面应用,管 Agent 的工作区(git worktree)、终端和编排(run、dispatch、worker)。Orca 内部怎么分工、要不要拆子 Agent,是它自己的事,Kiln 不管。

+

kiln-orca 以 macOS LaunchAgent 或 Linux systemd --user 服务运行,一个数据目录就是一个节点。节点注册时用的令牌决定它是审计节点还是开发节点;一台装了 Codex 和 Claude Code 的机器可以同时注册两个节点,各用一个数据目录。

+ +

一个任务在节点上的一生

+
prepareclone · 工作区 · 工具链 · 测试服务
先记下请求 id
startorca worker-start
Agent 开始干
running等 worker_done · 每 5 秒心跳
Agent 发出 worker_done
finishing推 attempt 分支 · Complete
结果已提交
stopping / releasing停 Agent · 释放终端
都确认了
reclaiming删工作区 · 删 journal
这些阶段名就是 journal 记录里 stage 字段的取值;连接器每进一步先写 journal,重启后按它接着做。
+ +

1. 启动:先确认自己能干活,再去领

+

服务启动时,连接器读注册信息和私钥,拿单实例锁,在数据目录的 run/kiln-orca.sock 上开 socket,然后逐项检查:Orca 是否打开、版本是否不低于 1.4.258,Docker 和 Compose 能不能用,随包的 kiln-runner 能不能准备工具链,journal 能不能写,每个 Agent 的 --version,以及 kiln-task skill 是否已同步进 Agent 的 skill 目录。

+

这些状态连同协议版本(现在是 10)每次都随 Acquire 报给 Server。容量满了(默认 max_tasks: 2)、本机设了 drain、Orca 没就绪、journal 或 skill 有问题时,节点照样连着,但声明自己不接新任务。读不了的 journal 记录也按占一份容量算,因为里面可能有一个还在 Orca 中运行、连接器却不认识的 Agent。

+

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

+ +

2. 准备:clone、工作区、工具链、测试服务

+

领到任务后,连接器在 repos/<repo id>/<仓库名> 下准备这个仓库的 clone。需要的只读 token 向 Server 要(IssueCredential,带一个 op_id),经环境变量里的 http.<地址>.extraHeader 交给 git,不出现在命令行参数里;clone 完立刻 RevokeCredential。连接器自己的 git 不读全局和系统的 git 配置。

+

然后把仓库登记到 Orca,在 tasks/<attempt>/ 下写好任务文件(work.json、开发选题时的 candidates.json 等),按仓库的 .kiln/runtimes.lock 调用 kiln-runner toolchain ensure 准备 Go、Node、pnpm,仓库声明了测试服务时用 docker compose up -d --wait 拉起 Postgres 或 Redis。

+

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

+ +

3. 启动 Agent:绝不启动两次

+

启动前,连接器先把这次启动的请求 id 写进 journal,然后才调用:

+

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 新建一个顶层工作区、在里面启动 Agent。如果这次调用的结果不明(超时、连接断开),连接器不重试,而是用同一个请求 id 去 request-show 查 Orca 到底启动了没有。查不出来就以 infra.lost 结束,宁可失败也不让同一个任务跑出两个 Agent。工作区的名字和备注带着 attempt 和 epoch,后面回收时靠它们确认「这是我建的」。

+

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

+ +

4. 跟踪:邮箱、心跳、超时

+

Agent 结束时会发一条 worker_done。连接器在 Orca 里有一个自己的「邮箱」终端,持续执行 orchestration check --types worker_done,escalation,question,把收到的消息落成文件;Agent 中途提问时给它一个固定的回复,让它按任务说明自己判断。

+

任务进行中,连接器每 2 秒看一次邮箱,每 30 秒用 worker-show 兜底查一次 Agent 的状态,每 5 秒给 Server 发一次心跳(带上当前阶段)。心跳的回复里可能有取消请求;超过任务时限、和 Server 失联 10 分钟、epoch 已经过期、节点被吊销,都会让连接器停下这个 Agent。连接器自己重启时只是不再跟踪,Agent 在 Orca 里继续跑,重启后从 journal 接上。

+

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

+ +

5. Agent 的唯一入口:kiln-orca task

+

Agent 拿到的任务说明里有一条形如 node cli.js task --home <数据目录> --attempt <id> 的命令,用法写在随包分发、由连接器同步进 Agent 目录的 kiln-task skill 里。这个命令把请求经 unix socket 交给运行中的连接器,连接器再替它调用 Server。

+
+ + + + + + + + + + + +
子命令做什么谁来校验
info任务的基本信息本地
check-report审计:提交前先校验 report.jsonServer 的 ValidateReport;本地只查文件类型和 1 MiB 上限
claim开发:领取选中的 IssueServer 的 ValidateReport + ClaimDevIssues
deliver开发:交付报告Server 校验报告;本地查工作区干净、HEAD 包含交付的 commit、设计阶段只改 Markdown
ci查 PR 或 commit 最新的 CI 结果Server 的 GetVerification
doc读冻结的外部设计文档Server 按任务关系授权
exec用受管理的工具链跑命令,git 经连接器拿凭据见下一节
done结束这一轮:再校验一次,然后在 Agent 自己的进程里向 Orca 发 worker_done连接器
+

最后一条有个细节:worker_done 由 Agent 的进程发出,身份来自 Orca 给这个会话设置的环境,连接器不冒充 Agent 报结束。

+

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

+ +

6. task exec:每一次 git 传输一枚 token

+
Agent 的 git经 task exec 运行
git-remote-https 被换成包装
传输包装先查有没有别的凭据
开一个只读操作
连接器 → Server签发只覆盖这个仓库的 token
✓ 传输结束、连接关闭:立即吊销发现 netrc、extraHeader、URL 里带密码:拒绝这次传输
Agent 和工作区里都没有长期的 git 凭据;每一次 fetch 都单独申请、单独吊销。
+

task exec -- <命令> 把工具链放到 PATH 最前面,再用 GIT_EXEC_PATH 指向一个镜像目录,其中 git-remote-http(s) 换成了连接器的包装程序,并给任务仓库的主机配上连接器的 credential helper。

+

每次 git 走 HTTP(S) 时,包装程序先检查这次传输会不会带上别的凭据:地址里有用户名或密码、对这个地址生效的 http.extraHeader、netrc 里出现这个主机或 default,或者这些查不了。有任何一项就拒绝这次传输。都没有时,它经 socket 向连接器开一个只读操作,连接器只在地址正好是任务仓库或声明过的依赖仓库时才向 Server 要 token;连接一断,token 立即吊销。

+

写权限只在交付时用:连接器自己推 attempt 分支时单独申请一枚写 token,推完就还。Agent 拿不到写凭据。

+

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

+ +

7. 收尾:先确认结果,再删东西

+

Agent 结束后,连接器先把结论写进 journal(阶段 finishing)。开发任务交付了的,用写 token 把交付的 commit 推到 kiln/attempt-<id>,再用 ls-remote 确认;没交付的,把现有改动作为 checkpoint 推到同一个分支,下一轮可以换一台机器接着做。然后 Complete,失败就重试,最长 30 分钟。

+

结果确认之后才清理:停掉测试服务,确认 Agent 已停、终端已释放,经 Orca 删除工作区、检出和本地分支,再核对 Orca、git 和磁盘上都没有了,最后删掉 journal 记录。删除前会核对名字、备注、路径和 git 登记,不是连接器建的一律不动。回收没完成就每分钟重试,12 小时后放弃并在日志里写明怎么手工处理。

+

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

+ +

崩溃了怎么办

+

整套设计的重点在这里。每一个会改变外部状态的动作之前,连接器都先在 journal/<attempt>.json 里记下要做什么:启动请求 id、结论、要不要推送、Complete 的内容。重启后逐条读 journal:

+
    +
  • 记了 Complete 的,重发;
  • +
  • 记了结论还没推送的,重做推送;
  • +
  • 停在 stopping、releasing、reclaiming 的,每分钟再试一次;
  • +
  • 读不了的记录不跳过、不删除:节点停止接新任务,在日志、doctor 和 Dashboard 上写明哪个文件、什么原因,等人处理。
  • +
+

测试也是按这个思路写的:约 580 个用例,用真实的 git、本地的 git HTTP 服务、真实的 unix socket 和多进程抢锁,还有大量「在某一步中途 epoch 过期 / 进程崩溃」的用例。

+ +

读到的问题

+

没有找到高危问题。值得改的几处,大多只在「Agent 和连接器是同一个用户」这个前提被当成安全边界时才要紧;Kiln 的文档自己也说这些是护栏,不是边界。

+
+ + + + + + + + + +
问题会怎样在哪
socket 只按 attempt id 区分调用方同时跑两个任务时,一个 Agent 可以冒充另一个任务领凭据、领 Issue、读文档。给任务命令加一个随机的每任务密钥就能补上host/run.ts:202
git 固定 10 分钟超时,clone 是完整 clone大仓库或慢网络下 clone 超时,下一次又从零开始,可能一直 infra.fetchcore/git.ts:50,412
共享 clone 自己的 .git/config 和 hooks 仍然生效上一轮的开发 Agent 留下的代理或 hook,会作用到后面任务里带 token 的 gitcore/git.ts:183
journal、状态文件写入后不 fsync断电后记录可能是空的;空的 journal 会让节点停止接活,直到有人删掉它core/journal.ts:215
clone 路径由 Server 给的仓库名拼出,删除前不检查是否在根目录内只有 Server 出错或被攻破时才会触发;回收代码里已经有这类检查,这里没有core/attempt.ts:428
报告文件超过 1 MiB 时,告诉 Agent 的是「可以稍后重试」Agent 可能反复重试直到超时core/attempt.ts:1534
+

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

+