Fix goal recovery
This commit is contained in:
parent
3846556035
commit
996f586bc1
1 changed files with 783 additions and 145 deletions
|
|
@ -32,7 +32,7 @@ func (op *operator) save() error {
|
|||
|
||||
func (op *operator) schedule(id string) {
|
||||
w := op.store.watch(id)
|
||||
if w.schedule(time.Now(), op.opts.base, op.opts.cap, op.jitter) {
|
||||
if w.schedule(time.Now(), op.opts.base, op.opts.cap, op.jitter) && w.Goal.Status != "usageLimited" {
|
||||
_, _ = fmt.Fprintf(op.log, "codex-keep: %s retry %d at %s\n", id, w.Failures, w.Due.Format(time.RFC3339Nano))
|
||||
}
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@ func (op *operator) inspect(ctx context.Context, id string) error {
|
|||
if err := op.inputs(w, end); err != nil {
|
||||
return err
|
||||
}
|
||||
if w.Hold != nil && w.Hold.Status == active && g.Goal.Status == blocked {
|
||||
if w.Hold != nil && w.Hold.Status == active && g.Goal.Status.waiting() {
|
||||
w.Hold = nil
|
||||
w.Goal = g.Goal
|
||||
w.Known, w.Armed = true, true
|
||||
|
|
@ -270,11 +270,29 @@ func (op *operator) resume(ctx context.Context, id string) error {
|
|||
if !w.eligible() {
|
||||
return op.save()
|
||||
}
|
||||
w.Due = time.Now().Add(min(op.opts.cap, op.jitter(backoff(op.opts.base, op.opts.cap, w.Failures+1))))
|
||||
if w.Goal.Status == "usageLimited" {
|
||||
revision = w.revision
|
||||
w.Due = time.Now().Add(op.opts.poll)
|
||||
var usage usageResult
|
||||
p := struct {
|
||||
Exclude bool `json:"excludeResetCreditDetails"`
|
||||
}{true}
|
||||
if err := op.conn.call(ctx, "account/rateLimits/read", p, &usage); err != nil {
|
||||
if saveErr := op.save(); saveErr != nil {
|
||||
return saveErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
if w.revision != revision || usage.Allowed == nil || !*usage.Allowed {
|
||||
return op.save()
|
||||
}
|
||||
} else {
|
||||
w.Due = time.Now().Add(min(op.opts.cap, op.jitter(backoff(op.opts.base, op.opts.cap, w.Failures+1))))
|
||||
}
|
||||
if err := op.setGoal(ctx, id, active); err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = fmt.Fprintf(op.log, "codex-keep: %s resumed after API failure\n", id)
|
||||
_, _ = fmt.Fprintf(op.log, "codex-keep: %s resumed after failed turn\n", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +310,7 @@ func (op *operator) setGoal(ctx context.Context, id string, status goalStatus) e
|
|||
w.Pending = false
|
||||
}
|
||||
if err != nil {
|
||||
if status == active && w.revision == revision && w.eligible() {
|
||||
if status == active && w.revision == revision && w.eligible() && w.Goal.Status != "usageLimited" {
|
||||
w.Failures++
|
||||
}
|
||||
} else {
|
||||
|
|
@ -329,7 +347,7 @@ func (op *operator) inputs(w *watch, end int64) error {
|
|||
if w.Goal == nil {
|
||||
return nil
|
||||
}
|
||||
if status == active && (w.Goal.Status == active || w.Goal.Status == blocked) {
|
||||
if status == active && (w.Goal.Status == active || w.Goal.Status.waiting()) {
|
||||
w.Hold = nil
|
||||
w.Known, w.Armed = true, true
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue