You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove the function-local os import that broke environment-variable lookup in Stage 4.
Restore Semantic Scholar and OpenAlex API key resolution from configuration and environment variables.
Add regression coverage for key precedence, search configuration, Web Search augmentation, orchestrator execution, and fallback behavior.
Root Cause
A function-local import os caused Python to treat os as a local variable throughout _execute_literature_collect.
Stage 4 accessed os.environ before reaching that import, raising UnboundLocalError. The existing broad exception handler then caught the error and silently skipped the real literature APIs.
This regression was introduced by my changes in #299. I’m sorry I missed the interaction with the existing function-local import during testing. Thank you for reporting it in #309. This PR fixes the issue and adds orchestration-level regression coverage to prevent the same silent fallback from recurring.
Validation
Stage 4 regression tests: 8 passed
Configuration and literature tests: 78 passed
Executor tests: 207 passed
Full suite: 2869 passed, 57 skipped
Real literature retrieval:
18 real candidates
12 OpenAlex and 6 arXiv results
0 placeholders
18 BibTeX entries
Semantic Scholar rate limiting was handled without breaking the remaining providers
Two pre-existing Windows shell-related tests remain environment-specific and are unrelated to this change.
Merged. This one fixed the highest-impact bug in the queue, and the test coverage is why it landed ahead of the two other PRs carrying the same one-line deletion (#315, #307).
Confirming the severity for the record, since the PR title undersells it. The function-local import os made os local to all of _execute_literature_collect, so the earlier uses raised:
UnboundLocalError: cannot access local variable 'os' where it is not associated with a value
_literature.py:392, in _execute_literature_collect
or os.environ.get(literature_config.s2_api_key_env, "")
Line 392 is inside the try: wrapping the entire real-API search, under a bare except Exception that logs [rate-limit] Literature search failed — falling back to LLM. So Stage 4 was not sometimes falling back — Semantic Scholar, OpenAlex and arXiv were unreachable on every run, and every pipeline silently produced LLM-generated candidates while logging what reads as a transient rate-limit. For a tool whose value rests on real citations, that's about as bad as a swallowed exception gets.
Reproduced before merge and confirmed gone after.
The ~400 lines of TestLiteratureCollectConfiguration are the right response: parametrised coverage of key resolution across inline/llm/env precedence and custom env names means the next refactor that breaks Stage 4's search path fails a test instead of quietly returning hallucinated papers. Post-merge: test_rc_executor.py + test_rc_literature.py → 254 passed. Full suite: 2956 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
osimport that broke environment-variable lookup in Stage 4.Root Cause
A function-local
import oscaused Python to treatosas a local variable throughout_execute_literature_collect.Stage 4 accessed
os.environbefore reaching that import, raisingUnboundLocalError. The existing broad exception handler then caught the error and silently skipped the real literature APIs.This regression was introduced by my changes in #299. I’m sorry I missed the interaction with the existing function-local import during testing. Thank you for reporting it in #309. This PR fixes the issue and adds orchestration-level regression coverage to prevent the same silent fallback from recurring.
Validation
8 passed78 passed207 passed2869 passed, 57 skippedTwo pre-existing Windows shell-related tests remain environment-specific and are unrelated to this change.
Fixes #309