Commit 7f8612d
Add keepAlive flag to prevent scale-to-zero during process execution (#176)
* Add lifecycle management for sandbox processes
Introduces new lifecycle features to the sandbox API, including the ability to force stop processes and retrieve the current sandbox status. The `/stop` endpoint allows for immediate or scheduled removal of the keepAlive flag from running processes, enabling auto-hibernation. The `/status` endpoint provides information on the current state of the sandbox and active keepAlive processes.
Additionally, integrates the lifecycle management with the MCP tools, enhancing the overall process control and monitoring capabilities. The scale-to-zero functionality is also improved with crash recovery mechanisms.
Updates include:
- New `LifecycleHandler` for managing lifecycle operations.
- API documentation updates for new endpoints.
- Integration of keepAlive functionality in process management.
- Comprehensive tests for lifecycle features and MCP integration.
* Enhance scale-to-zero functionality with improved error handling and logging
* Remove lifecycle management endpoints and related functionality
This commit removes the `/stop` and `/status` endpoints from the sandbox API, along with the associated `LifecycleHandler` and related data structures. The lifecycle management features, including the ability to force stop processes and retrieve the current sandbox status, have been deprecated.
Updates include:
- Deletion of lifecycle-related API routes and handlers.
- Removal of lifecycle management types and structures from the codebase.
- Adjustments to documentation to reflect the removal of these features.
This change simplifies the API and focuses on core process management functionalities.
* Fix PR
* Fix bug introduce with AI check
* Implement keepAlive timeout handling for restarted processes
This commit introduces functionality to manage timeouts for processes with the keepAlive flag enabled. If a process is restarted and keepAlive is active with a specified timeout, a goroutine is initiated to monitor the timeout and kill the process if it exceeds the limit. For processes with an infinite timeout, the goroutine simply waits for the process to complete. This enhancement improves process management and ensures better resource handling.
* Fix some recommendation from AI
* Enhance logging in ProcessManager to include process name in scale-to-zero warnings and timeout messages. Clear KeepAlive state before killing processes to prevent double ScaleEnable calls. Refactor related log messages for consistency.
* Refactor logging in ProcessManager to use structured log entries for KeepAlive events. Enhance clarity by including process details in log messages for scale-to-zero operations and timeout handling. This improves consistency and debuggability of process management logs.
* Sanitize user-provided values in log entries to prevent log injection (CWE-117)
Add sanitizeLogValue() helper that escapes newlines and control characters.
Replace structured logging (logrus.WithFields) with simple logrus.Infof/Warnf
calls that use sanitized values - clearer and more readable.
Addresses all CodeQL 'Log entries created from user input' warnings.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* Improve sanitizeLogValue to strip all control characters (CWE-117)
Replace strings.NewReplacer with byte-level filtering that strips all
control characters (< 0x20) including newlines. This provides more
thorough sanitization against log injection.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* Use strings.NewReplacer as CodeQL-recognized sanitizer for log injection (CWE-117)
Replace custom byte-level loop with package-level strings.NewReplacer
variable (logSanitizer). CodeQL explicitly recognizes strings.Replacer.Replace
as a sanitizer for go/log-injection since github/codeql#11910.
Call logSanitizer.Replace() directly at each log site.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* Use %q format directive for user-provided values in log entries (CWE-117)
CodeQL's SafeFormatArgumentSanitizer explicitly recognizes %q as safe
because it escapes newline characters. This is the simplest and most
idiomatic fix - no helper functions or variables needed.
Removes the logSanitizer variable entirely. User-provided values (name,
command) are now logged with %q which produces Go-syntax quoted strings,
making any control characters visible in the output.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* Revert sanitize/log changes - restore original structured logging
Reverts commits 6902a62, 16773fb, 4eeb6f7, 3a5b776 which added
log sanitization for CWE-117. Keeps all other agent recommendations
(structured logging with logrus.WithFields, race condition fix, etc).
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* Fix StopProcess keepAlive leak and KeepAlive data race
- StopProcess (SIGTERM path) now clears KeepAlive and calls ScaleEnable,
preventing the scale-to-zero counter from leaking when a keepAlive
process is gracefully stopped.
- All reads/writes of process.KeepAlive are now synchronized via pm.mu:
KillProcess and StopProcess write under Lock(), completion goroutines
read under RLock(). This eliminates the data race between the kill/stop
path and the completion goroutine.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* Fix data race on oldProcess.KeepAlive read in restartProcess
Protect the read of oldProcess.KeepAlive and oldProcess.Timeout in
restartProcess with pm.mu.RLock(), matching the synchronization used
by KillProcess/StopProcess which write under pm.mu.Lock().
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
---------
Co-authored-by: cploujoux <ch.ploujoux@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>1 parent 0ac40b9 commit 7f8612d
File tree
10 files changed
+538
-30
lines changed- sandbox-api
- docs
- src
- handler
- process
- lib/blaxel
- mcp
10 files changed
+538
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2185 | 2185 | | |
2186 | 2186 | | |
2187 | 2187 | | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
2188 | 2193 | | |
2189 | 2194 | | |
2190 | 2195 | | |
| |||
2198 | 2203 | | |
2199 | 2204 | | |
2200 | 2205 | | |
| 2206 | + | |
2201 | 2207 | | |
2202 | 2208 | | |
2203 | 2209 | | |
| |||
2249 | 2255 | | |
2250 | 2256 | | |
2251 | 2257 | | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
2252 | 2263 | | |
2253 | 2264 | | |
2254 | 2265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1772 | 1772 | | |
1773 | 1773 | | |
1774 | 1774 | | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
1775 | 1779 | | |
1776 | 1780 | | |
1777 | 1781 | | |
| |||
1782 | 1786 | | |
1783 | 1787 | | |
1784 | 1788 | | |
| 1789 | + | |
1785 | 1790 | | |
1786 | 1791 | | |
1787 | 1792 | | |
| |||
1811 | 1816 | | |
1812 | 1817 | | |
1813 | 1818 | | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
1814 | 1823 | | |
1815 | 1824 | | |
1816 | 1825 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
49 | 57 | | |
50 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | | - | |
91 | | - | |
| 92 | + | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| |||
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| 164 | + | |
161 | 165 | | |
162 | 166 | | |
163 | 167 | | |
| |||
202 | 206 | | |
203 | 207 | | |
204 | 208 | | |
| 209 | + | |
205 | 210 | | |
206 | 211 | | |
207 | 212 | | |
| |||
293 | 298 | | |
294 | 299 | | |
295 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
296 | 311 | | |
297 | | - | |
| 312 | + | |
298 | 313 | | |
299 | 314 | | |
300 | 315 | | |
| |||
335 | 350 | | |
336 | 351 | | |
337 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
338 | 363 | | |
339 | 364 | | |
340 | 365 | | |
| |||
346 | 371 | | |
347 | 372 | | |
348 | 373 | | |
349 | | - | |
| 374 | + | |
350 | 375 | | |
351 | 376 | | |
352 | 377 | | |
| |||
0 commit comments