Expose missing Jeannie labs through API
Homelab Main / validate (push) Successful in 1m17s Details
Homelab Main / running-update (push) Successful in 3s Details
Homelab Main / debian-ops (push) Successful in 2m35s Details

This commit is contained in:
juvenal.diaz 2026-11-10 22:03:56 -06:00
parent 97e1932f18
commit c4aee8b391
7 changed files with 99 additions and 7 deletions

View File

@ -72,7 +72,7 @@ var allowedCommands = map[string]bool{
"oci": true,
"secrets-init": true, "secrets-check": true, "tailnet-policy-check": true,
"secrets": true,
"ai-index": true, "ai-check": true, "ask": true, "ai-evals": true,
"ai-index": true, "ai-check": true, "ask": true, "ai-evals": true, "ai-lab": true, "gateway-lab": true, "secrets-lab": true, "progressive-lab": true, "goose-graph": true,
"ai-scheduler": true, "ai-memory": true, "model-observe": true,
"impact": true, "review-last-change": true,
"security-scan": true, "security-prepare": true, "security-zap": true,
@ -271,6 +271,10 @@ func (s *server) execute(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusForbidden, map[string]string{"error": "command is not remotely enabled"})
return
}
if request.Command == "goose-graph" && (len(request.Args) == 0 || (request.Args[0] != "update" && request.Args[0] != "context")) {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "interactive goose-graph actions require a terminal; use context through the API"})
return
}
item := &execution{ID: newID(), Command: request.Command, Args: request.Args, Status: "queued", StartedAt: time.Now().UTC()}
s.mu.Lock()
s.exec[item.ID] = item
@ -285,7 +289,7 @@ func (s *server) run(item *execution) {
return
}
s.update(item.ID, func(item *execution) { item.Status = "running" })
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
ctx, cancel := context.WithTimeout(context.Background(), jeannieworkflow.CommandTimeout(item.Command, item.Args))
defer cancel()
args := append([]string{item.Command}, item.Args...)
command := exec.CommandContext(ctx, filepath.Join(s.repoRoot, "jeannie"), args...)

View File

@ -7,6 +7,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
@ -173,3 +174,38 @@ func TestOCICommandIsRemotelyEnabled(t *testing.T) {
t.Fatal("oci must be exposed through the remote API")
}
}
func TestPublicJeannieCommandsAreRemotelyEnabled(t *testing.T) {
data, err := os.ReadFile(filepath.Join("..", "..", "jeannie"))
if err != nil {
t.Fatal(err)
}
text := string(data)
start := strings.LastIndex(text, "\ncase \"${1:-}\" in\n")
if start < 0 {
t.Fatal("public command dispatcher not found")
}
pattern := regexp.MustCompile(`(?m)^ ([a-z][a-z0-9-]*)\)`)
matches := pattern.FindAllStringSubmatch(text[start:], -1)
if len(matches) < 100 {
t.Fatalf("unexpectedly few public commands found: %d", len(matches))
}
for _, match := range matches {
if !allowedCommands[match[1]] {
t.Errorf("public command %q is missing from API allowlist", match[1])
}
}
}
func TestRemoteGooseGraphRejectsInteractiveActions(t *testing.T) {
s := &server{exec: make(map[string]*execution), repoRoot: t.TempDir()}
for _, action := range []string{"learn", "propose", "--"} {
payload, _ := json.Marshal(executeRequest{Command: "goose-graph", Args: []string{action, "question"}})
request := httptest.NewRequest(http.MethodPost, "/v1/execute", bytes.NewReader(payload))
response := httptest.NewRecorder()
s.execute(response, request)
if response.Code != http.StatusBadRequest {
t.Errorf("action %q: got %d, want %d", action, response.Code, http.StatusBadRequest)
}
}
}

View File

@ -28,6 +28,19 @@ Execution state is stored in memory and command output is returned through
GET /v1/executions/{id}. It is not a public edge service and does not accept
arbitrary shell commands.
The API includes `ai-lab`, `gateway-lab`, `secrets-lab`, `progressive-lab`,
and `goose-graph`. For example, `./jeannie remote ai-lab suite 3` runs the
suite on Debian. AI lab installation and suite commands have a two-hour limit;
other commands retain the 30-minute limit. The output arrives when the
execution finishes, rather than streaming live. The API and Temporal worker
must both be updated for the extended Temporal activity limit.
Remote AI lab installation needs non-interactive sudo for the API service user
when system packages must be installed. The lab fails with an explanatory error
if it cannot get it; a user can run the install from a Debian terminal instead.
`goose-graph update` and `context` are available remotely. Its `learn` and
`propose` modes require an interactive terminal and are rejected by the API.
`cluster-runtime check` and `cluster-transition k3s-to-native [--yes]` are
allowlisted as well. The transition runs on Debian, archives the accidental
laptop K3s state, prepares verified registry storage on the declared ARM host,

