chat: deliver attachments and cancel runs immediately
Carry browser files as base64 prompt attachments, write them to private temporary files and pass file:// references to OpenCode, and map the user turn's top-level files back into history. Replay a running step on subscribe, forward only a caller-supplied msg_ id, and persist cancel on the run and live step before interrupting the runner.
This commit is contained in:
+20
-11
@@ -674,18 +674,17 @@ func (r *runner) cancel(id int64) error {
|
||||
r.mu.Lock()
|
||||
entry, ok := r.active[id]
|
||||
r.mu.Unlock()
|
||||
if ok {
|
||||
entry.cancel()
|
||||
return nil
|
||||
}
|
||||
// A run that is waiting on a person has no live goroutine, so cancel it at
|
||||
// the persistence layer instead. This keeps cancel working across a restart.
|
||||
// The single follow-up read seeds the terminal delta; cancel is a cold
|
||||
// operator action, not a per-transition hot path.
|
||||
if err := r.store.CancelWaiting(r.ctx, id); err != nil {
|
||||
// Persist the cancellation before asking the runner to stop. A stage that is
|
||||
// stuck in a context-unaware provider call must not leave the run "running":
|
||||
// the operator's Stop is a terminal decision, and the live row/step show it
|
||||
// immediately. FinishStep/FinishRun only update active rows, so the late
|
||||
// stage return cannot undo this.
|
||||
if err := r.store.Cancel(r.ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
// A canceled run is terminal: nothing more can notify for it.
|
||||
if ok {
|
||||
entry.cancel()
|
||||
}
|
||||
r.forgetAttention(id)
|
||||
if r.events != nil {
|
||||
if detail, err := r.store.GetRun(r.ctx, id); err == nil && detail != nil {
|
||||
@@ -1265,7 +1264,17 @@ func (r *runner) finishRunState(id int64, name, workspace, status, outcome, diag
|
||||
c, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := r.store.FinishRun(c, id, status, outcome, diagnostic, input); err != nil {
|
||||
log.Printf("finish run %d: %v", id, err)
|
||||
// Cancel wins over a late stage result: the store already marked the run
|
||||
// canceled and FinishRun only updates queued/running rows. Read the
|
||||
// actual state so this turn emits and notifies canceled, never a failure
|
||||
// caused by the canceled step's persistence guard.
|
||||
if detail, getErr := r.store.GetRun(c, id); getErr == nil && detail != nil && detail.Status == protocol.RunStatusCanceled {
|
||||
status = protocol.RunStatusCanceled
|
||||
outcome = detail.Outcome
|
||||
diagnostic = detail.Diagnostic
|
||||
} else {
|
||||
log.Printf("finish run %d: %v", id, err)
|
||||
}
|
||||
}
|
||||
// Push the terminal delta before the attention notification, so a slow ntfy
|
||||
// never delays the live update the app folds.
|
||||
|
||||
Reference in New Issue
Block a user