diff --git a/internal/store/mergefacts.go b/internal/store/mergefacts.go index cb534f0..ab86241 100644 --- a/internal/store/mergefacts.go +++ b/internal/store/mergefacts.go @@ -33,8 +33,7 @@ func (s *Store) SettleMergeFacts(ctx context.Context, taskID string, g GitFacts) } f := api.MergeFacts{UnmergedCommits: g.UnmergedCommits, UnmergedFiles: g.UnmergedFiles, UnreviewedChanges: g.UnreviewedChanges} - err = tx.QueryRowContext(ctx, `SELECT coalesce(max(n), 0) FROM snapshots WHERE task_id = ? AND trigger NOT IN (?, ?, ?)`, - taskID, string(api.SnapshotTriggerAnswer), string(api.SnapshotTriggerFork), string(api.SnapshotTriggerAskHuman)).Scan(&f.ReviewSnapshot) + err = tx.QueryRowContext(ctx, `SELECT coalesce(max(n), 0) FROM snapshots WHERE task_id = ? AND trigger NOT IN `+cutPointTriggers, taskID).Scan(&f.ReviewSnapshot) if err != nil { return err } diff --git a/internal/store/snapshot.go b/internal/store/snapshot.go index 655548b..945d612 100644 --- a/internal/store/snapshot.go +++ b/internal/store/snapshot.go @@ -8,6 +8,8 @@ import ( "g.fc.run/ai/byre/internal/api" ) +const cutPointTriggers = `('answer', 'fork', 'ask_human')` + const snapshotColumns = `id, task_id, agent_session_id, n, commit_sha, tree_sha, event_seq, trigger, created_at` func (s *Store) CreateSnapshot(ctx context.Context, snap api.Snapshot, projectID string) error { @@ -17,11 +19,9 @@ func (s *Store) CreateSnapshot(ctx context.Context, snap api.Snapshot, projectID if err != nil { return err } - if !CutPoint(snap.Trigger) { - _, err = tx.ExecContext(ctx, `UPDATE tasks SET ready = '' WHERE id = ?`, snap.TaskId) - if err != nil { - return err - } + _, err = tx.ExecContext(ctx, `UPDATE tasks SET ready = '' WHERE id = ? AND ? NOT IN `+cutPointTriggers, snap.TaskId, string(snap.Trigger)) + if err != nil { + return err } return emit(api.Event{ Kind: "snapshot.created", @@ -68,13 +68,8 @@ func (s *Store) LastSnapshot(ctx context.Context, taskID string) (api.Snapshot, return snap, err } -func CutPoint(trigger api.SnapshotTrigger) bool { - return trigger == api.SnapshotTriggerAnswer || trigger == api.SnapshotTriggerFork || trigger == api.SnapshotTriggerAskHuman -} - func (s *Store) LastReviewable(ctx context.Context, taskID string) (api.Snapshot, error) { - snap, err := scanSnapshot(s.db.QueryRowContext(ctx, `SELECT `+snapshotColumns+` FROM snapshots WHERE task_id = ? AND trigger NOT IN (?, ?, ?) ORDER BY n DESC LIMIT 1`, - taskID, string(api.SnapshotTriggerAnswer), string(api.SnapshotTriggerFork), string(api.SnapshotTriggerAskHuman))) + snap, err := scanSnapshot(s.db.QueryRowContext(ctx, `SELECT `+snapshotColumns+` FROM snapshots WHERE task_id = ? AND trigger NOT IN `+cutPointTriggers+` ORDER BY n DESC LIMIT 1`, taskID)) if errors.Is(err, sql.ErrNoRows) { return snap, ErrNotFound } diff --git a/internal/store/store.go b/internal/store/store.go index 6d9c059..441334d 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -772,9 +772,9 @@ func (s *Store) ReadyPromptDue(ctx context.Context, id string) (bool, error) { err := s.db.QueryRowContext(ctx, `SELECT EXISTS ( SELECT 1 FROM events e, tasks t WHERE t.id = ? AND e.task_id = t.id AND e.seq > t.ready_prompt_seq - AND ((e.kind = 'snapshot.created' AND json_extract(e.payload, '$.trigger') NOT IN (?, ?, ?)) + AND ((e.kind = 'snapshot.created' AND json_extract(e.payload, '$.trigger') NOT IN `+cutPointTriggers+`) OR (e.kind = 'user.message' AND e.actor != ? AND e.actor NOT LIKE '% (lead)' AND json_extract(e.payload, '$.bounce') IS NOT 1)) - )`, id, string(api.SnapshotTriggerAnswer), string(api.SnapshotTriggerFork), string(api.SnapshotTriggerAskHuman), agentActor).Scan(&due) + )`, id, agentActor).Scan(&due) return due, err }