Skip to content

feat(sandbox): reclaim leftovers from a previous boot - #58

Merged
nishide-dev merged 2 commits into
mainfrom
feat/reclaim-previous-boot
Oct 3, 2026
Merged

nishide-dev merged 2 commits into
mainfrom
feat/reclaim-previous-boot

Conversation

@nishide-dev

Copy link
Copy Markdown
Owner

概要

host の識別子(Linux は boot ID + PID namespace、macOS は host 名)が変わった後でも、同じマシン の残りもの(停止した sandbox container と preview の scratch directory)を回収できるようにします。Linux の再起動(電源断・kernel panic を含む)と macOS の host 名の変更が対象です。判定できない場合はこれまでどおり残します(安全側)。

変更内容

  • Creator に machine と boot の識別子(どちらも Option、texrun 用の接頭辞付き FNV-1a hash)を追加
    • Linux: /etc/machine-id(32 桁の hex。全 0 / uninitialized は不可)。texrun が 初期 PID namespace(pid:[4026531836])にいて、container の中でない(/.dockerenv・/run/.containerenv が無い)場合だけ記録する。boot は /proc/sys/kernel/random/boot_id。
    • macOS: IOPlatformUUID。/usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice を path で起動(shell 無し、空の環境、timeout 5 秒、出力 64 KiB まで、texrun_process::run 経由)。unsafe は使わない。boot は記録しない。
  • 判定(owner::relation、Creator::is_gone(created))
    • 同じ host → 従来どおり PID・開始時刻で判定
    • 同じ machine・どちらも boot 無し(macOS)→ PID で判定(host 名の変更に対応)
    • 同じ machine・boot が違う(Linux)→ 残りものが 今の boot の開始(/proc/stat の btime)より前に作られた 場合だけ回収(container は inspect の .Created、scratch directory は ctime)。machine-id を共有する別の kernel(複製した VM など)が runtime の socket を共有していても、動いている texrun のものを消さないため
    • それ以外(別 machine、片方に machine / boot が無い、同じ machine・同じ boot で host 違い、壊れた label)→ 残す
  • container の label に org.texrun.sandbox.machine / .boot を追加(分かる場合のみ)。ps の絞り込みは .uid までにし(前の boot のものは .host が違うため)、host / machine の照合は candidate で行う
  • scratch directory の名前を texrun-preview-<pid>-<start|x>-<host>-<machine|x>-<boot|x>-<random> に。Reclaim leftover sandbox containers and report the process limit in containers #49 形式(machine / boot 無し)の名前も読み、従来どおり host だけで判定する
  • 互換性: Reclaim leftover sandbox containers and report the process limit in containers #49 形式の label / 名前は新しい要素が無いものとして扱い、同じ host のものだけを従来どおり回収する。Reclaim leftover sandbox containers and report the process limit in containers #49 以前(.host 無し・random だけの名前)は回収しない(変更なし)
  • PR feat(sandbox): reclaim containers left by killed runs and report the process limit #53 再レビューの nit 2 件: reclaim_scratch_dirs の rustdoc を「per tree」に修正、回収の inspect に --type container
  • .Created の RFC 3339 parser を追加(Docker の Z、Podman の {{json .Created}} の offset 付きの両方)
  • docs: docs/security.md §2「sandbox backend で追加で保証する」の 5、§4「container のライフサイクル」「scratch directory の回収」、検証の表、docs/development.md を更新
  • runtime の検出や HostConfig の照合(Test the container backend with rootless Podman and handle rootless Docker #47 の範囲)には触れていません

確認方法

  • cargo check --workspace --all-targets --all-features --locked
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --all-features --locked(host: macOS)
  • cargo deny --locked check
  • host の Docker(OrbStack)で container test(docker build -t texrun-engine:latest docker/engine、TEXRUN_REQUIRE_SANDBOX=1)
    • texrun-sandbox: unit 40 + container 21(3 回繰り返し)
    • texrun-texlive の container / scenarios / security: 14 / 11 / 14
    • texrun-preview の container / real_tools: 4 / 13
    • CLI の container: 8
    • 終了後に label org.texrun.sandbox の container は 0 件
  • dev コンテナ(docker-compose run --rm dev cargo test --workspace --all-features --locked): すべて pass

追加した test:

  • owner.rs: 識別子の組み合わせごとの relation(同 host、同 machine・別 boot → OtherBoot、別 machine、片側の machine / boot 欠落、同 machine・同 boot・別 host → Unknown、macOS の machine のみ)、before_boot、作成時刻が今の boot 以降なら別 boot でも回収しない、machine-id と ioreg 出力の検証、tag の新旧形式
  • reclaim.rs: 同じ machine で host 違いの label の候補判定(壊れた label・別 machine・Reclaim leftover sandbox containers and report the process limit in containers #49 形式は残す)、.Created の parse
  • fsops.rs: Reclaim leftover sandbox containers and report the process limit in containers #49 形式の名前は従来どおり回収、別 boot(ctime が今の boot 以降)・別 machine は残す、macOS では host 名の変わった同じ machine のものを回収
  • container test containers_of_this_machine_are_judged_by_boot_and_creation: label を偽装した停止 container で、同 machine・別 boot(今作ったもの)、別 machine、壊れた label、machine 無しの別 host は残し、macOS では同 machine・別 host(dead PID)を回収することを実 daemon で確認

関連 Issue

Closes #56

補足

  • 残すもの(docs に明記): PID namespace が毎回新しくなる環境(使い捨ての container、dev コンテナ)。container の machine-id は image のものを多くの container で共有しうるので、別の kernel の texrun と区別できないため、machine を記録しません。machine-id / IOPlatformUUID が読めない環境も同様です。
  • Linux の別 boot の判定で .Created < btime を要求するのは、machine-id が同じ別の kernel が socket を共有しているという想定しにくい構成への保険です。電源断から再起動までの間に作られた container も、作成時刻は boot より前なので回収されます。
  • scratch directory の削除が entry 数の上限で途中で止まった場合、別 boot のものは ctime が更新されるので以後は回収されません(手で消す。docs に記載)。
  • inspect の format に {{json .Created}} を追加しました。Podman では .Created が time 型ですが、JSON にすると RFC 3339 になるので同じ parser で読めます(Podman 実機では未確認。読めなければ None で、別 boot の回収だけが行われない側に倒れます)。
  • 既存の container test only_stopped_containers_of_gone_texrun_processes_are_reclaimed は、並行する別 test の回収と競合しうるので、返り値の件数の assert を外し、container の有無だけで確認するようにしました。

🤖 Generated with Claude Code

Record the machine (Linux machine-id in the initial PID namespace outside
containers; macOS IOPlatformUUID) and the boot, so that leftovers of an
earlier boot of the same machine (created before this boot) and of a
renamed Mac are reclaimed. Anything else stays kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@nishide-dev nishide-dev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CHANGES_REQUESTED

PR #58(#56: 前の boot と、host 名を変えた後の残りものの回収)のレビューです(head 0f1d2c9)。「消してはいけないものを決して消さない」という観点で見ました。判定は全体として残す側に倒れていて、must-fix はありません。should-fix は 1 件で、Linux で btime による保険を通らずに別 boot の creator を PID で判定してしまう経路があります。強制はされていない不変条件に頼っているので、CHANGES_REQUESTED にします。修正は数行で済みます。

実行結果

clone した PR の head で、docker build -t texrun-engine:latest docker/engine(label 無し)を使いました。host は macOS、OrbStack です。

  • cargo fmt --check / cargo clippy --workspace --all-targets --all-features --locked -D warnings / cargo test --workspace --all-features --locked: すべて pass
  • dev コンテナ(docker-compose run --rm dev cargo test --workspace --all-features --locked): すべて pass
  • TEXRUN_REQUIRE_SANDBOX=1 の container test
    • texrun-sandbox: unit 40 + container 21 を 3 回繰り返し、すべて pass
    • texrun-texlive の container / scenarios / security: 14 / 11 / 14、pass
    • texrun-preview の container / real_tools: 4 / 13、pass
    • CLI の container: 8、pass
    • 終了後、label org.texrun.sandbox の container は 0 件でした
  • この Mac の ioreg -rd1 -c IOPlatformExpertDevice の出力は約 1.9 KB で、IOPlatformUUID の行は 1 行だけでした。64 KiB の上限には十分な余裕があります。
  • CI はすべて green です。

確認した点(問題なし)

Linux の machine と boot

  • machine を記録するのは、初期 PID namespace にいて、/.dockerenv も /run/.containerenv も無い場合だけです。初期 PID namespace は、1 つの kernel に 1 つしかありません。そのため、同じ kernel の中で machine と boot が同じなら、host(boot ID + ns)も必ず同じになり、SamePidSpace に入ります。--pid=host の container や hostPID の pod で marker が無い場合も、PID は実際に比較できるので、判定は正しいです。
  • 別 boot と判定される(OtherBoot)には、ラベルの boot が今と違うことが必要です。今の boot で生きている texrun の label は、今の boot ID を持ちます。そのため、同じ kernel の中で、生きている creator が OtherBoot と判定されることはありません。OtherBoot になりうる「生きている creator」は、machine-id が同じ別の kernel が runtime を共有している場合だけです。その場合の保険が .Created < btime です。
  • 時計の扱い。/proc/stat の btime は「今の wall clock − uptime」なので、時計を step したときは一緒に動きます。同じ kernel の daemon(rootful / rootless Docker、Podman)では、.Created と同じ時計です。前の boot の時計が進んでいた場合は、.Created が後ろにずれて残る側に倒れます。また、今の boot で作ったものは、そもそも OtherBoot になりません。したがって、時計のずれで誤って消える経路は、上の別 kernel の場合に限られます(nit 1)。btime は OnceLock に入れて最初の値を使い続けますが、その後に時計を進めても、判定が厳しくなるだけです。
  • ctime は所有者が任意の値にできません。変えられるのは「今」への更新だけで、これは残す側です。scratch directory は、自分の euid の 0700 のものに限られます。
  • 壊れた .machine / .boot / .started は、? で候補から外れます(host が同じでも外れます)。

macOS

  • 同じ machine で host 名だけが違う場合は、PID で判定します。再起動の後に PID が再利用されていれば「生きている」とみなすので、残ります。開始時刻が無いことも、残す方向にしか働きません。消えるのは、この Mac でその PID が使われていない場合だけです。
  • machine の hash には linux-machine / macos-machine の接頭辞が入るので、OS をまたいで一致することはありません。
  • ioreg の起動: path は固定で、is_file を確かめます。shell は使いません。Spec の既定は env_clear() の後の空の allowlist です。timeout は 5 秒、stdout は 64 KiB までで、上限を超えたら None です。stderr は捨てます。stop、失敗した終了、truncate のいずれでも None になり、machine 無し(Unknown、従来どおり host だけで判定)に倒れます。parse は、行頭(trim 後)の "IOPlatformUUID" = " から閉じ引用符までを取り、8-4-4-4-12 の hex で全て 0 でないことを確かめます。十分堅牢です。

互換性と ps の絞り込み

  • #49 形式の label(machine 無し)で host が違うものは、Unknown で残ります。#49 より前の形式(.host 無し)は、label(LABEL_HOST)? で残ります。scratch の名前では、#49 形式(host の後が 16 hex の 1 要素だけ)を machine・boot 無しとして読みます。新しい形式を #49 形式と読み違えた場合も、条件が厳しくなるだけです。
  • ps の絞り込みを .uid までにしたことで、候補(別 host の同じ uid のもの)は増えます。ただし inspect は読むだけです。消すかどうかは、これまでどおり candidate(label、uid、host または machine の関係、名前、停止状態)、is_gone、--force 無しの rm で決まります。安全性は下がっていません。--type container も付きました。
  • .Created の parser: Docker の Z と、Podman の offset 付き(符号の扱いも正しい)の両方を正しく読みます。小数は 9 桁で切り捨てます。不正な形式、1970 年より前、offset の無いものは None で、別 boot の回収だけが行われません。日付の検証は月ごとの日数を見ていませんが(2 月 31 日を受け付けます)、こうした値は繰り上がって後ろの時刻になるだけなので、消す方向には働きません。{{json .Created}} が空白を含む形になった場合は、label の JSON の parse ごと失敗して、その行は候補になりません。

テスト

  • only_stopped_... から件数の assert を外したことで、検証が弱くなってはいません。並行する別 test の回収も同じ判定を使うので、「消えたこと」と「残ったこと」を名前で確かめれば十分です。新しい test の「残す」container(同じ machine で別 boot、別 machine、壊れた label、#49 形式)は、並行する他の test の回収でも残ります。macOS の renamed は、他の test が先に消しても期待どおりです。

should-fix

1. Linux で「machine はあるが boot が無い」状態ができうる。両側がそうなると、btime の保険を通らずに PID で判定される

relation は、machine が一致し、両側とも boot が無い場合を SamePidSpace(macOS の想定)にします。しかし、その前提(boot が無いのは macOS だけ)は、コードでは強制されていません。

  • local() では、host_id() と machine_and_boot() が /proc/sys/kernel/random/boot_id を 別々に 読みます。host の読み取りが成功しても、2 回目の読み取りが一時的に失敗すれば(fd の枯渇など)、machine: Some, boot: None の Creator ができ、その状態で label や名前に記録されます。
  • 両側がこの状態になると、machine が同じで host が違う Linux の creator(=別 boot)を、.Created < btime を確かめずに PID と開始時刻で判定します。開始時刻は boot ごとの tick なので、ほぼ必ず違い、「gone」になります。同じ kernel ならこの判定でも結果は正しいです。しかし、この PR が保険を設けた「machine-id が同じ別 kernel」の場合には、その保険が外れます。

起きる確率は低いものの、判定の安全性が暗黙の不変条件に依存しているので、強制してください。

修正案(どちらか、できれば両方):

  • machine_and_boot の Linux 分岐で、boot が None なら machine も None にする(例: let machine = boot.and(machine);)。boot ID は host_id と共有して 1 回だけ読むと、なおよいです。
  • relation の (None, None) => SamePidSpace を macOS に限る。例えば cfg!(target_os = "macos") を条件にして、それ以外は Unknown にする。あわせて unit test に「Linux で machine のみの両側は Unknown」を足してください(OS によって期待値が変わるので、cfg で分けるか、relation に OS を引数で渡せる形にする)。

nit

  1. 「別 kernel を排除する」の表現と、時計の前提。 owner.rs の module doc は「which rules out another live kernel that happens to share the machine-id」と書いていますが、実際に排除できるのは「こちらの boot の後に作られたもの」だけです。security.md も「事実上起きない」と書いています。しかし、別 kernel の texrun が一時停止(SIGSTOP / Ctrl-Z など)していて、こちらの boot より前に作った container が止まったまま残っている場合は、その container を消しえます(影響は、その texrun が終了状態や OOM を読めなくなる程度です)。また、この比較は daemon の時計(.Created)とこちらの kernel の時計(btime)の比較です。そのため、別 kernel の構成では、両者の時計が合っていることが前提になります。rustdoc と §4 を「こちらの boot の後に作られたものを除外する(runtime の時計とこの kernel の時計が合っていることが前提)」という趣旨に直すと、正確になります。
  2. macOS の複製 VM。 IOPlatformUUID が同じ macOS の複製 VM が runtime の socket を共有している場合、machine が同じなので、host 名が違っても PID で判定されます(#49 でも、host 名が同じ複製 VM なら同じ状況だったので、この PR で生じた問題ではありません)。docs の「残すもの / 判定の前提」に一言書いておくとよいと思います。将来的には、/usr/sbin/sysctl -n kern.bootsessionuuid を boot として記録できます(ioreg と同じ起動方法で、unsafe は不要です)。そうすれば、macOS でも「同じ machine・同じ boot → PID」「別 boot → kern.boottime との比較」と、Linux と同じ保険を掛けられます。
  3. container test の後始末。 containers_of_this_machine_are_judged_by_boot_and_creation(と既存の only_stopped_...)は、assert が失敗すると、それ以降の container を rm せずに panic します。偽装した label の container が daemon に残るので、作った名前を Drop で rm --force する guard にすると確実です。
  4. development.md の表現。 「/etc/machine-id が読めない場合」に、macOS の「IOPlatformUUID が読めない場合」も並べると、security.md §2 の 5 と揃います。
  5. Linux の正の経路の検証。 another_boot_of_this_machine_needs_an_earlier_creation は、machine が無い環境(dev コンテナ、macOS)では早期 return します。実際に machine を記録した状態で通るのは、CI の test (linux) / sandbox(GitHub の runner VM は初期 PID namespace で動きます)だけです。その前提を test のコメントに書いておくと、後で runner が container に変わったときに、検証されなくなったことに気づけます。

@nishide-dev

Copy link
Copy Markdown
Owner Author

レビューありがとうございます。指摘に対応しました。

should-fix 1

  • boot_id を 1 回だけ読み、host の識別子と boot の両方をそこから作るようにしました(owner::identity)。
  • machine は boot が分かる場合にだけ記録します(identity.boot.and(identity.machine))。macOS も同じです。
  • relation は、machine と boot が両側にある場合だけを見ます。machine が同じで boot が同じ場合に SamePidSpace とするのは macOS だけにしました(ONE_PID_SPACE_PER_BOOT = cfg!(target_os = "macos"))。Linux では Unknown です。machine と boot が両側とも無い場合は、どの OS でも Unknown です。
  • unit test creators_are_related_by_host_machine_and_boot は、relation_in(.., one_pid_space_per_boot) を Linux と macOS の両方の値で確かめます。「machine だけで boot の無い」記録が、どちらの OS でも Unknown になることも確かめます。this_process_is_not_gone では、machine があれば boot もあることを確かめます。

nit

  1. owner.rs の module doc と §4 を、「今の boot の開始の後に作られたものを除外する。runtime の時計とこの kernel の時計が合っていることが前提」という表現に直しました。除外できない場合(別の kernel で一時停止した texrun が、こちらの boot より前に作ったもの)とその影響も書きました。
  2. macOS でも /usr/sbin/sysctl -n kern.bootsessionuuid kern.boottime を boot と boot の開始時刻として記録するようにしました。起動方法は ioreg と共通の run_small で、path 固定、shell 無し、空の環境、timeout 5 秒、64 KiB までです。これで macOS も Linux と同じ判定になりました。
    • 同じ machine で同じ boot なら、PID で判定します(host 名の変更)。
    • 同じ machine で別の boot なら、kern.boottime との比較で判定します。
    • IOPlatformUUID が同じ複製 VM の制約は、§4 に書きました。
    • sysctl の出力の parse にも unit test があります。
  3. 両方の container test に、作った名前を rm --force する RemoveOnDrop guard を付けました。
  4. development.md に、macOS の IOPlatformUUID・kern.bootsessionuuid(と Linux の boot_id)が読めない場合を並べました。
  5. another_boot_of_this_machine_needs_an_earlier_creation に、Linux で検証されるのは CI の runner(VM、初期 PID namespace)だけであることをコメントで書きました。machine が無い環境では SKIPPED を出すようにしました。

確認

  • cargo check / fmt --check / clippy -D warnings / test --workspace --all-features --locked / deny: pass
  • host の Docker(OrbStack)、TEXRUN_REQUIRE_SANDBOX=1:
    • texrun-sandbox: unit 41 + container 21 を 3 回、pass
    • texrun-texlive の container / scenarios / security: 14 / 11 / 14、pass
    • texrun-preview の container / real_tools: 4 / 13、pass
    • CLI の container: 8、pass
  • dev コンテナ: pass

補足: 同じ daemon で main の版の only_stopped_... が並行して動くと、この PR の回収が先に消すことがあり、main の版の件数の assert が失敗しえます(この PR ではその assert を外しています)。手元で、そうして残ったと思われる停止 container(作成した PID はすでに終了)を手で消しました。

@nishide-dev nishide-dev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

PR #58 の再レビューです(head a41708f、fix(sandbox): record the machine only with the boot, and the boot on macOS)。前回の should-fix 1 件は解消しました。nit 1〜5 もすべて対応されています。新しく入った macOS の boot(kern.bootsessionuuid / kern.boottime)も、「消してはいけないものを消す」方向には働かないことを確認しました。APPROVE とします。

実行結果

clone した最新の head を使い、engine image は label 無しの texrun-engine:latest です。host は macOS(OrbStack)です。

  • cargo fmt --check / cargo clippy --workspace --all-targets --all-features --locked -D warnings / cargo test --workspace --all-features --locked: すべて pass
  • dev コンテナ(docker-compose run --rm dev cargo test --workspace --all-features --locked): すべて pass
  • TEXRUN_REQUIRE_SANDBOX=1 の container test
    • texrun-sandbox: unit 41 + container 21 を 3 回繰り返し、すべて pass
    • texrun-texlive の container / scenarios / security: 14 / 11 / 14、pass
    • texrun-preview の container / real_tools: 4 / 13、pass
    • CLI の container: 8、pass
    • 終了後、label org.texrun.sandbox の container は 0 件でした
  • macOS で another_boot_of_this_machine_needs_an_earlier_creation が早期 return せずに実行されることを確かめました(machine と boot の両方が記録されます)。
  • この Mac の /usr/sbin/sysctl -n kern.bootsessionuuid kern.boottime の実際の出力は、「UUID の行」と「{ sec = N, usec = M } 日付」の 2 行で、macos_boot が想定する形と一致しました。
  • CI はすべて green です。

前回の指摘の確認

  • S1: 解消。
    • Linux では、boot_id を 1 回だけ読み、host と boot の両方をそこから作ります。boot が読めなければ identity 自体が None になります。
    • local() で machine = boot.and(machine) としたので、machine だけの記録はどの OS でも作られません。
    • relation_in は、machine と boot が両側に揃っている場合しか Unknown 以外を返しません。(None, None) は全ての OS で Unknown です。
    • 同じ machine・同じ boot・host 違いを SamePidSpace にするのは、ONE_PID_SPACE_PER_BOOT(cfg!(target_os = "macos"))の場合だけです。これで、前提がコードで強制されるようになりました。
    • 判定表は、Linux と macOS の両方の期待値を relation_in で直接確かめています。片側に machine や boot が無い場合も、両方の値で Unknown を確かめています。
    • host の hash の入力(Linux の linux\n<boot_id>\n<ns>、macOS の <os>\n<node>)は変わっていません。そのため、#49 の label との互換性は保たれています。前回の commit の形式(macOS の machine のみ)は merge されていないので、互換性の問題はありません。
  • nit 1(btime の保険の範囲と時計の前提): rustdoc と §4 に正確に書かれました。
  • nit 2(macOS の複製 VM): kern.bootsessionuuid は boot ごとに作られます。そのため、IOPlatformUUID が同じ複製 VM でも、別の boot として btime(kern.boottime)の保険の対象になります。
  • nit 3: RemoveOnDrop で、assert が失敗しても偽装した label の container が残らなくなりました。
  • nit 4・5: development.md の列挙と、test の SKIPPED / CI の前提のコメントが追加されました。

macOS の sysctl / ioreg の取得(run_small)

  • 起動する program は固定の絶対 path(/usr/sbin/ioreg、/usr/sbin/sysctl)で、is_file を確かめます。引数は固定の argv で、shell は使いません。Spec の既定は env_clear() の後の空の allowlist です。cwd は /、timeout は 5 秒、stdout は 64 KiB まで、stderr は捨てます。
  • stop、失敗した終了、truncate、UTF-8 でない出力のいずれでも None です。sysctl の日付の部分は locale や TZ に依存しますが、parse では読まずに捨てるので、空の環境でも問題ありません。
  • macos_boot は次のどれか 1 つでも満たさなければ None にします。
    • 1 行目が UUID(8-4-4-4-12、全て 0 でない)
    • 2 行目が { sec = <10 進>, usec = <10 進 < 1,000,000> } で始まる
    • 3 行目が無い
  • 取得に失敗すると、boot が無く、したがって machine も無い状態になり、host だけの判定(#49 と同じ)に戻ります。残す側です。

新しい判定表の評価

  • 同じ host: 従来どおり、PID と開始時刻で判定します。
  • 同じ machine・同じ boot・host 違い(macOS): 同じ kernel の同じ boot なので、PID は比較できます。PID が使われていれば残し、開始時刻が無いことも残す方向にしか働きません。Linux では、初期 PID namespace の制約によりこの組み合わせは起きないので、Unknown で残すのが正しいです。
  • 同じ machine・別 boot: 今の boot で生きている texrun の label は、今の boot を持ちます。そのため、同じ kernel の中で生きている creator がこの分類に入ることはありません。入りうるのは、machine の識別子が同じ別の kernel だけです。その場合も、今の boot の開始より後に作られたもの(.Created / ctime)は残ります。docs に書かれた残余(一時停止した別 kernel の texrun の、こちらの boot より前の container)は、影響が小さく、明記されているので、受け入れられます。
  • 時計: 同じ kernel では、時計の step や前の boot の時計の進みは、作成時刻を後ろにずらして残す側に倒れるだけです。macOS では .Created は runtime の VM の時計です。前の boot のものは通常 kern.boottime より前になり、VM の時計が遅れていても、影響しうるのは別 kernel の場合だけです(docs の前提どおり)。
  • macOS の scratch directory(/var/folders/.../T は再起動しても残る)も、別 boot のものは ctime < kern.boottime で回収されます。同じ boot のものは PID で判定されます。

nit(任意。merge を止めるものではありません)

  1. fsops.rs の reclaim_scratch_dirs の rustdoc で、same machine and boot), and no process with its PID and start time; or, #56, の行だけが他の行より長くなっています(rustfmt はコメントを折り返さないので、通っています)。次に触るときに折り返してください。

@nishide-dev
nishide-dev merged commit b0959b6 into main Oct 3, 2026
10 checks passed
@nishide-dev
nishide-dev deleted the feat/reclaim-previous-boot branch October 3, 2026 21:00
nishide-dev added a commit that referenced this pull request Oct 6, 2026
## 概要

`v*` の tag を push するだけで、検証 → engine image の公開 → **release notes 付き** の
GitHub release の作成(source tar 添付)まで完了するようにする。release notes は前の版の tag
から今回の tag までの commit(= squash merge した PR タイトル、Conventional Commits)を
git-cliff で分類して生成し、インストール方法・image の tag / digest・`gh attestation
verify`・source tar の説明を定型で付ける。既存 release の notes だけを作り直す workflow
も追加する(v0.1.0 の notes を埋めるのに使う)。

## 変更内容

- `cliff.toml`(新規): git-cliff の設定。type で分類(`feat` → Features / `fix` →
Bug fixes / `perf` → Performance / `docs` → Documentation /
`refactor`・`test`・`build`・`chore` → Other changes)。`chore(deps)` は
Dependencies に「N dependency updates: #a, #b」の 1 行にまとめる(PR 番号はタイトル行の末尾の
`(#N)` だけから取る。番号の無いものは件数にだけ数える)。`!` / `BREAKING CHANGE:` は Breaking
changes にも載せる。Conventional でない commit も Other changes に残す。**すべての行は
commit のタイトル(1 行目 = PR タイトル)だけから作り**、PR 本文や footer の文面は載せない。末尾の `(#N)` を
PR へのリンクにし、`@name` は mention にならないよう code にし、前の版との compare リンクを付ける。
- `.github/scripts/release-notes-test.sh` /
`release-notes-test.expected.md`(新規): 使い捨ての repository に main の squash
merge と同じ形の fixture の commit(PR 本文付き、実際の Dependabot 形式の本文付き(単独・group)、PR
番号の無い `chore(deps)`、日本語の `BREAKING CHANGE:` footer + attribution、GitHub
の Revert、`@name` を含むタイトル)を作り、notes の「What's changed」を期待値と比べる。PR の
`notes` job で毎回実行する。
- `.github/scripts/release-notes.sh`(新規): `release-notes.sh <tag>
[<digest>]` で notes の Markdown を出力する。
- 安定版は前の安定版から(間の prerelease を畳み込む: `--ignore-tags '^v.*-'`)、prerelease
は直前の tag から、最初の版は全履歴。git-cliff の `--context` から対象 tag の release だけを選んで
`--from-context` で描画するので、HEAD が tag より先(main)でも同じ notes になる。
- tag がまだ無い場合は「最後の tag 〜 HEAD」をその版としてプレビューする。digest を省略すると placeholder。
  - tag が HEAD の祖先でない、semver でない、digest の形式が違う、対象の commit が無い、などはエラー。
- `.github/workflows/engine-image.yml`
  - `publish` が `digest` を output する。
- `release` が checkout(`fetch-depth: 0`)→
git-cliff(`taiki-e/install-action` を SHA
pin、`[email protected]`。install-action が checksum を検証)→ notes 生成(job
summary にも出す)→ release の作成(`--notes-file`。版に `-` があれば prerelease
にする既存の扱いを維持)。
- release が既にある場合(手で作った / 再実行)は、notes を生成したもので **上書き** してから asset を
upload する。
- `.github/workflows/release-notes.yml`(新規): notes の生成だけを行う
workflow。image の公開・release の作成はしない。
- `pull_request`(`cliff.toml`・script・この workflow の変更時): fixture の test
の後、PR の head commit(merge ref ではなく。`Merge … into …` の行が入らない)で、最後の tag(現状
v0.1.0、全履歴)の notes と、次の版(patch + 1)としての「最後の tag 以降」の notes を job summary
と artifact `release-notes` に出す。digest は GHCR から引く(未公開の版は placeholder)。
- `workflow_dispatch`(`tag`、`update`): `update=false`(既定)は dry
run。`update=true` は `gh release edit --notes-file` で既存 release の notes
を置き換える(main か tag 上の実行のみ。image が GHCR に無い版は失敗)。
- 権限: 生成する `notes` job は `contents: read`。書き込む `update` job だけが
`contents: write` で、repository の code は実行しない(artifact を受け取って `gh release
edit` するだけ)。
- docs
- `docs/development.md`: release 手順を「tag を push するだけ」に更新し、「release
notes」節(分類の規則、notes の文面は PR タイトルで決まること、ローカルでの生成方法、作り直し方)を追加。
- `CONTRIBUTING.md`: PR タイトルが release notes の 1 行になること、type /
description の書き方の注意、notes の PR check を追記。
- `docs/security.md`(権限の記述)、`docs/engine-image.md`(digest は release
notes に載る)を追随。

## 設計判断

- **git-cliff を採用**(GitHub の自動生成 + `.github/release.yml` ではなく): この repo
は PR にラベルを付けない運用で、GitHub の自動生成はラベルでしか分類できない。git-cliff は commit の type
で分類でき、PR タイトル = commit タイトルの運用にそのまま合う。API を使わず(`--offline`)git
の履歴だけで決まるので、PR 上やローカルでも同じ結果を再現できる。
- **既存 release の notes は上書き**: notes は git の履歴と公開済みの digest
から決定的に作られるので、再実行で上書きしても結果は同じ。手で先に release を作った場合も、生成した notes に揃える(docs
に明記。公開後の手修正は、作り直すと消える)。
- **CHANGELOG.md は置かない**: tag ごとに CHANGELOG 更新の commit / PR
が必要になり、運用が増えるため。GitHub release を changelog とし、必要なら同じ `cliff.toml` から
`git cliff` でいつでも全履歴を出せる。
- **notes の作り直しは別 workflow**: engine-image.yml の `workflow_dispatch` は
image の公開と結び付いているので、notes だけの経路を分けた。image は再公開せず、digest は GHCR
にある既存の版から引く。
- **notes の生成は image の公開後**: digest が要るため `release` job で生成する。設定の誤りは PR
上の `Release notes / notes` で先に検出する。万一 `release` で失敗しても image は公開済みで、`gh
run rerun --failed` でやり直せる(既存の手順どおり)。
- **git-cliff の版**: `2.14.2` を両 workflow で固定(install-action の manifest の
sha256 で検証)。install-action 自体は SHA pin で、Dependabot の対象。

## 確認方法

- [x] `actionlint`(全 workflow)、`shellcheck
.github/scripts/release-notes.sh`
- [x] ローカルで git-cliff 2.14.2(公式 release の tar を sha512 で確認)を使って生成
  - `release-notes.sh v0.1.0 sha256:b611…` → 下記(v0.1.0 までの全履歴、32 commit)
  - `release-notes.sh v0.1.1` → v0.1.0 以降の差分(この PR の commit のみ)のプレビュー
- 使い捨ての clone で `v0.2.0-rc.1` / `v0.2.0-rc.2` / `v0.2.0` を打って確認: rc.2 は
rc.1 からの差分、v0.2.0 は v0.1.0 からの全部(rc の分を畳み込む)。tag が HEAD の祖先でない場合・semver
でない tag・不正な digest はエラーになる
- `release-notes-test.sh`: 期待値どおり(下記)。修正前の `cliff.toml`
に戻して実行すると、Dependabot の行が `3 dependency updates (Dependabot):,,`
に、Breaking changes が日本語の footer + `🤖 Generated with …` に、Revert
の行が本文付きに、`@octocat` が mention になり、test が失敗することを確認した
  - レビュー対応の後も v0.1.0 の notes は変わらない(前回の出力と diff なし)
- [x] `CONTRIBUTING.md` / `docs/development.md`: タイトルだけが載ること、`@name`
を書かないこと、`jq` が要ること、`update` は通常 `--ref main` で実行すること(v0.1.0 の tag の上には
workflow が無い)、fixture の test を追記
- [x] PR 上の `Release notes / notes` が、v0.1.0 と v0.1.1(プレビュー)の notes を
job summary と artifact に出す(GHCR から v0.1.0 の digest を引く)
- `workflow_dispatch` の dry run は、新規 workflow が default branch に入るまで
dispatch できないため、merge 後に `gh workflow run release-notes.yml --ref main
-f tag=v0.1.0` で確認する(PR 上の `pull_request` の実行が同じ生成を行う)
- tag の push・release の作成 / 編集・publish を有効にした実行はしていない
- Rust のコードは変更していない(cargo の品質ゲートは CI で確認)

### 生成例: v0.1.0(digest は GHCR の実際の値)

<details>
<summary>v0.1.0 の notes(全文)</summary>

````markdown
## What's changed

### Features

- **core**: Define compile domain model and engine interface ([#20](#20))
- **workspace**: Add isolated compile workspaces ([#21](#21))
- **diagnostics**: Parse LaTeX logs into structured diagnostics ([#23](#23))
- **texlive**: Add latexmk engine ([#30](#30))
- **preview**: Render PDF pages to PNG previews ([#31](#31))
- **cli**: Add compile command ([#34](#34))
- **workspace**: Exclude nested output directories by path ([#38](#38))
- **diagnostics**: Locate missing packages and fold fatal errors ([#40](#40))
- **diagnostics**: Report BibTeX failures ([#42](#42))
- **process**: Apply resource limits before exec through a gate ([#44](#44))
- **process**: Limit CPU, memory and process count ([#45](#45))
- **sandbox**: Add a container backend for the TeX engine ([#50](#50))
- **sandbox**: Render previews inside the container ([#52](#52))
- **sandbox**: Reclaim containers left by killed runs and report the process limit ([#53](#53))
- **sandbox**: Reclaim leftovers from a previous boot ([#58](#58))

### Bug fixes

- **workspace**: Refine exclusion and collection edge cases ([#29](#29))
- **texlive**: Restore the build after #39 and #40 ([#43](#43))
- **sandbox**: Accept engine images without labels ([#55](#55))
- **sandbox**: Support rootless Podman and refuse rootless Docker ([#57](#57))
- **sandbox**: Detect OOM kills reliably on Docker ([#61](#61))

### Documentation

- Add contribution guidelines and MIT license ([#15](#15))
- Add initial README ([#18](#18))
- **security**: Define the MVP security model and execution limits ([#22](#22))
- Update README to reflect the completed MVP ([#37](#37))
- Rewrite the README ([#59](#59))

### Other changes

- Initialize repository
- Bootstrap Rust workspace and toolchain ([#16](#16))
- **ci**: Add quality gates and dependency checks ([#19](#19))
- **docker**: Add TeX Live development environment ([#17](#17))
- Add TeX Live integration fixtures and CI job ([#33](#33))
- **process**: Extract shared subprocess execution ([#39](#39))
- **ci**: Publish the engine image to GHCR ([#51](#51))

## Install

```bash
cargo install --locked --git https://github.com/nishide-dev/texrun --tag
v0.1.0 texrun
```

See the [README](https://github.com/nishide-dev/texrun/blob/v0.1.0/README.md#installation) for the requirements and
the tools each backend needs.

## Engine image

The container backend (`--backend container`) runs TeX in the engine image
of this version, `ghcr.io/nishide-dev/texrun-engine:0.1.0` (linux/amd64, linux/arm64). texrun
never pulls it; pull it once:

```bash
docker pull ghcr.io/nishide-dev/texrun-engine:0.1.0
```

Published versions are never overwritten. To use exactly this image, pin its
digest:

```bash
docker pull
ghcr.io/nishide-dev/texrun-engine@sha256:b611748f16d50c00982da2e52b51939d50167bebbc22b35ab8741d1c39e00d1b
texrun compile --backend container --container-image
ghcr.io/nishide-dev/texrun-engine@sha256:b611748f16d50c00982da2e52b51939d50167bebbc22b35ab8741d1c39e00d1b
main.tex
```

The image has an SBOM, SLSA provenance and a signed GitHub artifact
attestation:

```bash
gh attestation verify oci://ghcr.io/nishide-dev/texrun-engine:0.1.0 -R
nishide-dev/texrun
```

## Source of the engine image

`texrun-engine-0.1.0-sources.tar` (below) has the Debian source packages
(`.dsc`, `.orig.tar.*`, `.debian.tar.*`) of every package in the image,
for both platforms, at exactly the installed versions (`packages.txt` and
`SHA256SUMS` inside): the corresponding source of its GPL / AGPL programs.
See [docs/engine-image.md](https://github.com/nishide-dev/texrun/blob/v0.1.0/docs/engine-image.md#licenses).
````

</details>

### 生成例: v0.1.0 以降の main の差分(次の版のプレビュー)

````markdown
## What's changed

### Bug fixes

- **ci**: Build release notes lines from commit titles only

### Other changes

- **ci**: Generate release notes from conventional commits
- **ci**: Write release notes on tag push and add a notes-only workflow

**Full diff**: [v0.1.0...v0.1.1](v0.1.0...v0.1.1)
````

(以下の Install / Engine image / Source は v0.1.0 と同じ形で、digest は
placeholder。squash merge 後は 1 commit になる)

### 生成例: fixture(`release-notes-test.expected.md`)

````markdown
## What's changed

### Breaking changes

- **cli**: Rename --json flag to --format json ([#4](#4))

### Features

- **cli**: Rename --json flag to --format json ([#4](#4))

### Bug fixes

- **diagnostics**: Report the error `@octocat` found ([#7](#7))

### Other changes

- Revert "fix(core): handle empty logs ([#5](#5))" ([#6](#6))

### Dependencies

- 3 dependency updates: [#2](#2), [#3](#3)

**Full diff**: [v0.1.0...v0.2.0](v0.1.0...v0.2.0)
````

## 補足

- merge 後、v0.1.0 の notes を埋めるには: `gh workflow run release-notes.yml
--ref main -f tag=v0.1.0`(dry run、summary で確認)の後に `gh workflow run
release-notes.yml --ref main -f tag=v0.1.0 -f update=true`。
- notes の文面は PR タイトルで決まる。merge 後に誤りに気付いた場合は release を手で編集できるが、作り直すと消える。
- 推奨(任意): `release-notes.yml` の `update` job にも、engine-image.yml と同様に
`environment` を付けることを検討できる(docs/security.md の「release の入口」)。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reclaim sandbox leftovers from a previous boot of the same machine

1 participant