Wait for Namespace runner terminal state
Some checks failed
Cache: Publish Nix / Publish Nix Cache (push) Failing after 22s
Build Rust / Cargo Test (push) Successful in 5m47s
Build Site / Next.js Build (push) Failing after 4s
Lint Governance / BEP Metadata (push) Successful in 1s

This commit is contained in:
Conrad Kramer 2026-06-07 08:57:28 -07:00
parent de32d8390e
commit 4d7c19e593
3 changed files with 44 additions and 2 deletions

View file

@ -113,6 +113,9 @@ The same change also makes the forge itself the release authority: release tags
- Keep the shared Linux runner work directory out of macOS bootstraps. The - Keep the shared Linux runner work directory out of macOS bootstraps. The
dispatcher normalizes macOS runners to `/tmp/forgejo-runner` when the shared dispatcher normalizes macOS runners to `/tmp/forgejo-runner` when the shared
config points at Linux state paths such as `/var/lib/forgejo-runner`. config points at Linux state paths such as `/var/lib/forgejo-runner`.
- Do not destroy Namespace Linux runners until `nsc describe` shows a real
terminal container state or tombstone. Empty describe payloads mean the
environment is still starting, not that the one-job runner has finished.
- Run forge Namespace services with the repo-owned `nsc` package and keep it - Run forge Namespace services with the repo-owned `nsc` package and keep it
current with the token format expected by Namespace. `nsc 0.0.520` is the current with the token format expected by Namespace. `nsc 0.0.520` is the
first required baseline for revokable token-file auth. The dispatcher and first required baseline for revokable token-file auth. The dispatcher and

View file

@ -284,22 +284,28 @@ func instanceStopped(output string) bool {
if len(payload) == 0 { if len(payload) == 0 {
return false return false
} }
seenTerminalState := false
for _, entry := range payload { for _, entry := range payload {
if len(entry.PerResource) == 0 {
return false
}
for _, target := range entry.PerResource { for _, target := range entry.PerResource {
if target.Tombstone != "" { if target.Tombstone != "" {
seenTerminalState = true
return true return true
} }
if len(target.Container) == 0 { if len(target.Container) == 0 {
continue return false
} }
for _, container := range target.Container { for _, container := range target.Container {
if container.Status != "stopped" && container.TerminatedAt == "" { if container.Status != "stopped" && container.TerminatedAt == "" {
return false return false
} }
seenTerminalState = true
} }
} }
} }
return true return seenTerminalState
} }
func (d *Dispatcher) waitForInstanceStop(ctx context.Context, runnerName, instanceID string, timeout time.Duration) bool { func (d *Dispatcher) waitForInstanceStop(ctx context.Context, runnerName, instanceID string, timeout time.Duration) bool {

View file

@ -0,0 +1,33 @@
package nsc
import "testing"
func TestInstanceStoppedRequiresObservedTerminalState(t *testing.T) {
t.Parallel()
cases := []struct {
name string
output string
want bool
}{
{name: "empty output", output: "", want: false},
{name: "empty response", output: "[]", want: false},
{name: "no resources yet", output: `[{"per_resource":{}}]`, want: false},
{name: "resource without containers", output: `[{"per_resource":{"runner":{}}}]`, want: false},
{name: "running container", output: `[{"per_resource":{"runner":{"container":[{"status":"running"}]}}}]`, want: false},
{name: "stopped container", output: `[{"per_resource":{"runner":{"container":[{"status":"stopped"}]}}}]`, want: true},
{name: "terminated container", output: `[{"per_resource":{"runner":{"container":[{"status":"running","terminated_at":"2026-06-07T15:00:00Z"}]}}}]`, want: true},
{name: "tombstone", output: `[{"per_resource":{"runner":{"tombstone":"destroyed"}}}]`, want: true},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
got := instanceStopped(tc.output)
if got != tc.want {
t.Fatalf("instanceStopped(%s) = %v, want %v", tc.output, got, tc.want)
}
})
}
}