Skip to content

use a key to dedupe reqs#10

Open
swelborn wants to merge 1 commit into
exit-code-anyiofrom
key-not-transfer-id
Open

use a key to dedupe reqs#10
swelborn wants to merge 1 commit into
exit-code-anyiofrom
key-not-transfer-id

Conversation

@swelborn

@swelborn swelborn commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

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:

Copilot AI 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.

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_id with a nullable, unique key field on the Cache table/model for dedup/lookup.
  • Update POST /caches to return an existing active cache for the same key (200) and handle races by joining the “winner”.
  • Clear cache.key on 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 thread src/fastcache_api/tables.py
Comment thread src/fastcache_api/routes/cache.py Outdated
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 thread src/fastcache_api/routes/cache.py Outdated
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants