Skip to content

fix: async plan isolation, blocking API call, and CORS for production#205

Open
angziii wants to merge 1 commit intohuggingface:mainfrom
angziii:fix/blocking-api-plan-isolation-cors
Open

fix: async plan isolation, blocking API call, and CORS for production#205
angziii wants to merge 1 commit intohuggingface:mainfrom
angziii:fix/blocking-api-plan-isolation-cors

Conversation

@angziii
Copy link
Copy Markdown

@angziii angziii commented May 1, 2026

Summary

Three targeted fixes:

  • plan_tool.py: Per-session plan isolation — The module-level _current_plan list was shared across all sessions, causing concurrent sessions to overwrite each other's plans. Replaced with a per-session dict keyed by session_id. Updated get_current_plan(), format_plan_display(), and print_plan() to be session-aware.

  • hf_repo_git_tool.py: Async wrapper for get_repo_discussions — Every other HfApi call in this file uses _async_call() to run in a thread pool, but get_repo_discussions was called synchronously, blocking the event loop during the HTTP request. Wrapped it in _async_call() with the list materialized inside the thread.

  • backend/main.py: CORS origins for productionallow_origins was hardcoded to localhost-only, causing CORS middleware to reject browser requests when deployed to HF Spaces. Added SPACE_HOST env var to the allow list dynamically.

Test plan

  • Code review of diff
  • Verify plan isolation: two concurrent sessions should have independent plans
  • Verify get_repo_discussions no longer blocks the event loop
  • Verify CORS allows production HF Spaces URL when SPACE_HOST is set

- plan_tool.py: Replace module-level _current_plan list with per-session
  _session_plans dict to prevent cross-session plan corruption when
  multiple concurrent sessions use the plan tool.
- hf_repo_git_tool.py: Wrap get_repo_discussions in _async_call to avoid
  blocking the event loop with a synchronous HTTP request.
- backend/main.py: Add SPACE_HOST env var to CORS allow_origins so the
  production HF Spaces frontend is not rejected by the middleware.
- terminal_display.py / main.py: Thread session through plan display
  functions for session-aware plan retrieval.
@fglogan
Copy link
Copy Markdown

fglogan commented May 3, 2026

closed per maintainer request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants