🐛 Bug Report: Adding or removing files on a source works once, then is silently skipped for 24 hours
📜 Description
After one file operation on a source (file tree → add files, delete a file, or delete a folder), every further add/remove on the same source within the next 24 hours is reported as successful, but it never reaches the index:
POST /api/manage_source_filesanswers200 {"success": true, "reingest_task_id": ...}- the reingest task finishes
SUCCESSimmediately and returns the previous operation's cached result - an added file is stored but never parsed or embedded, so search and answers never see it
- a removed file is deleted from storage, but its chunks stay retrievable and the file tree still lists it
- the file tree waits for a
source.ingest.completedevent that never comes, until its 5-minute timeout
Root cause
- The web UI sends no
Idempotency-Keytomanage_source_files(userService.ts#L314-L315). The route therefore dispatchesreingest_source_taskwithidempotency_key=None(upload.py#L900-L904; the same applies at L1012 and L1142). with_idempotencythen falls back to a synthesized key,auto:reingest_source_task:<source_id>(idempotency.py#L60, #L152-L161).- The helper's docstring assumes
source_idis "unique per upload". That holds foringest, but a source keeps the same id across all of its reingests. - After the first reingest completes,
_lookup_completed(idempotency.py#L64) returns the cached row forDEDUP_TTL_INTERVAL = "24 hours"(repositories/idempotency.py#L18). The worker body never runs.
The synthesized key came in with #2484 as a guard against poison loops on redelivery, which is still useful. It just shouldn't be keyed only on source_id for a task that legitimately runs many times per source.
Related: POST /api/sources/reingest dispatches with the fixed key reingest-source:<owner>:<source_id> (sources/routes.py#L559-L564). So after one completed reingest, the next reingest of that source within 24 hours also just returns the cached result. The comment there says the aim is that "repeated clicks collapse onto one reingest", which reads like de-duplicating concurrent clicks rather than disabling the action for a day.
👟 Reproduction steps
From the UI:
- Upload
alpha.mdas a new source and wait until it is ready. - Open the source's file tree and add
bravo.md. This one works. - Add
charlie.mdthe same way. - Ask about something that is only in
charlie.md. It is never found, and the file tree keeps waiting.
The same steps through the API (local auth, default settings, default FAISS store):
import requests, time
API = "http://127.0.0.1:7091"
def wait(task_id):
while True:
j = requests.get(f"{API}/api/task_status", params={"task_id": task_id}).json()
if j["status"] in ("SUCCESS", "FAILURE"):
return j
def doc(name):
return (f"{name}.md", f"The secret word for file {name} is {name.upper()}-MARK.".encode(), "text/markdown")
r = requests.post(f"{API}/api/upload", data={"user": "local", "name": "reingest-test"},
files={"file": doc("alpha")}).json()
sid = r["source_id"]; wait(r["task_id"])
for name in ("bravo", "charlie"): # no Idempotency-Key header, same as the web UI
r = requests.post(f"{API}/api/manage_source_files",
data={"source_id": sid, "operation": "add", "parent_dir": ""},
files={"file": doc(name)}).json()
print(name, wait(r["reingest_task_id"])["result"])
hits = requests.post(f"{API}/api/sources/{sid}/search", json={"query": "secret word for file"}).json()
print([c["filename"] for c in hits["chunks"]])
👍 Expected behavior
Each add/remove (and each Reingest click after the previous one has finished) re-ingests the source. Added files become retrievable, and removed files' chunks disappear. Only a duplicate dispatch of the same operation should be de-duplicated.
👎 Actual Behavior with Screenshots
Only the first operation is applied. The second one returns the first one's result:
bravo {'added_files': ['bravo.md'], 'chunks_added': 1, 'chunks_deleted': 0, 'removed_files': [], 'status': 'completed', ...}
charlie {'added_files': ['bravo.md'], 'chunks_added': 1, 'chunks_deleted': 0, 'removed_files': [], 'status': 'completed', ...} <- stale
['alpha.md', 'bravo.md'] <- charlie.md never indexed
The remove case behaves the same way: the second removal returns the cached result, the removed file is gone from disk, and its chunks are still returned by search.
If each request sends its own Idempotency-Key header, both operations run, which confirms the shared synthesized key is the cause.
💻 Operating system
Linux
What browsers are you seeing the problem on?
Not browser-specific: reproduced through the API. The web UI shows the same behaviour because it sends the same requests.
🤖 What development environment are you experiencing this bug on?
Local dev server: the ASGI API under uvicorn plus a Celery worker with beat, from main at c6877e5c. The arc53/docsgpt:develop image is built from the same commit, so the Docker setup runs this same code.
🔒 Environment variable names
POSTGRES_URI, CELERY_BROKER_URL, CELERY_RESULT_BACKEND, CACHE_REDIS_URL, INTERNAL_KEY, LLM_PROVIDER, API_KEY, LLM_NAME, OPENAI_BASE_URL, DOCSGPT_HOME. There are no vector-store or idempotency overrides.
📃 Additional context
Possible fix directions (open to maintainers' preference):
- Don't fall back to a per-source key for
reingest_source_task. Instead, give each file operation its own key, either minted by the route when the client sends none or derived from the operation itself. Keep the poison-loop guard per dispatch. - Have the frontend send an
Idempotency-Keyper user action formanage_source_files, asUpload.tsxalready does for uploads. - Scope the
/api/sources/reingestkey to in-flight duplicates only, for example with a short TTL or by including the source's current file-tree state.
Regression test idea: two sequential manage_source_files adds on one source, with no header, must both run the reingest worker body, and the second file must be retrievable. A control where each add sends a distinct Idempotency-Key already passes today.
No schema change is needed. Existing task_dedup rows with auto:reingest_source_task:* keys expire on their own within 24 hours.
📖 Relevant log output
INFO in idempotency: idempotency hit for task=reingest_source_task key=auto:reingest_source_task:13d37f99-216c-47fe-89d4-816c6d0bb19c — returning cached result
👀 Have you spent some time to check if this bug has been raised before?
- [x] I checked and didn't find similar issue
I searched open and closed issues and PRs for reingest, idempotency, Idempotency-Key, manage_source_files, task_dedup and "cached result", and found nothing that matches. Open PR #2919 touches chunking only.
🔗 Are you willing to submit PR?
Yes, I am willing to submit a PR!
🧑⚖️ Code of Conduct
- [x] I agree to follow this project's Code of Conduct
cc @dartpain @siiddhantt @pabik @ManishMadan2882 , Assign this issue to me :)
Hi @arc53 team! I would love to work on this issue for Hacktoberfest.
I've reviewed the issue description and identified the root cause:
manage_source_filesinuserService.tsdoes not send anIdempotency-Keyheader.- The backend route (
upload.py) falls back toidempotency_key=None, generating a staticauto:reingest_source_task:<source_id>key that gets cached for 24 hours underDEDUP_TTL_INTERVAL.
I can implement the fix by:
- Minting an
Idempotency-Keyin the frontend per file action (matchingUpload.tsx). - Adding a per-dispatch key fallback in
upload.pyto ensure legitimate subsequent file operations on the same source are not deduplicated.
Could you please assign this issue to me? Thank you!
@satanic47, you're assigned.
- Open a PR or post progress within 14 days; otherwise the issue may be reassigned.
- Read
CONTRIBUTING.md; for UI work, also readfrontend/DESIGN.md. - Include a screenshot or short recording of the change in your PR.
Automated triage. A maintainer will follow up.
Thanks @satanic47 , but I reproduced this bug and raised it here , So I Obviously plan to raise a PR as well for Hacktober fest and as per the rules and guidelines I am gonna wait for the maintainers approval and assign this issue to me :) @arc53-machine @ManishMadan2882 @dartpain @siiddhantt