use a key to dedupe reqs#10
Open
swelborn wants to merge 1 commit into
Open
Conversation
This was referenced Jul 12, 2026
There was a problem hiding this comment.
Pull request overview
This PR changes cache request deduplication from a per-transfer identifier to a reusable “key” (e.g., experiment name) so concurrent/shared requests can join an existing active cache, and the key can be freed for reuse once the cache is torn down.
Changes:
- Replace
transfer_idwith a nullable, uniquekeyfield on theCachetable/model for dedup/lookup. - Update
POST /cachesto return an existing active cache for the same key (200) and handle races by joining the “winner”. - Clear
cache.keyon teardown/exit paths so the key can be reused.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/fastcache_api/tables.py | Replaces transfer_id with nullable unique key column and updates column semantics/doc. |
| src/fastcache_api/routes/cache.py | Adds key-based lookup/dedup in create route; updates persistence and shutdown behavior around key. |
| src/fastcache_api/reconcile.py | Frees key when caches are detected as exited and marked final. |
| src/fastcache_api/models.py | Updates request/response models to use key instead of transfer_id. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+43
to
+50
| async def _find_active_by_key(session: AsyncSession, key: str) -> Cache | None: | ||
| result = await session.execute( | ||
| select(Cache).where( | ||
| Cache.key == key, | ||
| Cache.state.in_([s.value for s in CacheState if not s.is_final()]), | ||
| ) | ||
| ) | ||
| return result.scalar_one_or_none() |
Comment on lines
+171
to
+172
| cache.state = CacheState.canceled | ||
| cache.key = None |
we use a key here instead of transfer ID. the main idea is that the transfer ID will always be unique. the experiment ID will be unchanged per request. If a cache is up and we req for an experiment (shared mode), then it will be OK. If we have a new id or we previously shut down the cache for this particular experiment, then the key is removed from the table and we can reuse it to start up another cache
swelborn
force-pushed
the
key-not-transfer-id
branch
from
July 12, 2026 21:51
e18cbdf to
979ca00
Compare
This was referenced Jul 12, 2026
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.
we use a key here instead of transfer ID. the main idea is that the transfer ID will always be unique. the experiment ID will be unchanged per request. If a cache is up and we req for an experiment (shared mode), then it will be OK. If we have a new id or we previously shut down the cache for this particular experiment, then the key is removed from the table and we can reuse it to start up another cache
This is part 6 of 10 in a stack made with GitButler: