Repository: truera/trulens
Issue: [BUG] `groundedness_measure_with_cot_reasons` doesn't call `evaluate_hypothesis` / `ThreadPoolExecutor.submit` not working
Root cause: Resource Mishandling

**Bug Description**

I found that in some cases `executor.submit` is called once (as expected, since I have 1 item in `hypotheses`) but the function `evaluate_hypothesis` is never actually reached. I identified this by debugging and stepping through the code and using various breakpoints. 

https://github.com/truera/trulens/blob/cc7588e0b620821077ea7278697da72a90a4f0e7/src/feedback/trulens/feedback/llm_provider.py#L1924-L1931

If I replace the above code and directly invoke `evaluate_hypothesis` (instead of using threads), it works just as expected:

```python
        for i, hypothesis in enumerate(hypotheses):
            results.append(evaluate_hypothesis(i, hypotheses[i]))
```

Not sure, but might be related to #1649 ?

**To Reproduce**

This is my code: https://gist.github.com/fhamborg/ac43e40be9b846dd59fd947332e7fa8e

**Expected behavior**
`evaluate_hypothesis` should actually be executed when invoked through `ThreadPoolExecutor`.

**Relevant Logs/Tracebacks**
 
```
/home/felix/miniforge3/envs/llmeval/bin/python /home/felix/PycharmProjects/llmeval/mytrulens/trurag.py 
decorating <function RAG.retrieve at 0x78998521a340>
decorating <function RAG.generate_answer at 0x78998521a8e0>
decorating <function RAG.query at 0x78998521a980>
adding method <class '__main__.RAG'> retrieve __main__
adding method <class '__main__.RAG'> generate_answer __main__
adding method <class '__main__.RAG'> query __main__
🦑 Initialized with db url sqlite:///default.sqlite .
🛑 Secret keys may be written to the database. See the `database_redact_keys` option of `TruSession` to prevent this.
Updating app_name and app_version in apps table: 0it [00:00, ?it/s]
Updating app_id in records table: 0it [00:00, ?it/s]
Updating app_json in apps table: 0it [00:00, ?it/s]
✅ In Groundedness, input source will be set to __record__.app.retrieve.rets.collect() .
✅ In Groundedness, input statement will be set to __record__.main_output or `Select.RecordOutput` .
✅ In Answer Relevance, input prompt will be set to __record__.main_input or `Select.RecordInput` .
✅ In Answer Relevance, input response will be set to __record__.main_output or `Select.RecordOutput` .
✅ In Context Relevance, input question will be set to __record__.main_input or `Select.RecordInput` .
✅ In Context Relevance, input context will be set to __record__.app.retrieve.rets[:] .
instrumenting <class '__main__.RAG'> for base <class '__main__.RAG'>
	instrumenting retrieve
	instrumenting generate_answer
	instrumenting query
skipping base <class 'object'> because of class
2025-01-29 13:29:13.303 | DEBUG    | __main__:load_documents:90 - Split 5 docs into 5 chunks and added to vector store.
calling <function RAG.query at 0x78998521a980> with (<__main__.RAG object at 0x78992f956b40>, 'What wave of coffee culture is Starbucks seen to represent in the United States?')
/home/felix/miniforge3/envs/llmeval/lib/python3.12/site-packages/pydantic/_internal/_config.py:345: UserWarning:

Valid config keys have changed in V2:
* 'fields' has been removed

calling <function RAG.retrieve at 0x78998521a340> with (<__main__.RAG object at 0x78992f956b40>, 'What wave of coffee culture is Starbucks seen to represent in the United States?')
calling <function RAG.generate_answer at 0x78998521a8e0> with (<__main__.RAG object at 0x78992f956b40>, 'What wave of coffee culture is Starbucks seen to represent in the United States?', ["Starbucks Corporation is an American multinational chain of coffeehouses and roastery reserves headquartered in Seattle, Washington.\nAs the world's largest coffeehouse chain, Starbucks is seen to be the main representation of the United States' second wave of coffee culture.", "Seattle, a city on Puget Sound in the Pacific Northwest, is surrounded by water, mountains and evergreen forests, and contains thousands of acres of parkland.\nIt's home to a large tech industry, with Microsoft and Amazon headquartered in its metropolitan area.\nThe futuristic Space Needle, a legacy of the 1962 World's Fair, is its most iconic landmark.", 'The University of Washington, founded in 1861 in Seattle, is a public research university\nwith over 45,000 students across three campuses in Seattle, Tacoma, and Bothell.\nAs the flagship institution of the six public universities in Washington state,\nUW encompasses over 500 buildings and 20 million square feet of space,\nincluding one of the largest library systems in the world.', "Washington State University, commonly known as WSU, founded in 1890, is a public research university in Pullman, Washington.\nWith multiple campuses across the state, it is the state's second largest institution of higher education.\nWSU is known for its programs in veterinary medicine, agriculture, engineering, architecture, and pharmacy."])
Starting dashboard ...


  You can now view your Streamlit app in your browser.



Dashboard started at http://localhost:60243 .
  Local URL: http://localhost:60243
  ...


🦑 Initialized with db url sqlite:///default.sqlite .

🛑 Secret keys may be written to the database. See the `database_redact_keys` option of `TruSession` to prevent this.

```

**Environment:**

- OS: Linux Mint
- Python Version: 3.12.8
- TruLens version: 1.3.3



Hi folks, our latest fix (https://github.com/truera/trulens/pull/2059) should improve performance and mitigate issues with `groundedness` not working. I am going to close this issue for now, but please feel free to open a new issue if you identify any additional problems or ongoing issues here!