Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project are documented in this file. The format is b

### Fixed

- **Switching a task's target gate off releases its waiting approvals**: the waiter observes the live flag on its 2 s poll, closes open requests so a late click can no longer pin the target, and lets a plain target-gated call continue as it would on an ungated task; a call whose rule or judge approval was merged into the request is told to retry, since that approval was not given (#804).
- **An `exact_ip` task allow rule grants sandbox egress**: the egress allowlist read task allow rules of kind `ip`, which the rule tables never store, so an `exact_ip` allow rule granted nothing. A task scoped to one private address (`10.0.0.5`) could not reach it from the sandbox, directly or through a name resolving only to it. `exact_ip` allow rules now join the allowed CIDRs as a host prefix, like `cidr` allow rules.
- **`GET /api/tasks/{id}/scope` reports scope approval**: the query behind it did not select `approved_by_operator` or `expanded`, so every row came back with `approved_by_operator: false` and `expanded: false`, including operator-approved rows that grant sandbox egress. The rows now carry both columns as stored, for the task's own scope and for its source tasks' scope.
- **The OpenAI Responses format no longer defaults to `gpt-5`**: OpenAI shuts `gpt-5` down on 2026-12-11 and lists `gpt-6.2-sol` as its replacement, so `ARTEX_LLM_PROVIDER=openai-responses` without `ARTEX_LLM_MODEL` (or a profile saved through the API without a model) would start failing then. The default is now `gpt-6.2-sol`; a model set in the profile or in `ARTEX_LLM_MODEL` is kept as is. A gateway set with `ARTEX_LLM_BASE_URL` that does not serve `gpt-6.2-sol` needs `ARTEX_LLM_MODEL` set explicitly.
Expand Down
7 changes: 4 additions & 3 deletions agent/hooks_reach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ func newHookReachFixture(t *testing.T) hookReachFixture {
t.Helper()
d := testDB(t)
t.Cleanup(func() { _ = d.Close() })
expID, err := d.CreateExploration("hook reach probe", "prove tool calls reach the hooks")
on := true
task, err := d.CreateTaskWithOptions("hook reach probe", "prove tool calls reach the hooks", db.TaskCreateOptions{TargetGate: &on})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _, _ = d.Exec(`DELETE FROM explorations WHERE id=$1`, expID) })
f := hookReachFixture{expID: expID, taskID: fmt.Sprint(expID), ts: d.Exploration(expID), workDir: t.TempDir()}
t.Cleanup(func() { _ = d.DeleteTask(task.ID) })
f := hookReachFixture{expID: task.ExplorationID, taskID: fmt.Sprint(task.ID), ts: d.Exploration(task.ExplorationID), workDir: t.TempDir()}
f.marker = filepath.Join(f.workDir, "tool-ran")
input, _ := json.Marshal(map[string]string{"command": "touch " + f.marker})
f.bash = string(input)
Expand Down
129 changes: 121 additions & 8 deletions db/target_pins.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,84 @@ WHERE COALESCE(task_id,'')=$1 AND status='pending' AND target_key IS NOT NULL`,
return err
}

// TargetGateDisabledReason is the audit reason used when disabling a task's
// target gate closes or refuses an approval request.
const TargetGateDisabledReason = "the target gate was switched off; nothing was pinned"

// ErrTargetGateDisabled reports an approval that was system-refused because
// the task's target gate was disabled before the decision committed.
var ErrTargetGateDisabled = errors.New("the target gate was disabled before the target approval was decided")

// systemDenyTargetRequest settles one locked target request without attributing
// the decision to a human. Its audit shape is shared by gate-off bulk closes and
// approvals refused after the task gate was disabled.
func systemDenyTargetRequest(tx *sql.Tx, id int64, reason string) error {
_, err := tx.Exec(`UPDATE intercept_pending SET status='denied', decided_at=NOW(), decided_by='system',
audit=CASE WHEN audit IS NULL THEN NULL ELSE (audit - 'approver' - 'approver_addr') ||
jsonb_build_object(
'effective_action', 'deny',
'decision_reason', $2::text,
'execution_status', 'not_executed',
'targets', COALESCE((
SELECT jsonb_agg(value || '{"outcome":"denied"}'::jsonb)
FROM jsonb_array_elements(COALESCE(audit->'targets', '[]'::jsonb)) AS target(value)
), '[]'::jsonb)
) END
WHERE id=$1 AND status='pending' AND target_key IS NOT NULL`, id, reason)
return err
}

// CloseTargetRequests settles every open target request in scope on behalf of
// the system and returns the ids that were closed. Classic asks and requests in
// other scopes are left untouched.
func (d *DB) CloseTargetRequests(scope TargetScopeRef, reason string) ([]int64, error) {
if err := scope.check(); err != nil {
return nil, err
}
taskID, _ := scope.pendingScope()
taskKey := ""
if taskID != nil {
taskKey = *taskID
}
tx, err := d.Begin()
if err != nil {
return nil, err
}
defer tx.Rollback()
rows, err := tx.Query(`SELECT id FROM intercept_pending
WHERE COALESCE(task_id,'')=$1 AND COALESCE(conversation_id,0)=$2
AND status='pending' AND target_key IS NOT NULL
ORDER BY id FOR UPDATE`, taskKey, scope.ConversationID)
if err != nil {
return nil, err
}
var ids []int64
for rows.Next() {
var id int64
if err := rows.Scan(&id); err != nil {
rows.Close()
return nil, err
}
ids = append(ids, id)
}
if err := rows.Err(); err != nil {
rows.Close()
return nil, err
}
if err := rows.Close(); err != nil {
return nil, err
}
for _, id := range ids {
if err := systemDenyTargetRequest(tx, id, reason); err != nil {
return nil, err
}
}
if err := tx.Commit(); err != nil {
return nil, err
}
return ids, nil
}

// TargetRequest is a new target approval request: the intercept_pending row a
// gated call asks for when one of its targets has no pin that covers it.
type TargetRequest struct {
Expand Down Expand Up @@ -256,20 +334,46 @@ func (d *DB) TargetRequestKey(id int64) (string, error) {
return key.String, err
}

// ResolveTargetRequest settles an open target request with a human decision, in
// one transaction. Allowed pins the addresses the request displayed: the active
// pin of the same key, if any, becomes superseded and a new version holds its
// addresses plus the displayed ones (addresses leave only by revocation).
// Denied pins nothing. approver and remoteAddr go to the pin and to the row's
// audit; decided_by on the row stays the actor class, human. ok is false when
// the row is not an open target request. If the pin cannot be written the row
// stays pending.
// ResolveTargetRequest settles an open target request in one transaction.
// A task-scoped approval first locks the task and is refused with a system
// denial when the task is gone or its target gate is off. Otherwise, allowed
// pins the displayed addresses: the active pin of the same key, if any, becomes
// superseded and a new version holds its addresses plus the displayed ones
// (addresses leave only by revocation). Denied pins nothing. Human decisions
// record approver and remoteAddr in the pin and row audit; decided_by remains
// the actor class. ok is false when the row is not open. A system-refused
// approval returns ErrTargetGateDisabled after committing the denial. If the
// pin cannot be written the row stays pending.
func (d *DB) ResolveTargetRequest(id int64, allowed bool, approver, remoteAddr string) (pin *TargetPin, ok bool, err error) {
tx, err := d.Begin()
if err != nil {
return nil, false, err
}
defer tx.Rollback()
var initialTaskID sql.NullString
err = tx.QueryRow(`SELECT task_id FROM intercept_pending
WHERE id=$1 AND status='pending' AND target_key IS NOT NULL`, id).Scan(&initialTaskID)
if errors.Is(err, sql.ErrNoRows) {
return nil, false, nil
}
if err != nil {
return nil, false, err
}
taskGateEnabled := true
if allowed && initialTaskID.Valid {
taskIDValue, parseErr := strconv.ParseInt(initialTaskID.String, 10, 64)
if parseErr != nil {
return nil, false, fmt.Errorf("target request %d: task id %q: %w", id, initialTaskID.String, parseErr)
}
// Lock task before pending, matching task deletion's lock order.
lockErr := tx.QueryRow(`SELECT target_gate FROM tasks
WHERE id=$1 AND deleted_at IS NULL FOR UPDATE`, taskIDValue).Scan(&taskGateEnabled)
if errors.Is(lockErr, sql.ErrNoRows) {
taskGateEnabled = false
} else if lockErr != nil {
return nil, false, lockErr
}
}
var taskID sql.NullString
var convID sql.NullInt64
var raw []byte
Expand All @@ -281,6 +385,15 @@ WHERE id=$1 AND status='pending' AND target_key IS NOT NULL FOR UPDATE`, id).Sca
if err != nil {
return nil, false, err
}
if allowed && taskID.Valid && !taskGateEnabled {
if err := systemDenyTargetRequest(tx, id, TargetGateDisabledReason); err != nil {
return nil, false, err
}
if err := tx.Commit(); err != nil {
return nil, false, err
}
return nil, false, ErrTargetGateDisabled
}
var audit InterceptAudit
if len(raw) > 0 {
if err := json.Unmarshal(raw, &audit); err != nil {
Expand Down
Loading
Loading