返回 DeepSeek-Reasonix
tab_startup_failure.go
根目录 / desktop / tab_startup_failure.go
1 package main
2
3 import (
4 "errors"
5
6 "reasonix/internal/agent"
7 )
8
9 type startupFailureRestorePolicy uint8
10
11 const (
12 keepStartupRestore startupFailureRestorePolicy = iota
13 suppressStartupRestore
14 )
15
16 type tabsSaveRequest struct {
17 dir string
18 entries []desktopTabEntry
19 activeID string
20 version uint64
21 }
22
23 // markTabStartupFailureLocked owns the failed-startup state transition. A
24 // terminal recovery failure also returns a tab snapshot to write after unlock.
25 func (a *App) markTabStartupFailureLocked(tab *WorkspaceTab, err error, policy startupFailureRestorePolicy) (bool, *tabsSaveRequest) {
26 leaseHeld := setTabStartupError(tab, err)
27 tab.Ready = false
28 phase := sessionRuntimeFailed
29 if leaseHeld {
30 phase = sessionRuntimeLeaseBlocked
31 }
32 a.setSessionRuntimePhaseLocked(tab, phase, err)
33
34 rt := a.runtimeForTabLocked(tab)
35 suppress := !leaseHeld && policy == suppressStartupRestore
36 if rt != nil {
37 rt.suppressStartupRestore = suppress
38 }
39 if !suppress {
40 return leaseHeld, nil
41 }
42 dir, entries, activeID, version := a.saveTabsCollectLocked()
43 return leaseHeld, &tabsSaveRequest{dir: dir, entries: entries, activeID: activeID, version: version}
44 }
45
46 func (a *App) writeTabsSaveRequest(req *tabsSaveRequest) {
47 if req != nil {
48 a.saveTabsWrite(req.dir, req.entries, req.activeID, req.version)
49 }
50 }
51
52 func (a *App) suppressTabStartupRestoreLocked(tab *WorkspaceTab) bool {
53 rt := a.runtimeForTabLocked(tab)
54 return rt != nil && rt.Phase == sessionRuntimeFailed && rt.suppressStartupRestore
55 }
56
57 func persistedActiveTabID(entries []desktopTabEntry, activeID string) string {
58 for _, entry := range entries {
59 if entry.ID == activeID {
60 return activeID
61 }
62 }
63 if len(entries) > 0 {
64 return entries[0].ID
65 }
66 return ""
67 }
68
69 func failedStartupSnapshotError(err error) bool {
70 return errors.Is(err, agent.ErrSessionWriteAuthorityMissing) ||
71 errors.Is(err, agent.ErrSessionWriteAuthorityStale)
72 }
73
73 lines GO