mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-24 00:50:54 +08:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d235be850e | ||
|
|
6ec01e007e | ||
|
|
9f0436e272 | ||
|
|
410d8fa7f2 | ||
|
|
8040e38faf | ||
|
|
1aaa7a479b | ||
|
|
b7e766ffe4 |
@@ -12,6 +12,8 @@ All notable changes to this project are documented in this file. The format is b
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Task timeout triggers fire for every task**: `on_task_timeout` used the task id as a watermark, but tasks time out in deadline order. Once a newer task timed out first, an older task that timed out later was never fired for. Fired timeouts are now kept in a persisted set, like met goals; on first start the set is seeded with the tasks already timed out, so nothing replays.
|
||||
- **A named pipe in the task workspace no longer hangs the archive worker**: packing opened every non-directory entry, and opening a FIFO blocks until a writer appears, so the single archive worker stopped there and every later archive, restore and delete job waited behind it. A socket failed the archive instead, and a device was packed but refused on restore. The packer now skips every entry that is neither a directory nor a regular file, as it already did for symlinks.
|
||||
- **Task form does not keep test-account secrets on screen**: after a task is created the credential rows are cleared, and the password field is masked.
|
||||
- **LLM connection-test logs stay one line**: the response body written by a connection test has CR and LF replaced with spaces before it is logged, so the body cannot start a second log record.
|
||||
- **Benchmark judge validation**: grading and the judge's falsification battery require one verdict per ground-truth ID, actual boolean decisions and gates, and matches to the supplied scanner findings. Invalid grading responses use the existing three-attempt budget and abort without writing scores, rather than counting duplicate IDs or truthy strings such as `"false"`.
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
# ---------------------------------------------------------------- frontend ---
|
||||
# Pinned to the Node 22 line the CI/release workflows use. On the build platform
|
||||
# only; the frontend static export is architecture-independent.
|
||||
FROM --platform=$BUILDPLATFORM node:26-bookworm-slim@sha256:5df79989ed685e09f0a98019db4cebfb22fb9df1a53c0161664a011f7ff6b0f1 AS web
|
||||
FROM --platform=$BUILDPLATFORM node:22-bookworm-slim@sha256:e9f565d32859f0cbfb52125eafe8be39390f24dac302dc3cdf566e8ba3ab21ee AS web
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
WORKDIR /src/web
|
||||
COPY web/package.json web/package-lock.json ./
|
||||
|
||||
+7
-6
@@ -189,13 +189,14 @@ ORDER BY n.id`, lastID)
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// TimedOutTasksSince returns tasks that reached status='timeout' with id > lastID,
|
||||
// ordered by id (monotonic watermark → no double-fire across restarts).
|
||||
func (d *DB) TimedOutTasksSince(lastID int64) ([]TaskEvent, error) {
|
||||
// TimedOutTasks returns all live tasks in status='timeout', ordered by id. Tasks
|
||||
// time out in deadline order, not id order, so the scheduler filters out the
|
||||
// ones it already fired for via its persisted fired-set, not an id watermark.
|
||||
func (d *DB) TimedOutTasks() ([]TaskEvent, error) {
|
||||
rows, err := d.Query(`
|
||||
SELECT id, description, goal FROM tasks
|
||||
WHERE status='timeout' AND deleted_at IS NULL AND id > $1
|
||||
ORDER BY id`, lastID)
|
||||
WHERE status='timeout' AND deleted_at IS NULL
|
||||
ORDER BY id`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -206,7 +207,7 @@ ORDER BY id`, lastID)
|
||||
if err := rows.Scan(&e.NodeID, &e.TaskDesc, &e.TaskGoal); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.TaskID = e.NodeID // task id doubles as NodeID for the watermark
|
||||
e.TaskID = e.NodeID // task id doubles as NodeID for the fired-set
|
||||
e.Summary = e.TaskGoal
|
||||
out = append(out, e)
|
||||
}
|
||||
|
||||
+41
-29
@@ -28,7 +28,7 @@ type Scheduler struct {
|
||||
const (
|
||||
schedKeyLastFinding = "last_finding_id" // watermark: max finding node id fired for
|
||||
schedKeyFiredGoals = "fired_goals" // JSON array of goal node ids already fired
|
||||
schedKeyLastTimeout = "last_timeout_id" // watermark: max task id fired for task timeout
|
||||
schedKeyFiredTimeouts = "fired_timeouts" // JSON array of task ids already fired for task timeout
|
||||
schedKeyLastToolCall = "last_toolcall_id" // watermark: max activity id fired for tool call
|
||||
schedKeyLastTaskCreate = "last_taskcreate_id" // watermark: max task id fired for task create
|
||||
)
|
||||
@@ -77,18 +77,16 @@ func (sc *Scheduler) init() {
|
||||
set[e.NodeID] = true
|
||||
}
|
||||
}
|
||||
sc.saveFiredGoalSet(set)
|
||||
sc.saveFiredSet(schedKeyFiredGoals, set)
|
||||
}
|
||||
if sc.mustState(schedKeyLastTimeout) == "" {
|
||||
var maxID int64
|
||||
if evs, err := sc.pg.TimedOutTasksSince(0); err == nil {
|
||||
if sc.mustState(schedKeyFiredTimeouts) == "" {
|
||||
set := map[int64]bool{}
|
||||
if evs, err := sc.pg.TimedOutTasks(); err == nil {
|
||||
for _, e := range evs {
|
||||
if e.NodeID > maxID {
|
||||
maxID = e.NodeID
|
||||
}
|
||||
set[e.NodeID] = true
|
||||
}
|
||||
}
|
||||
_ = sc.pg.SetSchedState(schedKeyLastTimeout, strconv.FormatInt(maxID, 10))
|
||||
sc.saveFiredSet(schedKeyFiredTimeouts, set)
|
||||
}
|
||||
if sc.mustState(schedKeyLastToolCall) == "" {
|
||||
var maxID int64
|
||||
@@ -195,7 +193,7 @@ func (sc *Scheduler) fireGoals(triggers []*db.AgentTrigger) {
|
||||
}
|
||||
// Mark goals as consumed whether or not a trigger is active, so enabling an
|
||||
// on_goal_met trigger later doesn't replay every already-met goal.
|
||||
fired := sc.firedGoalSet()
|
||||
fired := sc.firedSet(schedKeyFiredGoals)
|
||||
changed := false
|
||||
for _, e := range events {
|
||||
if fired[e.NodeID] {
|
||||
@@ -212,12 +210,14 @@ func (sc *Scheduler) fireGoals(triggers []*db.AgentTrigger) {
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
sc.saveFiredGoalSet(fired)
|
||||
sc.saveFiredSet(schedKeyFiredGoals, fired)
|
||||
}
|
||||
}
|
||||
|
||||
// fireTaskTimeouts fires on_task_timeout triggers for tasks that newly reached
|
||||
// status='timeout' above the persisted watermark (task id → no double-fire).
|
||||
// status='timeout'. Tasks time out in deadline order, not id order, so fired
|
||||
// tasks are kept in a persisted set (like goals) rather than an id watermark:
|
||||
// a watermark would skip an older task that times out after a newer one.
|
||||
func (sc *Scheduler) fireTaskTimeouts(triggers []*db.AgentTrigger) {
|
||||
var want []*db.AgentTrigger
|
||||
for _, tr := range triggers {
|
||||
@@ -225,17 +225,8 @@ func (sc *Scheduler) fireTaskTimeouts(triggers []*db.AgentTrigger) {
|
||||
want = append(want, tr)
|
||||
}
|
||||
}
|
||||
last, _ := strconv.ParseInt(sc.mustState(schedKeyLastTimeout), 10, 64)
|
||||
events, err := sc.pg.TimedOutTasksSince(last)
|
||||
if err != nil || len(events) == 0 {
|
||||
return
|
||||
}
|
||||
// Advance the watermark even with no active trigger — see fireFindings.
|
||||
maxID := last
|
||||
for _, e := range events {
|
||||
if e.NodeID > maxID {
|
||||
maxID = e.NodeID
|
||||
}
|
||||
// Consume the timeouts even with no active trigger — see fireFindings.
|
||||
for _, e := range sc.newTaskTimeouts() {
|
||||
if len(want) == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -244,7 +235,28 @@ func (sc *Scheduler) fireTaskTimeouts(triggers []*db.AgentTrigger) {
|
||||
sc.s.StartTriggeredRun(tr.AgentKey, fmt.Sprintf("Timeout trigger · task#%d", e.TaskID), tr.TaskTimeoutMessage+msgCtx, e.TaskID, true, e.TaskDesc, e.TaskGoal)
|
||||
}
|
||||
}
|
||||
_ = sc.pg.SetSchedState(schedKeyLastTimeout, strconv.FormatInt(maxID, 10))
|
||||
}
|
||||
|
||||
// newTaskTimeouts returns the timed-out tasks not fired for yet and records
|
||||
// them as consumed.
|
||||
func (sc *Scheduler) newTaskTimeouts() []db.TaskEvent {
|
||||
events, err := sc.pg.TimedOutTasks()
|
||||
if err != nil || len(events) == 0 {
|
||||
return nil
|
||||
}
|
||||
fired := sc.firedSet(schedKeyFiredTimeouts)
|
||||
var out []db.TaskEvent
|
||||
for _, e := range events {
|
||||
if fired[e.NodeID] {
|
||||
continue
|
||||
}
|
||||
fired[e.NodeID] = true
|
||||
out = append(out, e)
|
||||
}
|
||||
if len(out) > 0 {
|
||||
sc.saveFiredSet(schedKeyFiredTimeouts, fired)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// fireTaskCreates fires on_task_create triggers for tasks newly created above the
|
||||
@@ -347,9 +359,9 @@ func (sc *Scheduler) mustState(key string) string {
|
||||
return v
|
||||
}
|
||||
|
||||
func (sc *Scheduler) firedGoalSet() map[int64]bool {
|
||||
func (sc *Scheduler) firedSet(key string) map[int64]bool {
|
||||
out := map[int64]bool{}
|
||||
raw := sc.mustState(schedKeyFiredGoals)
|
||||
raw := sc.mustState(key)
|
||||
if raw == "" {
|
||||
return out
|
||||
}
|
||||
@@ -362,13 +374,13 @@ func (sc *Scheduler) firedGoalSet() map[int64]bool {
|
||||
return out
|
||||
}
|
||||
|
||||
func (sc *Scheduler) saveFiredGoalSet(set map[int64]bool) {
|
||||
func (sc *Scheduler) saveFiredSet(key string, set map[int64]bool) {
|
||||
ids := make([]int64, 0, len(set))
|
||||
for id := range set {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
b, _ := json.Marshal(ids)
|
||||
if err := sc.pg.SetSchedState(schedKeyFiredGoals, string(b)); err != nil {
|
||||
log.Printf("[scheduler] save fired goals failed: %v", err)
|
||||
if err := sc.pg.SetSchedState(key, string(b)); err != nil {
|
||||
log.Printf("[scheduler] save %s failed: %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Autumn-27/artex/db"
|
||||
)
|
||||
|
||||
// Tasks time out in deadline order, not in id order: a task created later with
|
||||
// a shorter timeout can time out first. Each timeout must still fire once.
|
||||
func TestSchedulerTaskTimeoutsFireOutOfIDOrder(t *testing.T) {
|
||||
skipWithoutDSN(t)
|
||||
m, err := NewManager(t.TempDir(), "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { m.Close() })
|
||||
sc := &Scheduler{pg: m.pg}
|
||||
sc.newTaskTimeouts() // consume timeouts other tests left behind
|
||||
|
||||
var ids [2]int64
|
||||
for i := range ids {
|
||||
task, err := m.pg.CreateTaskWithOptions("timeout order", "goal", db.TaskCreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ids[i] = task.ID
|
||||
t.Cleanup(func() { _ = m.pg.DeleteTask(task.ID) })
|
||||
}
|
||||
older, newer := ids[0], ids[1]
|
||||
timeOut := func(id int64) {
|
||||
t.Helper()
|
||||
if _, err := m.pg.Exec(`UPDATE tasks SET status='timeout' WHERE id=$1`, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
fired := func() []int64 {
|
||||
var out []int64
|
||||
for _, e := range sc.newTaskTimeouts() {
|
||||
if e.TaskID == older || e.TaskID == newer {
|
||||
out = append(out, e.TaskID)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
timeOut(newer)
|
||||
if got := fired(); len(got) != 1 || got[0] != newer {
|
||||
t.Fatalf("after the newer task timed out: fired %v, want [%d]", got, newer)
|
||||
}
|
||||
timeOut(older)
|
||||
if got := fired(); len(got) != 1 || got[0] != older {
|
||||
t.Fatalf("after the older task timed out: fired %v, want [%d]", got, older)
|
||||
}
|
||||
if got := fired(); len(got) != 0 {
|
||||
t.Fatalf("second scan fired %v again, want nothing", got)
|
||||
}
|
||||
}
|
||||
@@ -639,6 +639,12 @@ func writeTaskArchivePackage(path, payloadDir string, snapshot *pgdb.TaskArchive
|
||||
log.Printf("[task-archive] skipping symlink (unsupported by the archive, other files unaffected): %s", current)
|
||||
return nil
|
||||
}
|
||||
if !entry.IsDir() && !info.Mode().IsRegular() {
|
||||
// A named pipe, socket or device left by a command: opening a pipe blocks until
|
||||
// a writer appears, tar refuses a socket, and the unpacker refuses the rest.
|
||||
log.Printf("[task-archive] skipping a file that is not regular (unsupported by the archive): %s", current)
|
||||
return nil
|
||||
}
|
||||
header, err := tar.FileInfoHeader(info, "")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
//go:build unix
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
pgdb "github.com/Autumn-27/artex/db"
|
||||
)
|
||||
|
||||
// A named pipe or a socket left in the task workspace by a command must not
|
||||
// make the archive unrestorable, nor stop the task from being archived.
|
||||
func TestTaskArchiveSkipsSpecialFiles(t *testing.T) {
|
||||
// A short root: a socket path is limited to about 100 bytes.
|
||||
dataDir, err := os.MkdirTemp("/tmp", "arch")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { os.RemoveAll(dataDir) })
|
||||
taskID := "42"
|
||||
runDir := filepath.Join(dataDir, "tasks", taskID, "main")
|
||||
if err := os.MkdirAll(runDir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
evidence := filepath.Join(runDir, "evidence.txt")
|
||||
if err := os.WriteFile(evidence, []byte("task evidence"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := syscall.Mkfifo(filepath.Join(runDir, "backpipe"), 0o600); err != nil {
|
||||
t.Skipf("mkfifo: %v", err)
|
||||
}
|
||||
ln, err := net.Listen("unix", filepath.Join(runDir, "ctl.sock"))
|
||||
if err != nil {
|
||||
t.Skipf("unix socket: %v", err)
|
||||
}
|
||||
ln.(*net.UnixListener).SetUnlinkOnClose(false)
|
||||
ln.Close()
|
||||
|
||||
stage, err := stageTaskArchiveFiles(dataDir, 1, taskID, 7)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
archivePath := taskArchivePath(dataDir, 1, taskID)
|
||||
snapshot := &pgdb.TaskArchiveSnapshot{FormatVersion: pgdb.TaskArchiveFormatVersion, TaskID: 42, ExplorationID: 7}
|
||||
_, _, checksum, err := writeTaskArchivePackage(archivePath, stage.payload, snapshot)
|
||||
if err != nil {
|
||||
t.Fatalf("the task could not be archived: %v", err)
|
||||
}
|
||||
if err := stage.commit(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
extracted := filepath.Join(dataDir, "restore")
|
||||
if err := extractTaskArchivePackage(archivePath, checksum, extracted); err != nil {
|
||||
t.Fatalf("the archive of the task cannot be restored: %v", err)
|
||||
}
|
||||
installed, err := installTaskArchiveFiles(dataDir, extracted, taskID, 1, ExecPrivilege{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := installed.commit(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, err := os.ReadFile(evidence); err != nil || string(got) != "task evidence" {
|
||||
t.Fatalf("restored %s = %q, %v", evidence, got, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user