getWorkspaceConnLocked returns the cached connection when it still matches the current workspace. When the workspace changed, it clears the stale cached state and returns the release func for the caller to run after unlocking.
()
| 953 | // cached state and returns the release func for the caller to run after |
| 954 | // unlocking. |
| 955 | func (c *turnWorkspaceContext) getWorkspaceConnLocked() (workspacesdk.AgentConn, func()) { |
| 956 | if c.conn == nil { |
| 957 | return nil, nil |
| 958 | } |
| 959 | |
| 960 | chatSnapshot := c.currentChatSnapshot() |
| 961 | if nullUUIDEqual(c.cachedWorkspaceID, chatSnapshot.WorkspaceID) { |
| 962 | return c.conn, nil |
| 963 | } |
| 964 | |
| 965 | agentRelease := c.releaseConn |
| 966 | c.agent = database.WorkspaceAgent{} |
| 967 | c.agentLoaded = false |
| 968 | c.conn = nil |
| 969 | c.releaseConn = nil |
| 970 | c.cachedWorkspaceID = uuid.NullUUID{} |
| 971 | return nil, agentRelease |
| 972 | } |
| 973 | |
| 974 | // isAgentUnreachable reports whether the given agent row's |
| 975 | // status is disconnected or timed out. It uses timestamp |
no test coverage detected