Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
go test ./... -count=1 -timeout 180s
go vet ./...
go mod verify
- name: Task revival concurrency regressions
run: go test -race ./server -run '^(TestTerminalTask|TestTimedOutTask|TestRunningTaskAdmission|TestStopTask)' -count=1 -timeout 180s
- name: Go vulnerability gate
run: go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 ./...
- name: Frontend checks and dependency gate
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

本项目的重要变更记录在此文件中,格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。

## [1.0.5] - 2026-11-16

### 任务恢复与超时

- 修复已完成或失败的任务追加目标、意图后仍沿用过期截止时间,导致 Worker 执行预算被压缩至 1 秒的问题。
- `done`、`failed` 和 `timeout` 任务恢复时统一清理上一轮时钟,实际开始执行时获得完整的新预算;等待并发队列期间不计入新预算。
- 任务状态与时钟在同一次数据库写入中更新;恢复前等待上一轮超时协调器退出,避免旧收尾流程影响新一轮运行。
- 普通暂停、继续和运行中追加工作保持当前轮次的截止时间。
- 增加任务恢复、排队、写入失败和协调器退出的回归测试,并在 CI 中运行相关并发检测。

### 安全更新

- 构建工具链升级至 Go 1.27.4,修复 `net/http` 的 [GO-2026-6859](https://pkg.go.dev/vuln/GO-2026-6859);同步 Docker 源码构建镜像与安装要求。

关联 PR:[#1](https://github.com/jaykwok/ARTEX/pull/1)(@qcnhy)。

[完整变更](https://github.com/jaykwok/ARTEX/compare/v1.0.4...v1.0.5)

## [1.0.4] - 2026-11-10

### 安全更新
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ COPY web/ ./
RUN npm run build:static

# ── 源码编译:内嵌前端的 Go 单二进制 ────────────────
FROM golang:1.27.3-bookworm AS gobuild
FROM golang:1.27.4-bookworm AS gobuild
# .dockerignore 排除了 .git,镜像内拿不到 git describe,版本号由构建参数传入。
# 缺省 dev:页面一键更新会对 dev 构建禁用,Docker 部署本就应通过重建镜像升级。
ARG ARTEX_VERSION=dev
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ flowchart TB
- `ARTEX_DB_PATH` / `database.path` 必须指向文件管理器目录之外。禁止把 `workspace/` 本身替换为符号链接或目录联接。文件管理器的链接无法逃逸工作区;覆盖文件采用原子替换,不截断硬链接指向的内部数据。
- 修改密码或管理员重置密码会撤销所有既有登录会话,当前浏览器也必须重新登录;本次升级会使旧签名方式的会话失效一次。
- 默认同源部署;浏览器跨域 API 支持 Bearer `Authorization` 与 `PATCH` 预检,不提供跨域 cookie credentials。
- 构建要求 Go 1.27.3 或更高安全补丁版本。`install.sh`、`update.sh` 与 `build.sh` 共用版本解析;带未提交改动的源码仍显示 dirty 版本,正式构建应使用干净的版本标签或显式 `ARTEX_BUILD_VERSION`。
- 构建要求 Go 1.27.4 或更高安全补丁版本。`install.sh`、`update.sh` 与 `build.sh` 共用版本解析;带未提交改动的源码仍显示 dirty 版本,正式构建应使用干净的版本标签或显式 `ARTEX_BUILD_VERSION`。
- 开发前端固定为 `http://127.0.0.1:5173`,默认仅监听本机。正式部署继续使用 Go 内嵌静态页面,Node 服务仅用于开发或单独的前端托管。
- 已删除缺少镜像和 fixture 的 `docker-compose.bench.yml`;当前仓库不提供该旧基准入口。
- PR、main push 及发布前执行 Go 测试/vet、前端类型检查/测试/lint、依赖扫描和全新 SQLite 启动检查。`npm run lint` 使用逐文件逐规则计数基线,禁止新增错误及保留已解决的基线项;`npm run lint:strict` 可查看全部既有债务,修改基线须审阅 `web/lint-baseline.json` 的差异。
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ while [ "$#" -gt 0 ]; do
esac
done

command -v go >/dev/null 2>&1 || die "未检测到 Go(项目需要 Go 1.27.3 或更高版本)"
command -v go >/dev/null 2>&1 || die "未检测到 Go(项目需要 Go 1.27.4 或更高版本)"

ARTEX_GOSUMDB="${ARTEX_GOSUMDB:-sum.golang.org}"
. ./scripts/version.sh
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Autumn-27/artex

go 1.27.3
go 1.27.4

require (
github.com/Autumn-27/norma v0.4.3
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ install_local(){
fi

# go 环境检查
command -v go >/dev/null 2>&1 || die "未检测到 Go,请先安装 Go(>=1.27.3):https://go.dev/dl/"
command -v go >/dev/null 2>&1 || die "未检测到 Go,请先安装 Go(>=1.27.4):https://go.dev/dl/"
ok "Go: $(go version)"

# 内嵌前端需要 node 出静态产物
Expand Down
20 changes: 14 additions & 6 deletions server/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ type Engine struct {
plannerRound sync.Map // taskID -> int, planner round counter (for UI round separators)

// 任务级超时(见 docs/任务级超时与收尾设计.md):
settling sync.Map // taskID -> bool, 任务已进入收尾时序(停止派/领新意图)
deadline sync.Map // taskID -> int64 unix, 绝对截止时刻(首次运行时盖章;0/缺省=不限)
stamped sync.Map // taskID -> bool, first_run_at 是否已盖章(本进程内只盖一次)
inflight sync.Map // taskID -> *int64, 在跑的 planner.Plan + worker.Execute 计数(用于 drain)
coordStarted sync.Map // taskID -> bool, deadline 协调器是否已启动(Run/reload 去重)
clockMu sync.Mutex // serializes clock caches, first-run writes and coordinator registration
settling sync.Map // taskID -> bool, 任务已进入收尾时序(停止派/领新意图)
deadline sync.Map // taskID -> int64 unix, 绝对截止时刻(首次运行时盖章;0/缺省=不限)
stamped sync.Map // taskID -> bool, first_run_at 是否已盖章(每轮运行只盖一次)
inflight sync.Map // taskID -> *int64, 在跑的 planner.Plan + worker.Execute 计数(用于 drain)
coordStarted sync.Map // taskID -> *deadlineCoordinatorRun, current run's timer (Run/reload deduplication)

// resolve returns a task's dedicated planner/worker (wired by the server as the
// authoritative task-router). nil,nil means this task is deliberately unavailable
Expand All @@ -149,6 +150,11 @@ type taskRuntime struct {
wg sync.WaitGroup
}

type deadlineCoordinatorRun struct {
cancel context.CancelFunc
done chan struct{}
}

type workExecution struct {
cancel context.CancelCauseFunc
done chan error
Expand Down Expand Up @@ -271,10 +277,12 @@ func (e *Engine) StopTask(taskID string) {
e.dropCnt.Delete(taskID)
e.plannerRound.Delete(taskID)
e.settling.Delete(taskID)
e.clockMu.Lock()
e.deadline.Delete(taskID)
e.stamped.Delete(taskID)
e.inflight.Delete(taskID)
e.coordStarted.Delete(taskID)
e.clockMu.Unlock()
e.inflight.Delete(taskID)
e.deleteMu.Lock()
e.deleting.Delete(taskID)
e.deleteMu.Unlock()
Expand Down
59 changes: 48 additions & 11 deletions server/engine_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (e *Engine) inflightCount(taskID string) int64 {
// map (stamped this session); falls back to the DB-loaded value (restart), seeding
// the map. 0 = no timeout / not yet stamped.
func (e *Engine) taskDeadline(t *Task) int64 {
e.clockMu.Lock()
defer e.clockMu.Unlock()
if v, ok := e.deadline.Load(t.ID); ok {
return v.(int64)
}
Expand All @@ -79,12 +81,13 @@ func (e *Engine) taskDeadline(t *Task) int64 {
return 0
}

// resetTimeoutRevival clears only the per-run timeout state after SQLite has
// atomically committed timeout -> running and reset first_run_at/deadline_at. The
// resetTerminalRevival clears per-run timeout state after SQLite has atomically
// committed a terminal -> running transition and reset first_run_at/deadline_at. The
// configured TimeoutSeconds remains on Task, so the next real Planner/Worker run
// stamps a fresh full budget. coordStarted is reset because the coordinator that
// produced the timeout has already completed (or is in its final return path).
func (e *Engine) resetTimeoutRevival(taskID string) {
// stamps a fresh full budget. Admission has already stopped the old coordinator.
func (e *Engine) resetTerminalRevival(taskID string) {
e.clockMu.Lock()
defer e.clockMu.Unlock()
e.settling.Delete(taskID)
e.deadline.Delete(taskID)
e.stamped.Delete(taskID)
Expand All @@ -97,6 +100,12 @@ func (e *Engine) stampFirstRun(t *Task) {
if t.TimeoutSeconds <= 0 {
return
}
e.clockMu.Lock()
defer e.clockMu.Unlock()
lifecycle := t.lifecycleSnapshot()
if e.IsPaused(t.ID) || lifecycle.Paused || lifecycle.Queued || isTerminalStatus(lifecycle.Status) {
return // a cancelled run must not start the next budget during admission
}
if _, loaded := e.stamped.LoadOrStore(t.ID, true); loaded {
return
}
Expand Down Expand Up @@ -133,17 +142,39 @@ func (e *Engine) startDeadlineCoordinator(ctx context.Context, t *Task) {
return
}
e.deleteMu.RLock()
if e.IsDeleting(t.ID) {
e.deleteMu.RUnlock()
defer e.deleteMu.RUnlock()
e.clockMu.Lock()
defer e.clockMu.Unlock()
if e.IsDeleting(t.ID) || isTerminalStatus(t.lifecycleSnapshot().Status) {
return
}
if _, loaded := e.coordStarted.LoadOrStore(t.ID, true); loaded {
e.deleteMu.RUnlock()
if _, loaded := e.coordStarted.Load(t.ID); loaded {
return
}
rt := e.registerTaskRoutines(ctx, t.ID, 1)
e.deleteMu.RUnlock()
runTaskRoutine(rt, func(loopCtx context.Context) { e.deadlineCoordinator(loopCtx, t) })
loopCtx, cancel := context.WithCancel(rt.ctx)
run := &deadlineCoordinatorRun{cancel: cancel, done: make(chan struct{})}
e.coordStarted.Store(t.ID, run)
runTaskRoutine(rt, func(context.Context) {
defer close(run.done)
defer cancel()
e.deadlineCoordinator(loopCtx, t)
})
}

// stopDeadlineCoordinator waits for the previous timer and final planner round
// before admission changes a terminal task back to running. Keep the registration
// until the lifecycle commit succeeds, so repeated starts cannot overlap it.
func (e *Engine) stopDeadlineCoordinator(taskID string) {
e.clockMu.Lock()
v, ok := e.coordStarted.Load(taskID)
if ok {
v.(*deadlineCoordinatorRun).cancel()
}
e.clockMu.Unlock()
if ok {
<-v.(*deadlineCoordinatorRun).done
}
}

// deadlineCoordinator waits until the task's absolute deadline, then runs the settle
Expand Down Expand Up @@ -182,6 +213,9 @@ func (e *Engine) deadlineCoordinator(ctx context.Context, t *Task) {

// settleTask runs the ordered settle sequence once (§4 steps ①–⑥).
func (e *Engine) settleTask(ctx context.Context, t *Task) {
if ctx.Err() != nil {
return
}
if !e.markSettling(t.ID) {
return
}
Expand All @@ -204,6 +238,9 @@ func (e *Engine) settleTask(ctx context.Context, t *Task) {

// ⑤ 终局一轮 planner(任务超时词,最后目标判定,不产新意图)。
met := e.runFinalPlannerRound(ctx, t)
if ctx.Err() != nil {
return
}
if !e.beginTaskOperation(t.ID) {
return
}
Expand Down
11 changes: 7 additions & 4 deletions server/goals.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,21 @@ func (s *Server) admitTaskWhen(t *Task, mode string, requirePaused bool) (queued
status := lifecycle.Status
if wasTerminal {
status = "running"
// Finish the old coordinator while the task is still terminal. Its timer
// or final planner round must not settle the next run after admission.
s.engine.stopDeadlineCoordinator(t.ID)
}
if err := s.m.ApplyTaskAdmission(t.ID, lifecycle.Status, status, shouldQueue, mode, wasQueued); err != nil {
if !engineWasPaused && !wasPaused && !wasQueued {
s.engine.Resume(t)
}
return false, err
}
if lifecycle.Status == "timeout" && status == "running" {
// ApplyTaskAdmission reset this timed-out run's persisted clock. Clear the
if wasTerminal {
// ApplyTaskAdmission reset the previous run's persisted clock. Clear the
// matching Engine gates before either parking it in FIFO or starting work;
// otherwise the old settling flag would make every worker skip forever.
s.engine.resetTimeoutRevival(t.ID)
s.engine.resetTerminalRevival(t.ID)
}
if shouldQueue {
if !wasQueued {
Expand Down Expand Up @@ -245,7 +248,7 @@ func (s *Server) startAdmittedTask(t *Task, mode string) {
s.engine.Run(s.ctx, t)
s.engine.Resume(t)
// Run returns early for an already-started task. Explicitly ensure a timeout
// coordinator exists after resume; resetTimeoutRevival cleared the completed
// coordinator exists after resume; resetTerminalRevival cleared the completed
// coordinator's marker and the next real call will stamp a fresh deadline.
s.engine.startDeadlineCoordinator(s.ctx, t)
}
Expand Down
6 changes: 4 additions & 2 deletions server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ func (m *Manager) SetTaskPaused(id string, paused bool) error {
// concurrency scheduler. Keeping status, paused and queue metadata in one UPDATE
// prevents a failed resume from leaving a task half-revived (for example running
// but still user-paused, or dequeued without an Engine start).
// Leaving a terminal state also clears the previous run's clock in this UPDATE;
// the next real Planner/Worker call starts a new budget after any FIFO wait.
//
// preservePosition applies only when the row is already queued. A repeated
// admission keeps its FIFO timestamp; a task that was explicitly paused and is
Expand Down Expand Up @@ -1190,11 +1192,11 @@ func (m *Manager) ApplyTaskAdmission(id, expectedStatus, status string, queued b
ELSE 'resume'
END,
first_run_at=CASE
WHEN $6='timeout' AND $2 NOT IN ('done','failed','timeout') THEN NULL
WHEN $6 IN ('done','failed','timeout') AND $2 NOT IN ('done','failed','timeout') THEN NULL
ELSE first_run_at
END,
deadline_at=CASE
WHEN $6='timeout' AND $2 NOT IN ('done','failed','timeout') THEN NULL
WHEN $6 IN ('done','failed','timeout') AND $2 NOT IN ('done','failed','timeout') THEN NULL
ELSE deadline_at
END
WHERE id=$1 AND deleted_at IS NULL AND status=$6
Expand Down
4 changes: 3 additions & 1 deletion server/task_admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ func TestTimedOutTaskRevivalResetsClockAndSettlingAcrossFIFO(t *testing.T) {
s.engine.settling.Store(task.ID, true)
s.engine.deadline.Store(task.ID, oldClock.DeadlineAt)
s.engine.stamped.Store(task.ID, true)
s.engine.coordStarted.Store(task.ID, true)
coordinator := &deadlineCoordinatorRun{cancel: func() {}, done: make(chan struct{})}
close(coordinator.done)
s.engine.coordStarted.Store(task.ID, coordinator)

queued, err := s.admitTask(task, "resume")
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion server/task_delete_barrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ func TestStopTaskCancelsRuntimeAndClearsLifecycleState(t *testing.T) {
e.lastAct.Store(taskID, int64(1))
e.paused.Store(taskID, true)
e.plannerRound.Store(taskID, 3)
e.coordStarted.Store(taskID, true)
coordinator := &deadlineCoordinatorRun{cancel: func() {}, done: make(chan struct{})}
close(coordinator.done)
e.coordStarted.Store(taskID, coordinator)
e.deleteMu.RUnlock()

done := make(chan struct{})
Expand Down
Loading
Loading