mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
CI / build (push) Failing after 33s
Go / generate (push) Failing after 46s
The git ceiling named the workspace, which git only applies to a proper ancestor of the directory it starts from, so a request with no dir found, read and wrote a repository above the workspace. The ceiling is now the workspace's parent, which refuses from the root and from any directory under it. patch staged by action id, so two changes naming one file collided and the second failed with the first's bytes already in place, and a delete that could not happen left earlier renames behind. Every change now stages under a random name, the file that was there is kept on a second link until every move has landed, and a move that fails is put back. A diff that names one file twice, gives two names for one file, would delete a directory, or renames is refused. A zero-length packet is a packet on SOCK_SEQPACKET, and reading it as end of file ended the daemon for good. POLLRDHUP tells the two apart. Also: a listing fills a page to what a frame holds instead of promising 4096 entries no frame can carry; write and patch resolve the parent with openat2 on the path as written, so one string cannot mean two places; a refused request is not recorded, so its id is free, while an action that ran is recorded whatever came of it; a staged name is random, so a workspace file is never unlinked to make room; children start from a declared environment instead of the daemon's; write reports the mode on disk and keeps the mode a file had; mode means permission bits in stat as well as read and list; a read past the end is refused; an oversize refusal names the op it refused; the ledger is bounded by bytes as well as count; the diff path is the reading both header lines agree on; the build constraint sits above the package doc; and BUILD embeds a library, which is how the repo builds a main package with tests. Co-authored-by: Hanzo Dev <[email protected]>
84 lines
2.6 KiB
Go
84 lines
2.6 KiB
Go
// Copyright 2026 The gVisor Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//go:build linux
|
|
|
|
// execd runs inside a visor sandbox and does what a coding agent asks of an
|
|
// operating system: run a program, drive a pty, read and write files, watch
|
|
// them, apply a diff, run git. It knows nothing about models, sessions or
|
|
// plans — those live outside the sandbox and reach it as actions.
|
|
//
|
|
// It serves ZAP frames on one descriptor it inherits already connected: FD 3,
|
|
// one end of a SOCK_SEQPACKET socketpair the host made. There is no listen,
|
|
// no connect and no path in a filesystem. See docs/execd.md.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// hostFd is the descriptor the host connects before exec: one end of a
|
|
// socketpair, already connected, inherited across the exec.
|
|
const hostFd = 3
|
|
|
|
func main() {
|
|
workspace := flag.String("workspace", "", "directory every path in a request is resolved beneath")
|
|
fd := flag.Int("fd", hostFd, "inherited connected SOCK_SEQPACKET descriptor")
|
|
flag.Parse()
|
|
|
|
if *workspace == "" {
|
|
die(fmt.Errorf("-workspace is required"))
|
|
}
|
|
if err := checkSocket(*fd); err != nil {
|
|
die(err)
|
|
}
|
|
r, err := openRoot(*workspace)
|
|
if err != nil {
|
|
die(err)
|
|
}
|
|
defer r.close()
|
|
|
|
if err := newDaemon(*fd, r).serve(); err != nil {
|
|
die(err)
|
|
}
|
|
}
|
|
|
|
// checkSocket refuses anything that is not the contract: a connected
|
|
// sequenced-packet socket. It also asks the kernel for room for a whole
|
|
// frame, which is a request and not a requirement.
|
|
func checkSocket(fd int) error {
|
|
kind, err := unix.GetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_TYPE)
|
|
if err != nil {
|
|
return fmt.Errorf("descriptor %d is not a socket: %w", fd, err)
|
|
}
|
|
if kind != unix.SOCK_SEQPACKET {
|
|
return fmt.Errorf("descriptor %d is socket type %d, not SOCK_SEQPACKET", fd, kind)
|
|
}
|
|
if _, err := unix.Getpeername(fd); err != nil {
|
|
return fmt.Errorf("descriptor %d is not connected: %w", fd, err)
|
|
}
|
|
unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_SNDBUF, 4*frameMax)
|
|
unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_RCVBUF, 4*frameMax)
|
|
return nil
|
|
}
|
|
|
|
func die(err error) {
|
|
fmt.Fprintf(os.Stderr, "execd: %v\n", err)
|
|
os.Exit(1)
|
|
}
|