Skip to content

Tidy up the shutdown sequence in EnhancedAgent#10

Open
Wanbogang wants to merge 2 commits intoTeneoProtocolAI:mainfrom
Wanbogang:fix/shutdown-ordering
Open

Tidy up the shutdown sequence in EnhancedAgent#10
Wanbogang wants to merge 2 commits intoTeneoProtocolAI:mainfrom
Wanbogang:fix/shutdown-ordering

Conversation

@Wanbogang
Copy link

@Wanbogang Wanbogang commented Dec 3, 2025

Description

Was looking at the agent shutdown logic and noticed the context was being cancelled a bit too early in the process. When the health server stops or cleanup needs to happen, having the main context already cancelled could lead to some flaky behavior.

Made a small adjustment to the order:

  • Health server stops first (it's doing network stuff)
  • Network disconnects next
  • Then we cancel the main agent context
  • Cache cleanup after that
  • Any final cleanup gets a fresh 5-second context to work with

Basically just reordering things so each step has what it needs to finish cleanly. The agent should stop a bit more reliably now.

No big changes to functionality, just better flow.

Type of Change

  • Bug fix

Changes Made

  • Testing
    • Tested locally
    • Added/updated tests
    • All tests pass

Additional Notes

Checklist

  • My code follows the project's coding style
  • I have tested my changes
  • I have updated the documentation (if needed)
  • My changes don't introduce new warnings
  • I have added comments for complex code (if needed)

Was looking at the agent shutdown logic and noticed the context was being
cancelled a bit too early in the process. When the health server stops
or cleanup needs to happen, having the main context already cancelled
could lead to some flaky behavior.

Made a small adjustment to the order:
- Health server stops first (it's doing network stuff)
- Network disconnects next
- Then we cancel the main agent context
- Cache cleanup after that
- Any final cleanup gets a fresh 5-second context to work with

Basically just reordering things so each step has what it needs to
finish cleanly. The agent should stop a bit more reliably now.

No big changes to functionality, just better flow.
@bjastrzebski
Copy link
Contributor

Hi @Wanbogang , our team has been busy in the Christmas-New Year time. Thank you so much for the improvements, Looks good to me!

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.

3 participants