fix(local): keep a rename or note edit made while a document ingests - #2148
Conversation
finish_job wrote back the title and content begin_job had read, so a file renamed during its parse got its upload name back, and a note edited mid-ingest got its old text written over the edit, which the re-ingest the edit queued then indexed. finish_job now writes only the status, the error and the columns its caller produced: ingest passes a file's extracted text and never a note's or a title; Studio passes the title and content it generated.
|
@Cedric921 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (4)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: MODSetter/SurfSense/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughIngest completion now updates only fields produced by the job. File ingestion supplies extracted Markdown, while note ingestion preserves user-written content. Studio generation supplies the document’s current title and content. Integration tests and architecture documentation cover edits during ingestion. ChangesIngest completion updates
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to This change keeps a rename or note edit made while a document is being ingested, instead of overwriting it with stale values. No merge-blocking risk was found. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change reduces concurrent-edit data loss while retaining cancellation controls. Search freshness still depends on follow-up ingestion, and recovery after an interruption is not fully established. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
finish_jobno longer writes back the rowbegin_jobread. It writes the terminalstatusanderror_message, plus only the columns its caller produced (**produced):worker/ingestion/pipeline.pypassescontent=markdownfor aFILEonly, and no longer assignsdocument.contenton the ORM object. A note's content is the user's and ingest only reads it; ingest never passestitle.worker/studio/job.pypasses thetitleandcontentthatpersist()just set.Why
Found in review of #2132. With
expire_on_commit=False, the copybegin_jobread was never refreshed, andfinish_jobwrote itstitleandcontentback:update_documenthas no processing guard, unlike delete, and greying out the controls would only narrow the window, so the fix is at the cause, as the review suggested.docs/architecture/documents.md: the ingest Finish step says what it writes and why an edit made meanwhile stands.Unblocks #2132.
How to test
tests/integration/worker/test_edits_during_ingest.pycommits an edit from a second session while the worker parses, asPATCHwould:pending) ends, after the ingest the edit queued, with the new text stored and indexed. The old text's words no longer match inchunks_fts.High-level PR Summary
This PR fixes a race condition where user edits (file renames or note content changes) made during document ingestion were being overwritten when the ingestion job completed. The fix modifies
finish_jobto only write back columns that the ingestion process actually produced, rather than writing back the entire row that was read at the start. For files, only the extracted markdown content is written; for notes, the user's content is preserved as it's never modified by ingestion. The change ensures that renames made right after upload (during parsing) and note edits made mid-ingest are both preserved.⏱️ Estimated Review Time: 15-30 minutes
💡 Review Order Suggestion
surfsense_local/backend/tests/integration/worker/test_edits_during_ingest.pysurfsense_local/backend/worker/jobs.pysurfsense_local/backend/worker/ingestion/pipeline.pysurfsense_local/backend/worker/studio/job.pydocs/architecture/documents.mdSummary by CodeRabbit