feat: Per-chat isolation and contention detection for Time Travel#1605
Open
gdeyoung wants to merge 1 commit into
Open
feat: Per-chat isolation and contention detection for Time Travel#1605gdeyoung wants to merge 1 commit into
gdeyoung wants to merge 1 commit into
Conversation
Fixes index.lock contention when multiple chats run simultaneously. Each chat now gets its own isolated shadow git workspace. Adds file categorization, ownership tracking, and cross-chat conflict detection to prevent destructive restores. Changes: - workspace_id_for() accepts context_id for per-chat isolation - resolve_workspace() passes context_id through - New contention_engine.py with file risk categorization - New history_aggregate.py API for global view - New test suite (7 tests, all passing) Backward compatible: empty context_id uses legacy path-only hash.
cdc19fb to
43926cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per-Chat Isolation and Contention Detection for Time Travel
Problem
When multiple Agent Zero chats run simultaneously, they all share the same shadow git repository because
workspace_id_for()only hashes the display path. This causesindex.lockcontention and crashes:Additionally, per-chat isolation introduces a shared filesystem contention problem: restoring one chat's snapshot can silently overwrite another chat's changes, which is especially dangerous for system/platform files.
Solution
This PR implements two features:
1. Per-Chat Workspace Isolation
Each chat now gets its own isolated shadow git workspace by including
context_idin the workspace ID hash:Key property: When
context_idis empty, the output is identical to the old implementation, ensuring full backward compatibility.2. Cross-Chat Contention Detection
A new
contention_engine.pyprevents destructive restores by:Files Changed
plugins/_time_travel/helpers/time_travel.pyplugins/_time_travel/helpers/contention_engine.pyplugins/_time_travel/api/history_aggregate.pytests/test_time_travel_per_chat_isolation.pyTotal: 559 lines added, 4 lines removed
Backward Compatibility
context_idproduces the identical workspace ID as the current implementationTest Results
Per-Chat Isolation (7/7 passing):
File Categorization (11/11 passing):
Contention Detection (integration test passing):
How It Works
Restore contention flow:
Debounce Isolation
The debounce system uses
workspace.idas dict keys. Since workspace IDs now includecontext_id, per-chat debounce isolation works automatically without any code changes to the debounce logic.Performance Impact
All overhead is restore-time only - snapshot performance is negligibly affected.