Skip to content

[BUG] Fix #220 #221 #222 — PandasAdapter dead code, negative limit validation, async background loop#243

Open
harsh2025-sketch wants to merge 2 commits intosktime:mainfrom
harsh2025-sketch:main
Open

[BUG] Fix #220 #221 #222 — PandasAdapter dead code, negative limit validation, async background loop#243
harsh2025-sketch wants to merge 2 commits intosktime:mainfrom
harsh2025-sketch:main

Conversation

@harsh2025-sketch
Copy link
Copy Markdown

Summary

Fixes three confirmed bugs found during ESoC 2026 codebase audit.

Fixes #220
Fixes #221
Fixes #222


Fix #220 — PandasAdapter auto-detection dead code

File: src/sktime_mcp/data/adapters/pandas_adapter.py

Condition was always False — pd.Index is base class of all pandas
index types so _detect_time_column was never called.

Fix: Removed pd.Index from check — detection now triggers correctly
on RangeIndex inputs.


Fix #221 — Negative limit returns 400+ results

File: src/sktime_mcp/tools/list_estimators.py

limit was never validated. limit=-5 caused all_estimators[0:-5]
to return 410 results, flooding LLM agent context window.

Fix: Added guard before slice:
if limit is not None and limit < 0: return error


Fix #222 — Async jobs stay pending forever

Files: _background_loop.py (new), fit_predict.py, data_tools.py

run_coroutine_threadsafe was submitting to a loop never started
in a background thread. All async jobs stayed pending forever.

Fix: Created _BackgroundLoop with daemon thread running
loop.run_forever(). All async tools now submit via BG_LOOP.submit(coro).


Tests — all passing

Test Result
test_list_estimators_negative_limit_rejected done
test_list_estimators_zero_limit_returns_empty done
test_pandas_adapter_auto_detects_time_column done
test_async_fit_predict_tool_completes_background_job done

Copilot AI review requested due to automatic review settings April 18, 2026 08:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes three audited bugs across data loading, estimator listing, and async background job execution in sktime_mcp, and adds regression tests to prevent recurrence.

Changes:

  • Fix PandasAdapter time-column auto-detection so _detect_time_column() is reachable when the index is a default RangeIndex.
  • Validate limit in list_estimators_tool to reject negative values that would otherwise return a near-full page.
  • Introduce a shared background asyncio loop (BG_LOOP) and route async tool submissions through it so background jobs actually execute.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/sktime_mcp/data/adapters/pandas_adapter.py Adjusts index-type guard so time-column detection runs when time_column is omitted.
src/sktime_mcp/tools/list_estimators.py Adds negative limit validation before slicing.
src/sktime_mcp/runtime/_background_loop.py Adds a singleton background event loop running in a daemon thread and a submit() API.
src/sktime_mcp/tools/fit_predict.py Uses BG_LOOP.submit(...) for async fit/predict jobs instead of submitting to a non-running loop.
src/sktime_mcp/tools/data_tools.py Uses BG_LOOP.submit(...) for async data-loading jobs instead of submitting to a non-running loop.
tests/test_core.py Adds regression tests for negative/zero limit and pandas time-column auto-detection.
tests/test_background_jobs.py Adds a tool-level regression test ensuring async fit/predict jobs move beyond pending.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sktime_mcp/data/adapters/pandas_adapter.py Outdated
Comment thread src/sktime_mcp/runtime/_background_loop.py
Comment thread tests/test_background_jobs.py
Comment thread tests/test_background_jobs.py Outdated
Comment thread tests/test_core.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment