Skip to content

fix(module): keep a concurrent verified cache fill instead of replacing it - #105

Merged
M3gA-Mind merged 1 commit into
tinyhumansai:mainfrom
M3gA-Mind:fix/module-cache-keep-concurrent-fill
Oct 23, 2026
Merged

M3gA-Mind merged 1 commit into
tinyhumansai:mainfrom
M3gA-Mind:fix/module-cache-keep-concurrent-fill

Conversation

@M3gA-Mind

Copy link
Copy Markdown
Collaborator

Summary

cache::commit removes whatever is at the cache directory and renames the staging directory over it. acquire_cached only looked at the cache again after a failed commit. So when two processes miss the cache for the same release at the same time, the one that finishes second deletes the first one's verified directory, which that process may already have its module mapped from, and replaces it with an identical copy.

Fix

The commit tail of acquire_cached moves into commit_or_reuse, which checks cache::find_verified once more right before committing. If the cache already verifies (a concurrent fill), the staging directory is dropped and the existing module is returned. The existing fallback after a failed commit is unchanged.

A ponytail: note records the remaining window: a sibling can still commit between that check and the rename. Closing it needs a cross-process File::lock, which needs Rust 1.89.

Validation

Regression test a_concurrent_fill_that_verifies_is_kept_rather_than_replaced, run alone with cargo test -p tinybus --features modules --lib -- <name>:

result
before (pre-commit check disabled) FAILED: "the sibling's verified cache directory was replaced"
after passed (with the two existing cache tests: 3 passed)

Behaviour change

When a verified fill for the same release appears while a download is in flight, the download's copy is discarded and the existing directory is used. Nothing changes when the cache is empty or fails verification.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1cba1fb6-fc3d-43a6-8219-ed2826972ac8
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@tinysweeper

tinysweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: 4506d3f2c2573cced2b5bbdd94ea82fb2c7afb52

Verdict: Ready for maintainer review · Priority: none
Coverage: Reviewed 2 of 2 files.
Pull request purpose (title): fix(module): keep a…

Diagnostics and supporting details

Full summary

Pull request purpose (title): fix(module): keep a concurrent verified cache fill instead of replacing it. Purpose (from the pull-request title): fix(module): keep a concurrent verified cache fill instead of replacing it. The pull request addresses a race in the GitHub release module cache where two processes missing the cache for the same release simultaneously cause the second finisher to delete the first's verified directory via `cache::commit` and replace it with an identical copy. The commit tail of `acquire_cached` is moved into a new `commit_or_reuse` helper in `crates/tinybus/src/module/github.rs` that re-checks `cache::find_verified` before committing; on a hit, staging is dropped and the cached module and digest are returned. The pre-existing post-failure fallback is retained through a shared closure, and a `ponytail:` note records the remaining check-then-rename window until a cross-process `File::lock` is available at Rust 1.89. A regression test covering the reuse path is added to `crates/tinybus/src/module/github_tests.rs`. No push delta is available.

Review snapshot

Change surface Files Review signal Count
Production 1 Active findings 0
Tests 1 Noted findings 0
Documentation 0 Resolved findings 0
Configuration 0 Pending checks/questions 0

Completeness: Complete
Test assessment: No supported feature-to-test mapping was available; this does not mean tests are absent or passed.

What changed

`acquire_cached` in `crates/tinybus/src/module/github.rs` now hands its post-staging work to a new `commit_or_reuse` function. That helper builds a `concurrent_fill` closure over `cache::find_verified` and checks it before `cache::commit`; on a verified hit it logs and returns the cached module and digest without replacing the directory. The existing race fallback after a failed commit reuses the same closure. The remaining race window is documented in a `ponytail:` comment. A new test in `crates/tinybus/src/module/github_tests.rs` exercises keeping a concurrent verified fill.

