René's URL Explorer Experiment


Title: fix(knowledge): stop the stuck-document sweep reclaiming still-queued documents by waleedlatif1 · Pull Request #6921 · simstudioai/sim · GitHub

Open Graph Title: fix(knowledge): stop the stuck-document sweep reclaiming still-queued documents by waleedlatif1 · Pull Request #6921 · simstudioai/sim

X Title: fix(knowledge): stop the stuck-document sweep reclaiming still-queued documents by waleedlatif1 · Pull Request #6921 · simstudioai/sim

Description: Live on staging now. Introduced by the interaction between #6920 and a pre-existing gap in the stuck-document sweep — each is fine alone. The bug The sweep gives 'processing' a staleness cutoff but gives 'pending' and 'failed' none at all. The only cross-run guard is uploadedAt < syncStartedAt, which scopes within a sync but not across syncs. That was harmless while processDocumentsWithQueue awaited every document inline — documents were terminal by the time a sync ended. Since #6920 made dispatch asynchronous they sit 'pending' until a worker picks them up, and processingStatus only flips to 'processing' when the worker starts. So the next sync sees merely-queued documents, deletes their embeddings, resets them, and re-dispatches while the original runs may still be executing. Each re-dispatch mints a fresh pass id, so it bills again — directly undercutting #6911. Very reachable: document-processing-queue has a global concurrency of 20, so a large connector drains slowly, and syncIntervalMinutes is validated at min(0). The signal No column records dispatch time — document has only uploadedAt, processingStartedAt, processingCompletedAt. So queued age is processingStartedAt ?? uploadedAt: First dispatch: uploadedAt is the proxy. Its error is bounded and one-directional — dispatch happens later in the same sync — so it over-estimates the wait by at most the 1h sync ceiling. Re-dispatch: uploadedAt is arbitrarily old and useless, so the sweep now stamps processingStartedAt when it re-dispatches. Without this only a document's first dispatch was protected and the sweep churned once per sync forever on anything that kept waiting — the same bug, one layer down. User-triggered retry (retryDocumentProcessing) previously set the column to null and dispatched, leaving a connector document with an old uploadedAt sweepable by the very next sync. It now stamps the requeue time. The overload is safe: every reader of processingStartedAt gates on processingStatus === 'processing' first, and processDocumentAsync claims with an unconditional update — it never requires the column to be null — so a stamped pending row is claimed exactly as a nulled one was. processing-outbox-handler.ts deliberately unchanged: the outbox is the upload path only, so those documents have connectorId = null and the connector-scoped sweep can never see them. Its null write is also load-bearing there as the CAS token invalidating a dead worker. The grace period: 240 minutes Derived from queue drain time, not run duration — the existing STALE_PROCESSING_MINUTES = 45 bounds a run (600s × 3 attempts), which is a different quantity. Concurrency is 20, global across all workspaces (verified on the task definition; no concurrencyKey exists anywhere in the document dispatch path). The largest documented corpus — 2,600 documents — is 130 waves, roughly two hours to drain, longer when other tenants hold slots. 240 is ~2× that and still well under the 1,440-minute default syncIntervalMinutes, so a default-configured connector gains zero recovery latency. 45 would still reclaim live documents on any corpus over ~900. Recovery is preserved — nothing was removed from the sweep, only delayed. A dispatch lost to a crash is swept by the first sync starting more than 240 minutes after it was queued; RETRY_WINDOW_DAYS = 7 still bounds it from above. A 'processing' document abandoned mid-run is unaffected at 45 minutes, and a user can retry a 'failed' document immediately. 'failed' deliberately gets no grace: it is terminal, so re-dispatch cannot duplicate live work, and it is the state the user-facing retry operates from. Structure The SQL now selects a coarse, index-friendly superset and the age decision moves to isStuckDocumentSweepEligible, a pure exported function. That matters for testability — this file's tests mock drizzle-orm to bare vi.fn()s, so a SQL-shape assertion would prove nothing. Verification type-check clean · check:audits 32/32 · 567 tests across lib/knowledge. Nine mutations, all red. The flagship — making 'pending' unconditionally sweepable, i.e. exactly today's staging behavior — turns four tests red, including the requested "dispatched by the previous sync and still queued". The new retry-processing-grace.test.ts calls the real retryDocumentProcessing, captures its actual .set() payload, and feeds it into the real predicate, so the linkage between the two files is executed rather than asserted by review. Known limitations, stated plainly The grace narrows the duplicate-billing window; it cannot close it. A re-dispatch mints a new request id and the Trigger idempotency key is doc-process-{documentId}-{requestId} — scoped per dispatch by design, so cross-sync duplicates are never deduped. Closing it durably needs a document-scoped key or a dispatch-generation column the worker checks before billing. Recorded in TSDoc, deliberately not built here. Two load-bearing pieces have no test coverage, by choice: the processingStartedAt stamp in the sweep's own reset, and the widened SQL predicate. Both live inside executeSync, for which no harness exists; building one means standing up the whole db/transaction/registry stack. The retry-path equivalent of that stamp is covered, which is the closest available proxy — same column, same fallback, same predicate. If connector documents are ever routed through the outbox, the assumption above breaks and the same stamp is needed in processing-claim.ts.

