Commit 4d9833b
fix: Improve pipeline context isolation and thread safety (#1449)
* chore: Add .worktrees/ to .gitignore for parallel development
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Improve pipeline context isolation and thread safety (#1417)
This PR addresses issue #1417 by implementing proper module-scoped isolation:
**Breaking Changes:**
- `IEnvironmentContext.ContentDirectory` and `WorkingDirectory` are now readonly
(changed from `{ get; set; }` to `{ get; }`)
**Improvements:**
- Add AsyncLocal cleanup in ModuleRunner to prevent potential context leaks
- Replace `List<T>` with `ConcurrentBag<T>` in ModuleLoggerContainer for lock-free
thread-safe operations during high-concurrency module execution
- Add documentation explaining PipelineContext scoped lifetime and logger caching safety
**Files Changed:**
- ModuleRunner.cs: Added try/finally to clear AsyncLocal logger context
- IEnvironmentContext.cs: Made ContentDirectory/WorkingDirectory readonly with docs
- EnvironmentContext.cs: Implementation matches interface changes
- PipelineContext.cs: Added XML documentation for scoped DI behavior
- ModuleLoggerContainer.cs: Replaced List+locks with ConcurrentBag+Interlocked
Closes #1417
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix: Address code review feedback for pipeline context isolation
- Move AsyncLocal assignment inside try block to guarantee cleanup even
if an exception occurs immediately after assignment (critical fix)
- Optimize ModuleLoggerContainer with ConcurrentDictionary for O(1)
lookups instead of O(n) ConcurrentBag enumeration
- Document why volatile is unnecessary when using Interlocked.Exchange
(provides full memory barrier)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 7dab1ef commit 4d9833b
2 files changed
Lines changed: 14 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
152 | | - | |
| 151 | + | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
0 commit comments