View File

@ -3,6 +3,7 @@ package jeannieworkflow
import (
"strings"
"testing"
"time"
)
func TestNewExecutionDropsInheritedProfilePin(t *testing.T) {
@ -20,3 +21,14 @@ func TestNewExecutionDropsInheritedProfilePin(t *testing.T) {
t.Fatal("new operation lost its remote flag or unrelated configuration")
}
}
func TestCommandTimeoutForLongAILabWork(t *testing.T) {
for _, action := range []string{"suite", "install", "colibri-install", "colibri-prepare"} {
if got := CommandTimeout("ai-lab", []string{action}); got != 2*time.Hour {
t.Errorf("%s timeout = %s", action, got)
}
}
if got := CommandTimeout("status", nil); got != 30*time.Minute {
t.Errorf("status timeout = %s", got)
}
}

View File

@ -41,9 +41,20 @@ func CommandEnvironment() []string {
return append(result, "JEANNIE_REMOTE_SERVER=true")
}
// Long-running lab builds and suites need more than the normal command limit.
func CommandTimeout(command string, args []string) time.Duration {
if command == "ai-lab" && len(args) > 0 {
switch args[0] {
case "suite", "install", "colibri-install", "colibri-prepare":
return 2 * time.Hour
}
}
return 30 * time.Minute
}
func Workflow(ctx workflow.Context, input CommandInput) (CommandResult, error) {
options := workflow.ActivityOptions{
StartToCloseTimeout: 30 * time.Minute,
StartToCloseTimeout: CommandTimeout(input.Command, input.Args),
RetryPolicy: &temporal.RetryPolicy{
MaximumAttempts: 1,
},

View File

@ -150,13 +150,23 @@ def checkout(destination, repo, tag, prefix):
return commit
def apt_command(*args):
if os.environ.get("JEANNIE_REMOTE_SERVER") == "true":
try:
command(["sudo", "-n", "apt-get", *args])
except RuntimeError as exc:
raise RuntimeError("Remote apt failed; check its output and non-interactive sudo for the API user, or run the install from a Debian terminal") from exc
else:
command(["sudo", "apt-get", *args])
def install():
workspace()
if shutil.disk_usage(ROOT).free < 5 * 1024 ** 3:
raise RuntimeError(f"Need at least 5 GiB free in {ROOT} to build the lab")
packages = ["git", "build-essential", "cmake", "libvulkan-dev", "glslc", "spirv-headers", "vulkan-tools", "mesa-vulkan-drivers"]
command(["sudo", "apt-get", "update"])
command(["sudo", "apt-get", "install", "-y", *packages])
apt_command("update")
apt_command("install", "-y", *packages)
commit = checkout(SOURCE, REPOSITORY, TAG, COMMIT_PREFIX)
command(["cmake", "-S", str(SOURCE), "-B", str(SOURCE / "build"), "-DCMAKE_BUILD_TYPE=Release", "-DGGML_VULKAN=ON"])
command(["cmake", "--build", str(SOURCE / "build"), "--config", "Release", "--parallel", "2"])
@ -171,8 +181,8 @@ def install_colibri():
if shutil.disk_usage(ROOT).free < 2 * 1024 ** 3:
raise RuntimeError("Colibri build requires at least 2 GiB free in the lab workspace")
if not all(shutil.which(tool) for tool in ("git", "gcc", "make")):
command(["sudo", "apt-get", "update"])
command(["sudo", "apt-get", "install", "-y", "git", "build-essential"])
apt_command("update")
apt_command("install", "-y", "git", "build-essential")
commit = checkout(COLIBRI_SOURCE, COLIBRI_REPO, COLIBRI_TAG, COLIBRI_COMMIT)
command(["make", "-C", str(COLIBRI_SOURCE / "c"), "qwen36", "ARCH=native", "-j2"])
if not COLIBRI_CLI.is_file() or not (COLIBRI_SOURCE / "c/qwen36").is_file():

View File

@ -97,6 +97,12 @@ class AiLabTest(unittest.TestCase):
self.assertIsNone(metrics["lookup_decode_tokens_per_second_including_startup"])
self.assertIsNone(metrics["rss_after_weight_load_gb"])
def test_remote_install_reports_unavailable_sudo_without_prompting(self):
with mock.patch.dict(lab.os.environ, {"JEANNIE_REMOTE_SERVER": "true"}), mock.patch.object(lab, "command", side_effect=RuntimeError("failed")) as run:
with self.assertRaisesRegex(RuntimeError, "non-interactive sudo"):
lab.apt_command("update")
self.assertEqual(run.call_args.args[0], ["sudo", "-n", "apt-get", "update"])
if __name__ == "__main__":
unittest.main()