Open Graph Description: Live on staging now. Introduced by the interaction between #6920 and a pre-existing gap in the stuck-document sweep — each is fine alone. The bug The sweep gives 'processing' a staleness cu...

X Description: Live on staging now. Introduced by the interaction between #6920 and a pre-existing gap in the stuck-document sweep — each is fine alone. The bug The sweep gives &#39;processing&#39; a stal...

Opengraph URL: https://github.com/simstudioai/sim/pull/6921

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:814689a4-8691-9fae-5504-1a63da3071ef
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA478:2E4CE1:7250E8:A01AB0:6AFB67FC
html-safe-noncef4f85fa84ae63027d1b6d803a9a689289aeb154766ceba7ac71c5f8b45891553
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDc4OjJFNENFMTo3MjUwRTg6QTAxQUIwOjZBRkI2N0ZDIiwidmlzaXRvcl9pZCI6IjMyMDI3MjYxMzQ4MjI5NTUwMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac455bcbd1ad012835031a57368f5a2ef87434cfcd467037b5e64c4e3d2c9affc4
hovercard-subject-tagpull_request:4327894537
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6921/files
twitter:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
og:image:altLive on staging now. Introduced by the interaction between #6920 and a pre-existing gap in the stuck-document sweep — each is fine alone. The bug The sweep gives 'processing' a staleness cu...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release59ef97164c52cf59bd10558ddec9c4f482763988
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/6921/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6921%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6921%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/pull/6921/files
Reloadhttps://github.com/simstudioai/sim/pull/6921/files
Reloadhttps://github.com/simstudioai/sim/pull/6921/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests197 (197)https://github.com/simstudioai/sim/pulls
Actionshttps://github.com/simstudioai/sim/actions
Projectshttps://github.com/simstudioai/sim/projects
Security and qualityhttps://github.com/simstudioai/sim/security
Insightshttps://github.com/simstudioai/sim/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
waleedlatif1https://github.com/waleedlatif1
staginghttps://github.com/simstudioai/sim/tree/staging
fix/sweep-pendinghttps://github.com/simstudioai/sim/tree/fix/sweep-pending
Conversation 12 https://github.com/simstudioai/sim/pull/6921
Commits 3 https://github.com/simstudioai/sim/pull/6921/commits
Checks 28 https://github.com/simstudioai/sim/pull/6921/checks
Files changed https://github.com/simstudioai/sim/pull/6921/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6921/files
fix(knowledge): stop the stuck-document sweep reclaiming still-queued documents https://github.com/simstudioai/sim/pull/6921/files#top
Show all changes 3 commits https://github.com/simstudioai/sim/pull/6921/files
b5947fe fix(knowledge): stop the stuck-document sweep reclaiming still-queued… waleedlatif1 Aug 21, 2026 https://github.com/simstudioai/sim/pull/6921/commits/b5947fe00c6e70a09e5847db215732d945314b37
f2438d7 fix(knowledge): record dispatch time in its own column instead of ove… waleedlatif1 Aug 21, 2026 https://github.com/simstudioai/sim/pull/6921/commits/f2438d7aff6413f264d84cb37d4a6c61721b81b1
4f98807 fix(knowledge): stamp the queue time in the dispatch funnel, not at e… waleedlatif1 Aug 21, 2026 https://github.com/simstudioai/sim/pull/6921/commits/4f98807fa0fdec87b8d7d95c3efb2283713124e2
Clear filters https://github.com/simstudioai/sim/pull/6921/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6921/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6921/files
documents.ts https://github.com/simstudioai/sim/pull/6921/files#diff-5fc1dd43e7e48f04aac58010b417d279c66b714c91f3960831d5276725495645
internal-route.ts https://github.com/simstudioai/sim/pull/6921/files#diff-11a77429c36a02382ed7c10785326d4be20acfbb8ccbd3ae4b1f4f90e265e940
sync-engine.test.ts https://github.com/simstudioai/sim/pull/6921/files#diff-021afebf7e100833ecdc940e307263436964ce85ef3dfd40fc90307a1d115534
sync-engine.ts https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
retry-processing-grace.test.ts https://github.com/simstudioai/sim/pull/6921/files#diff-24e9b3a40786dff73fbb7dc3d959893039829339609677b1b55c06fd4f2ccddd
service.ts https://github.com/simstudioai/sim/pull/6921/files#diff-12adff6ec055d413ec20f1debed4ca207b994d23df6de9aa4ef79bf47f2857b2
0297_eminent_sinister_six.sql https://github.com/simstudioai/sim/pull/6921/files#diff-05dced6a5653d04f77866c2c592d2c32f1792a3d615211e984ab0e2e2fc1ac45
0297_snapshot.json https://github.com/simstudioai/sim/pull/6921/files#diff-4777bd83ba3020327998feea0714235dfc0e1ed5dfdd8122044cd60fa8198d53
_journal.json https://github.com/simstudioai/sim/pull/6921/files#diff-37150cc65ad16ee6fbc5fa318fc096be7730e16d63eaf863e3df5521b7030649
schema.ts https://github.com/simstudioai/sim/pull/6921/files#diff-9a959e2ce3cb4c86957bbae021d06eae364f7b0cb18964f5873bab53220af928
schema.mock.ts https://github.com/simstudioai/sim/pull/6921/files#diff-3b648ee44a059e5fc069169fdfd7c32c89200a3e79b5d0dc25227d3470da73af
apps/sim/lib/api/contracts/knowledge/documents.tshttps://github.com/simstudioai/sim/pull/6921/files#diff-5fc1dd43e7e48f04aac58010b417d279c66b714c91f3960831d5276725495645
View file https://github.com/simstudioai/sim/blob/4f98807fa0fdec87b8d7d95c3efb2283713124e2/apps/sim/lib/api/contracts/knowledge/documents.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6921/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6921/files#diff-5fc1dd43e7e48f04aac58010b417d279c66b714c91f3960831d5276725495645
https://github.com/simstudioai/sim/pull/6921/files#diff-5fc1dd43e7e48f04aac58010b417d279c66b714c91f3960831d5276725495645
apps/sim/lib/knowledge/api/internal-route.tshttps://github.com/simstudioai/sim/pull/6921/files#diff-11a77429c36a02382ed7c10785326d4be20acfbb8ccbd3ae4b1f4f90e265e940
View file https://github.com/simstudioai/sim/blob/4f98807fa0fdec87b8d7d95c3efb2283713124e2/apps/sim/lib/knowledge/api/internal-route.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6921/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6921/files#diff-11a77429c36a02382ed7c10785326d4be20acfbb8ccbd3ae4b1f4f90e265e940
https://github.com/simstudioai/sim/pull/6921/files#diff-11a77429c36a02382ed7c10785326d4be20acfbb8ccbd3ae4b1f4f90e265e940
https://github.com/simstudioai/sim/pull/6921/files#diff-11a77429c36a02382ed7c10785326d4be20acfbb8ccbd3ae4b1f4f90e265e940
apps/sim/lib/knowledge/connectors/sync-engine.test.tshttps://github.com/simstudioai/sim/pull/6921/files#diff-021afebf7e100833ecdc940e307263436964ce85ef3dfd40fc90307a1d115534
View file https://github.com/simstudioai/sim/blob/4f98807fa0fdec87b8d7d95c3efb2283713124e2/apps/sim/lib/knowledge/connectors/sync-engine.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6921/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6921/files#diff-021afebf7e100833ecdc940e307263436964ce85ef3dfd40fc90307a1d115534
https://github.com/simstudioai/sim/pull/6921/files#diff-021afebf7e100833ecdc940e307263436964ce85ef3dfd40fc90307a1d115534
https://github.com/simstudioai/sim/pull/6921/files#diff-021afebf7e100833ecdc940e307263436964ce85ef3dfd40fc90307a1d115534
apps/sim/lib/knowledge/connectors/sync-engine.tshttps://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
View file https://github.com/simstudioai/sim/blob/4f98807fa0fdec87b8d7d95c3efb2283713124e2/apps/sim/lib/knowledge/connectors/sync-engine.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6921/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
Please reload this pagehttps://github.com/simstudioai/sim/pull/6921/files
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
https://github.com/simstudioai/sim/pull/6921/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
Please reload this pagehttps://github.com/simstudioai/sim/pull/6921/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6921/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.