Features

  • Added — `commit_or_reuse` pre-commit verification check: A verified cache fill that appears while a download is in flight is kept rather than deleted and replaced, so a sibling process's mapped module is not disturbed; behavior is unchanged when the cache is empty or fails verification. (crates/tinybus/src/module/github.rs pub(crate) fn acquire_cached(release: &CachedRelease<'_>) -> Result<(PathBuf, St)
  • Internal refactor — Commit tail of `acquire_cached` extracted into `commit_or_reuse`: The existing post-commit-failure logic that falls back to a concurrent fill is preserved unchanged and shared through a `concurrent_fill` closure; commit failures without a verified fill still propagate as before. (crates/tinybus/src/module/github.rs pub(crate) fn acquire_cached(release: &CachedRelease<'_>) -> Result<(PathBuf, St)
  • Added — Regression test for keeping a concurrent verified fill: Pins the reuse path: a pre-populated sibling cache directory with an in-use marker is left intact, and the returned module and digest come from the cache rather than staging. (crates/tinybus/src/module/github_tests.rs fn an_asset_name_that_leaves_the_cache_directory_is_refused() {)

Tests

No supported feature-to-test mapping was produced. Test execution is not inferred.

Findings

No active actionable findings.

Before merge

None.

Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The critique lane answered with no retained findings, noting that `commit_or_reuse` checks the cache for a verified sibling fill before replacing it and that the test exercises that path through the real cache. One model observation was capped at Likely confidence due to degraded retrieval.
  • Lane summary: Critique findings were capped at Likely confidence because retrieval was degraded: Reuse the pinned digest consistency of the concurrent fill. (1 model finding retained at no more than Likely confidence because retrieval was degraded) _The code index is behind this pull request (indexed at `b12f71ab4b21`), so retrieved context may be out of date._

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The security lane answered with no defects: the change keeps a verified sibling cache directory instead of overwriting it, the new test exercises the path through the real `find_verified` check, and no new input path, permission widening, or repository-rule violation was found in the two changed files.
  • Lane summary: The change keeps a verified sibling cache directory instead of overwriting it, and the new test exercises that path through the real `find_verified` check. Behaviour is a strict improvement over the previous replace-on-commit and I found no new input path, permission widening, or repository-rule violation in these two files. _The code index is behind this pull request (indexed at `b12f71ab4b21`), so retrieved context may be out of date._

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The tests lane answered with nothing to report: the new early-return branch is exercised by the regression test asserting observable filesystem behavior, and the existing commit-lost-a-race fallback remains in place.
  • Lane summary: The change looks sound and is covered: the new early-return branch in `commit_or_reuse` is exercised by `a_concurrent_fill_that_verifies_is_kept_rather_than_replaced`, which asserts on observable filesystem behaviour (the sibling's marker survives, the returned module path is canonical and outside staging, and the digest matches) rather than on mocks, and the existing commit-lost-a-race fallback remains. I found nothing to report. _The code index is behind this pull request (indexed at `b12f71ab4b21`), so retrieved context may be out of date._

commits

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: The commits lane answered and reports no sensitive content in committed files.
  • Lane summary: No sensitive content in committed files. _The code index is behind this pull request (indexed at `b12f71ab4b21`), so retrieved context may be out of date._

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The description matches the diff: it states the race, the new `commit_or_reuse` pre-commit check, the unchanged failed-commit fallback, the remaining window noted in the `ponytail:` comment, and the new regression test, all of which are present as described. No description defect found. _The code index is behind this pull request (indexed at `b12f71ab4b21`), so retrieved context may be out of date._
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash
  • Spend: $0.000633
  • Tokens: 263064 input · 4499 output · 37888 cached · 233 embedding
  • Updated: 2026-10-23T08:03:32Z
Head State Pass summary
8b0c16ffb0ec ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-22T23:42:46Z)
4506d3f2c257 ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-23T08:03:32Z)

tinysweeper 0.1.2

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper found nothing blocking. Approving.

Diagnostics

Total spend: $0.0007

@tinysweeper tinysweeper Bot added the priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. label Oct 22, 2026
…ng it

cache::commit removes whatever is at the cache directory before renaming
the staging directory over it. When another process filled and verified
the same release while this one downloaded, that removed a directory the
sibling may have its module mapped from. acquire_cached now looks at the
cache once more before committing and keeps a fill that already verifies.
@M3gA-Mind
M3gA-Mind force-pushed the fix/module-cache-keep-concurrent-fill branch from 8b0c16f to 4506d3f Compare October 23, 2026 08:02
@M3gA-Mind
M3gA-Mind merged commit ed637c2 into tinyhumansai:main Oct 23, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant