Skip to content

UN-2942 [HOT-FIX] API deployments now properly clean up execution directories after completion#1635

Merged
ritwik-g merged 1 commit into
v0.138.17-hotfixfrom
fix/UN-2942-HOT-FIX_api-deployment-directory-cleanup
Nov 3, 2025
Merged

UN-2942 [HOT-FIX] API deployments now properly clean up execution directories after completion#1635
ritwik-g merged 1 commit into
v0.138.17-hotfixfrom
fix/UN-2942-HOT-FIX_api-deployment-directory-cleanup

Conversation

@muhammad-ali-e

Copy link
Copy Markdown
Contributor

What

  • Added missing cleanup call to process_batch_callback_api function in workers/callback/tasks.py
  • API deployments now properly clean up both API execution directories and workflow execution directories after completion

Why

  • API deployments were not cleaning up execution directories after workflow completion
  • ETL workflows had the cleanup logic, but API callback implementation was missing this critical step
  • This caused accumulation of execution files on disk over time for API deployments
  • The cleanup function _cleanup_execution_resources() already existed and worked correctly for ETL workflows

How

  • Added cleanup_result = _cleanup_execution_resources(context) call after UI logs publishing (line 1574-1575)
  • The cleanup function already handles API deployments correctly:
    • Skips cache cleanup for API deployments (preserves cache for subsequent requests)
    • Cleans both API execution directory (unstract/api/...) and workflow execution directory (unstract/execution/...)
    • Uses the same proven cleanup logic as ETL workflows

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

No, this PR cannot break existing features:

  • This is a 2-line addition that adds missing functionality (bug fix)
  • Uses the existing _cleanup_execution_resources() function that is already proven to work for ETL workflows
  • No changes to API workflow execution logic, status updates, or pipeline handling
  • No changes to cache behavior - cache is still preserved for API deployments as designed
  • Only affects post-completion cleanup, which was completely missing before
  • The cleanup operation is non-critical and failures are logged without breaking the callback flow
  • Backward compatible - API deployments will simply start cleaning up directories (expected behavior)

Database Migrations

  • No database migrations required
  • No database schema changes

Env Config

  • No environment configuration changes required
  • No new environment variables added

Relevant Docs

  • Related to worker architecture documentation in workers/ARCHITECTURE_DOCUMENTATION.md
  • Cleanup logic documented in workers/callback/tasks.py function comments

Related Issues or PRs

  • Jira Ticket: UN-2942
  • Fixes issue where API deployment execution directories were not being cleaned up

Dependencies Versions

  • No dependency version changes
  • No new dependencies added

Notes on Testing

Testing Steps:

  1. Deploy an API workflow with file processing
  2. Check callback worker logs for cleanup messages:
    ℹ️  Cache cleanup skipped for API deployment (cache preserved)
    🧹 Starting directory cleanup for execution xxx (2 directories to clean)
    🧹 Cleaning api directory: unstract/api/...
    ✅ Successfully cleaned up api execution directory
    🧹 Cleaning workflow directory: unstract/execution/...
    ✅ Successfully cleaned up workflow execution directory
    
  3. Verify directories are removed after execution completes
  4. Verify API functionality still works correctly (cache preserved)
  5. Compare with ETL workflow cleanup behavior (should be identical)

Screenshots

N/A - Backend/worker change with no UI impact

Checklist

I have read and understood the Contribution Guidelines.

@coderabbitai

coderabbitai Bot commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/UN-2942-HOT-FIX_api-deployment-directory-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2025

Copy link
Copy Markdown

@ritwik-g ritwik-g merged commit 200cf43 into v0.138.17-hotfix Nov 3, 2025
5 checks passed
@ritwik-g ritwik-g deleted the fix/UN-2942-HOT-FIX_api-deployment-directory-cleanup branch November 3, 2025 13:48
ritwik-g pushed a commit that referenced this pull request Nov 3, 2025
…atibility (#1637)

* Fix/un 2910 fix prevent task duplication while warm shutdown heartbeatkeeper and resolve sigsegv issues (#1616)

* UN-2910 [FIX] Prevent task duplication during Kubernetes warm shutdown with HeartbeatKeeper

Implemented HeartbeatKeeper bootstep to maintain RabbitMQ connection during
Celery warm shutdown, preventing task requeuing and duplication during
Kubernetes rolling updates and graceful pod terminations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* structuretool-for-testing

* handling envs

* sonar issue addressing

* forksafe gcs and gdrive connectors

* updated grpc imports

* fork safty in shared internal client session

* reverted forksafty fropm baseclient, addressed coderabbitai comments

* minor changes

* reverted structure tool changes that was changed for tetsing

* plugin registry changes for .so file comaptibility

* added default value for heartbeat

---------

Co-authored-by: Claude <noreply@anthropic.com>

* Fix: Added InternalAPIAuthMiddleware to Django middleware stack (#1628)

* UN-2942 [HOT-FIX] API deployments now properly clean up execution directories after completion (#1635)

UN-2942 [FIX] API deployments now properly clean up execution directories after completion

* UN-2942 [FIX] Fix API deployment directory cleanup and MinIO compatibility (#1636)

* Added boto3 version pin to match backend

* Added uvlock

* fix execution directory for api

---------

Signed-off-by: ali <117142933+muhammad-ali-e@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
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