| 1511 | } |
| 1512 | |
| 1513 | async appendToHistory(workspaceId: string, message: MuxMessage): Promise<Result<void>> { |
| 1514 | return this.fileLocks.withLock(workspaceId, async () => { |
| 1515 | const result = await this._appendToHistoryUnlocked(workspaceId, message); |
| 1516 | if (result.success) { |
| 1517 | // A new durable boundary seals the previous epoch — rotate it out of |
| 1518 | // chat.jsonl so subsequent reads/rewrites stay O(active epoch). |
| 1519 | await this.rotateAfterBoundaryWriteUnlocked(workspaceId, message); |
| 1520 | } |
| 1521 | return result; |
| 1522 | }); |
| 1523 | } |
| 1524 | |
| 1525 | /** |
| 1526 | * Update an existing message in history by historySequence |