Skip to content

Commit 8489a3d

Browse files
phernandezclaude
andauthored
fix: add X-Tigris-Consistent headers to all rclone commands (#558)
Signed-off-by: phernandez <paul@basicmachines.co> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a47c9c0 commit 8489a3d

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/basic_memory/cli/commands/cloud/rclone_commands.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
# Minimum rclone version for --create-empty-src-dirs support
2828
MIN_RCLONE_VERSION_EMPTY_DIRS = (1, 64, 0)
2929

30+
# Tigris edge caching returns stale data for users outside the origin region (iad).
31+
# These headers bypass edge cache and force reads/writes against the origin.
32+
# See: https://www.tigrisdata.com/docs/objects/consistency/
33+
TIGRIS_CONSISTENCY_HEADERS = [
34+
"--header-download", "X-Tigris-Consistent: true",
35+
"--header-upload", "X-Tigris-Consistent: true",
36+
]
37+
3038

3139
class RunResult(Protocol):
3240
returncode: int
@@ -210,6 +218,7 @@ def project_sync(
210218
"sync",
211219
str(local_path),
212220
remote_path,
221+
*TIGRIS_CONSISTENCY_HEADERS,
213222
"--filter-from",
214223
str(filter_path),
215224
]
@@ -279,6 +288,7 @@ def project_bisync(
279288
"bisync",
280289
str(local_path),
281290
remote_path,
291+
*TIGRIS_CONSISTENCY_HEADERS,
282292
"--resilient",
283293
"--conflict-resolve=newer",
284294
"--max-delete=25",
@@ -354,6 +364,7 @@ def project_check(
354364
"check",
355365
str(local_path),
356366
remote_path,
367+
*TIGRIS_CONSISTENCY_HEADERS,
357368
"--filter-from",
358369
str(filter_path),
359370
]
@@ -393,6 +404,6 @@ def project_ls(
393404
if path:
394405
remote_path = f"{remote_path}/{path}"
395406

396-
cmd = ["rclone", "ls", remote_path]
407+
cmd = ["rclone", "ls", *TIGRIS_CONSISTENCY_HEADERS, remote_path]
397408
result = run(cmd, capture_output=True, text=True, check=True)
398409
return result.stdout.splitlines()

tests/test_rclone_commands.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from basic_memory.cli.commands.cloud.rclone_commands import (
1010
MIN_RCLONE_VERSION_EMPTY_DIRS,
11+
TIGRIS_CONSISTENCY_HEADERS,
1112
RcloneError,
1213
SyncProject,
1314
bisync_initialized,
@@ -40,6 +41,18 @@ def __call__(self, cmd: list[str], **kwargs):
4041
return _RunResult(returncode=self._returncode, stdout=self._stdout)
4142

4243

44+
def _assert_has_consistency_headers(cmd: list[str]) -> None:
45+
"""Assert the rclone command includes Tigris consistency headers."""
46+
assert "--header-download" in cmd
47+
assert "X-Tigris-Consistent: true" in cmd
48+
assert "--header-upload" in cmd
49+
# Verify upload header value follows --header-upload
50+
upload_idx = cmd.index("--header-upload")
51+
assert cmd[upload_idx + 1] == "X-Tigris-Consistent: true"
52+
download_idx = cmd.index("--header-download")
53+
assert cmd[download_idx + 1] == "X-Tigris-Consistent: true"
54+
55+
4356
def _write_filter_file(tmp_path: Path) -> Path:
4457
p = tmp_path / "filters.txt"
4558
p.write_text("- .git/**\n", encoding="utf-8")
@@ -127,6 +140,7 @@ def test_project_sync_success(tmp_path):
127140
assert cmd[:2] == ["rclone", "sync"]
128141
assert Path(cmd[2]) == Path("/tmp/research")
129142
assert cmd[3] == "basic-memory-cloud:my-bucket/research"
143+
_assert_has_consistency_headers(cmd)
130144
assert "--filter-from" in cmd
131145
assert str(filter_path) in cmd
132146
assert "--dry-run" in cmd
@@ -208,6 +222,7 @@ def test_project_bisync_success(tmp_path):
208222
assert result is True
209223
cmd, _ = runner.calls[0]
210224
assert cmd[:2] == ["rclone", "bisync"]
225+
_assert_has_consistency_headers(cmd)
211226
assert "--resilient" in cmd
212227
assert "--conflict-resolve=newer" in cmd
213228
assert "--max-delete=25" in cmd
@@ -369,6 +384,7 @@ def test_project_check_success(tmp_path):
369384
assert result is True
370385
cmd, kwargs = runner.calls[0]
371386
assert cmd[:2] == ["rclone", "check"]
387+
_assert_has_consistency_headers(cmd)
372388
assert kwargs["capture_output"] is True
373389
assert kwargs["text"] is True
374390

@@ -407,6 +423,8 @@ def test_project_ls_success():
407423
project = SyncProject(name="research", path="app/data/research")
408424
files = project_ls(project, "my-bucket", run=runner, is_installed=lambda: True)
409425
assert files == ["file1.md", "file2.md", "subdir/file3.md"]
426+
cmd, _ = runner.calls[0]
427+
_assert_has_consistency_headers(cmd)
410428

411429

412430
def test_project_ls_with_subpath():

0 commit comments

Comments
 (0)