Skip to content

perf(cache): extend shallow-copy cache helpers to mirror PRs - #839

Closed
mkdev5 wants to merge 1 commit into
entrius:testfrom
mkdev5:fix/issue-785-cache-shallow-copy
Closed

perf(cache): extend shallow-copy cache helpers to mirror PRs#839
mkdev5 wants to merge 1 commit into
entrius:testfrom
mkdev5:fix/issue-785-cache-shallow-copy

Conversation

@mkdev5

@mkdev5 mkdev5 commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

_build_cache_entry and _isolate_for_downstream from #786 only handle legacy PullRequest lists. After copy.copy(evaluation), the three mirror lists (mirror_merged_prs, mirror_open_prs, mirror_closed_prs) remain as shared references — source mutations leak into the cache, successive get() calls share the same ScoredMirrorPR objects, and heavy files[*].head_content / base_content blobs are never stripped.

What changed

  • _build_cache_entry — copies each ScoredMirrorPR and its nested MirrorPullRequest (review_summary, labels, linked_issues), sets files = None.
  • _isolate_for_downstream — copies each cached ScoredMirrorPR and mutable sub-objects to isolate successive get() calls.
  • 4 module-level helpers: _scored_mirror_pr_for_cache, _scored_mirror_pr_isolated, _mirror_pr_copy, _mirror_linked_issue_copy.
  • TestMirrorCacheIsolation — 3 tests covering file-blob stripping, store-to-get isolation, and get-to-get isolation.

Related Issues

Closes #696

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other (describe below)

Testing

  • Tests added/updated
  • Manually tested
uv run pytest tests/validator/test_validator_cache_fallback.py  # 9 passed
uv run ruff check gittensor/classes.py tests/validator/test_validator_cache_fallback.py  # All checks passed
uv run ruff format --check gittensor/classes.py tests/validator/test_validator_cache_fallback.py  # Already formatted
uv run pyright gittensor/classes.py tests/validator/test_validator_cache_fallback.py  # 0 errors

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Changes are documented (if applicable)

@xiao-xiao-mao xiao-xiao-mao Bot added the enhancement New feature or request label Apr 28, 2026
@anderdc

anderdc commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

#786 just merged with the legacy-path shallow-copy helpers (_build_cache_entry / _isolate_for_downstream). Please rebase this onto test and scope it down to just the mirror additions on top of those helpers.

Keep: dropping ScoredMirrorPR.files in _build_cache_entry, shallow-copying each ScoredMirrorPR (plus pr / pr.review_summary / pr.labels / pr.linked_issues with their labels) in _isolate_for_downstream, and the mirror-specific tests.

Drop: the rewrite to a single create_lightweight_copy (already replaced), _copy_pull_request_for_cache / _copy_issues (equivalents already in _pr_for_cache / _pr_with_fresh_issues), and the legacy-only test cases #786 already covers.

@mkdev5
mkdev5 force-pushed the fix/issue-785-cache-shallow-copy branch from 385a54c to 37af439 Compare April 29, 2026 20:42
Wire ScoredMirrorPR handling into _build_cache_entry (drop files,
copy pr/review_summary/labels/linked_issues) and _isolate_for_downstream
(shallow-copy each ScoredMirrorPR plus mutable sub-objects).

Add TestMirrorCacheIsolation covering file-blob stripping,
store-to-get isolation, and get-to-get isolation for mirror PRs.

Closes #696
@mkdev5 mkdev5 changed the title perf(cache): replace MinerEvaluationCache deepcopy with targeted copies perf(cache): extend shallow-copy cache helpers to mirror PRs Apr 29, 2026
@mkdev5
mkdev5 force-pushed the fix/issue-785-cache-shallow-copy branch from 37af439 to 442ad50 Compare April 29, 2026 20:54
@mkdev5

mkdev5 commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

#786 just merged with the legacy-path shallow-copy helpers (_build_cache_entry / _isolate_for_downstream). Please rebase this onto test and scope it down to just the mirror additions on top of those helpers.

Keep: dropping ScoredMirrorPR.files in _build_cache_entry, shallow-copying each ScoredMirrorPR (plus pr / pr.review_summary / pr.labels / pr.linked_issues with their labels) in _isolate_for_downstream, and the mirror-specific tests.

Drop: the rewrite to a single create_lightweight_copy (already replaced), _copy_pull_request_for_cache / _copy_issues (equivalents already in _pr_for_cache / _pr_with_fresh_issues), and the legacy-only test cases #786 already covers.

@anderdc can you please review the update?

@anderdc

anderdc commented May 1, 2026

Copy link
Copy Markdown
Collaborator

Closing as duplicate of #824

@anderdc anderdc closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(cache): shallow-copy cache helpers miss mirror PR lists

2 participants