Skip to content

Conversation

@coterp
Copy link

@coterp coterp commented Dec 17, 2025

Summary

This PR improves the reliability of Cypress E2E runs when starting and stopping Chainlit.

Changes

  • Track the spawned Chainlit process and shut it down reliably via process group
  • Use port-based termination (fkill) only as a fallback when no tracked process exists
  • Fix broken entrypoint file existence check (async fs/promises.access was not awaited)
  • Improve signal handling and typing in cypress.config.ts
  • Modernize Node core imports (node: + type imports)

Motivation

Cypress E2E runs were failing consistently due to unreliable Chainlit shutdown and restart behavior in containerized dev environments.

Tests frequently failed with port-in-use errors because previous Chainlit instances were not reliably terminated between runs or between specs. The existing port-based termination (fkill(:port)) proved unreliable in containers and was insufficient as a primary means of terminating Chainlit.

This PR introduces explicit process tracking and shutdown of the spawned Chainlit process, using port-based termination only as a fallback to clean up stray instances from previous runs.

Testing

  • uv run pytest --cov=chainlit
  • pnpm test (Cypress, headless via Xvfb)
  • pnpm test:ui
  • pnpm lint

Summary by cubic

Improves reliability of Cypress E2E runs by cleanly starting and stopping Chainlit to avoid port-in-use errors in containers. Tracks and kills the spawned process group, using port-based termination only as a fallback.

  • Bug Fixes
    • Fix entrypoint check by awaiting fs.promises.access.
    • Add stopChainlit and typed signal handling to kill the process group cleanly; fall back to fkill when no tracked process exists.
    • Streamline Cypress setup and restartChainlit flow; modernize Node imports and types.
    • On Windows, kill the entire Chainlit process tree with taskkill for reliable port release.

Written for commit d8e9a68. Summary will update automatically on new commits.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. dev-tooling Relating to developer/contributor toolings. labels Dec 17, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

@asvishnyakov
Copy link
Member

@coterp Thank you for contribution!

@hayescode @sandangel I would like to review this PR myself, as I tried to implement such functionality earlier and had an issues with that

@coterp
Copy link
Author

coterp commented Dec 17, 2025

@hayescode Sounds good, thanks for your review.
Let me know if you have any questions or want me to adjust anything.

@asvishnyakov asvishnyakov changed the title Fix Cypress Chainlit shutdown and entrypoint checks fix(cypress): Chainlit shutdown and entrypoint checks Dec 23, 2025
Copy link
Member

@asvishnyakov asvishnyakov left a comment

Choose a reason for hiding this comment

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

@coterp Unfortunately I have same issue with it as when I tried implement such feature myself: it doesn't work in Cypress interactive mode, at least on Linux
Try to:

  • Open Cypress in interactive mode (for example, via pnpm test:interactive)
  • Run custom_theme tests (you'll see green screen, then red)
  • Run data_layer tests (you'll see green screen again and tests will fail because login isn't enabled in previous test server, while it is in data_layer test server)

@asvishnyakov
Copy link
Member

But I think we can merge some implements from here, like broken entrypoint file existence check, if you'll remove or fix new server restart code

@coterp
Copy link
Author

coterp commented Dec 30, 2025

Thanks for the reproduction steps and feedback. That helps clarify the scope.

Given that the restart behavior only affects Cypress interactive mode on Linux and isn’t something I can easily validate in my current dev container setup, I think the safest approach is to split this PR and drop the restart changes for now, keeping only the clearly correct fixes.

I should be able to push that split as early as tomorrow, though it may slip into early next week depending on availability.

@coterp
Copy link
Author

coterp commented Dec 30, 2025

I went ahead and tried to reproduce the issue in Cypress interactive mode on Linux at commit d8e9a68d. I ran custom_theme and then data_layer in the same Cypress session, and both passed for me. I tried this with both Electron and Chrome.

I’m running on RHEL 9.7. Could you share which browser and distro/desktop you’re using? I’ll try to match it.

@asvishnyakov
Copy link
Member

@coterp Happy holidays! I'm using Ubuntu 24.04 and running Cypress via pnpm test:interactive with Electron. May be it was something local, let me try again within few days and I'll return with additional feedback

@coterp
Copy link
Author

coterp commented Jan 6, 2026

Thanks! I hope you had happy holidays as well!

Quick update: I set up a test environment on Ubuntu 24.04 and still wasn’t able to reproduce the behavior you mentioned. I tried running the specs in rapid succession to rule out timing issues, tested with both Electron and Chrome, and ran several other specs, but couldn’t get a failure.

Let me know if there’s any additional detail I can try to match.

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

Labels

dev-tooling Relating to developer/contributor toolings. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants