René's URL Explorer Experiment


Title: fix(v2): give the keyset cursor's timestamp an explicit SQL type by waleedlatif1 · Pull Request #6636 · simstudioai/sim · GitHub

Open Graph Title: fix(v2): give the keyset cursor's timestamp an explicit SQL type by waleedlatif1 · Pull Request #6636 · simstudioai/sim

X Title: fix(v2): give the keyset cursor's timestamp an explicit SQL type by waleedlatif1 · Pull Request #6636 · simstudioai/sim

Description: The defect Every v2 collection hands back a nextCursor. Passing that cursor straight back returned 500 INTERNAL_ERROR on every list whose sort includes a timestamp key — which is the default sort on five of them. The keyset compares millisecond-truncated timestamps on both sides: date_trunc('milliseconds', "created_at") > date_trunc('milliseconds', $n) $n went out as a bare placeholder, which Postgres types as unknown. date_trunc is overloaded across timestamp, timestamptz, and interval, so date_trunc(unknown, unknown) matches no single candidate and the statement fails with function date_trunc(unknown, unknown) is not unique. The cursor value was never unvalidated — a non-string or unparseable date is already rejected as a 400 by KeysetKey.bind. It simply reached SQL with no type. The old TSDoc claimed sql.param(date, column) bound it "through the column so drizzle's own timestamp encoder serializes it"; the encoder does run, but drizzle still emits an untyped $n, and nothing about a placeholder tells Postgres what it is. The file's own unit test asserted the untyped form and passed. Not a regression from the recent v2 work git log -S"date_trunc" -- apps/sim/lib/api/list-query.ts, and the same for sql.param(date, column), both point at a single commit: #5273, the original v2 PR. v2 keyset pagination has never worked past page one on a timestamp-sorted list. #6620 made it reachable and uniform — it gave four previously-unpaginated collections working cursors — which is how it surfaced, but it did not introduce it. The fix Cast the bound value to the column's own SQL type, inside timestampKey, so all twelve call sites across six modules inherit it rather than each patching itself: sql`date_trunc('milliseconds', cast(${sql.param(date, column)} as ${sql.raw(column.getSQLType())}))` Derived from the column rather than hardcoded timestamp: every column reaching this today is timestamp without time zone, but a timestamptz column would need its Z offset honoured rather than ignored, and the derivation keeps that correct for free. It is read inside bind rather than at construction because every caller builds its sort map at module scope. The millisecond truncation is unchanged. It is load-bearing: Postgres stores microseconds, a cursor value round-trips through a millisecond-only JS Date, and comparing the raw column against the truncated value re-admits the page's own last row. Verified against a real database that a row stored at …568999 is still correctly excluded by a cursor stamped …568. Affected sorts Every keyset containing a timestamp key — 7 collections, 15 sorts. Default sorts in bold. Collection Broken Unaffected workflows position, createdAt, updatedAt name, runCount tables createdAt, updatedAt name files uploadedAt, updatedAt name, size credentials createdAt, updatedAt displayName secrets (shares the credentials keyset) createdAt, updatedAt name knowledge createdAt, updatedAt name custom-tools createdAt, updatedAt title Not affected at all: logs, skills, billing-logs, mcp-servers, audit-logs — none of them build a keyset over a truncated timestamp. numberKey and textKey carry no equivalent exposure. Their bound values only ever sit as one side of a comparison against a typed column or expression (sort_order > $1, coalesce(size_bytes, size) > $1), where Postgres infers the type from the comparison. date_trunc is the only place a keyset passes a bound value into a function — which is exactly why this stayed invisible everywhere else. I swept every sql.param( call site and every SQL-function call with an interpolated operand across apps/ and packages/. The others either already carry an explicit cast by hand (::jsonb, ::text, ::vector — seven sites, each author having hit the same wall independently) or are single-candidate and resolve fine (websearch_to_tsquery(regconfig, text), lower, make_interval). This was the only live instance. Verification Reproduced against a real Postgres 17.9 before the fix, rendering the actual keysetAfter SQL through PgDialect and executing it: 4 of 5 sort shapes failed with function date_trunc(unknown, unknown) is not unique; the name (text-key) control passed. After the fix, 5/5 pass and return the correct rows, including the microsecond-truncation case above. New unit tests fail before the fix and pass after. Three added/changed: the cast is emitted; the cast is taken from the column (a timestamptz fixture renders cast($1 as timestamp with time zone)); and a class guard asserting no bound value is left bare inside any function call, so a future key that wraps its value is caught. bun run type-check, bunx turbo run lint:check, bun run check:api-validation:strict, bun run check:openapi all pass. lib/api suites: 723 tests green; the six modules that call timestampKey plus their dependents: 4,470 green. Skill .agents/skills/v2-api-conventions/SKILL.md states "500 is never caller-reachable" and keeps an incident log against it. This class is added, along with the generalisation it produces — if a bound value is an argument to a SQL function rather than one side of a comparison, write its type down — and the reason it survived review: the generated SQL was well-formed and every assertion passed, so only a database could reject it. Projections regenerated with scripts/sync-skills.ts. Note for a follow-up (not in this PR) lib/data-drains/sources/cursor.ts (timeCursorPredicate) applies date_trunc('milliseconds', …) to the column but not to the bound cursor value. It does not hit this bug — a row-constructor comparison types the parameter from the left-hand element — but that asymmetry is the same one timestampKey's TSDoc argues re-admits the page's own last row. Worth a look separately.

Open Graph Description: The defect Every v2 collection hands back a nextCursor. Passing that cursor straight back returned 500 INTERNAL_ERROR on every list whose sort includes a timestamp key — which is the default sort o...

X Description: The defect Every v2 collection hands back a nextCursor. Passing that cursor straight back returned 500 INTERNAL_ERROR on every list whose sort includes a timestamp key — which is the default sort o...

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

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:ef7087e8-c2c4-bf84-1735-0c8fb8d3096d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAE78:2D7CAE:5B95BB:82425A:6AFB4320
html-safe-nonce7473b77c4a5f0cf719434a14d76bc456e8a1bc29984efc845c41941f156677f6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTc4OjJEN0NBRTo1Qjk1QkI6ODI0MjVBOjZBRkI0MzIwIiwidmlzaXRvcl9pZCI6IjQxNzUwNTAyNjg5OTcyNzIzNTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacfa180fc44cc7d5df3a0f5feed57a055763f6a18e8823ff1e1360ac417dfe0b9c
hovercard-subject-tagpull_request:4265086400
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/6636/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:altThe defect Every v2 collection hands back a nextCursor. Passing that cursor straight back returned 500 INTERNAL_ERROR on every list whose sort includes a timestamp key — which is the default sort o...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noned849b928f455c800985398e7f1b659425adb312a5fa14fba5d9a14e62e9fe5dd
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
releasea6c2f87cbcb6414452377b4967858ed6a66f1109
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/6636/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6636%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%2F6636%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/6636/files
Reloadhttps://github.com/simstudioai/sim/pull/6636/files
Reloadhttps://github.com/simstudioai/sim/pull/6636/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests200 (200)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/v2-keyset-timestamp-cursorhttps://github.com/simstudioai/sim/tree/fix/v2-keyset-timestamp-cursor
Conversation 8 https://github.com/simstudioai/sim/pull/6636
Commits 1 https://github.com/simstudioai/sim/pull/6636/commits
Checks 30 https://github.com/simstudioai/sim/pull/6636/checks
Files changed https://github.com/simstudioai/sim/pull/6636/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6636/files
fix(v2): give the keyset cursor's timestamp an explicit SQL type https://github.com/simstudioai/sim/pull/6636/files#top
Show all changes 1 commit https://github.com/simstudioai/sim/pull/6636/files
f27c7d6 fix(v2): give the keyset cursor's timestamp an explicit SQL type waleedlatif1 Aug 12, 2026 https://github.com/simstudioai/sim/pull/6636/commits/f27c7d6efc627965970736f89b98333c053823c7
Clear filters https://github.com/simstudioai/sim/pull/6636/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6636/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6636/files
SKILL.md https://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
v2-api-conventions.md https://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
v2-api-conventions.md https://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
list-query.test.ts https://github.com/simstudioai/sim/pull/6636/files#diff-7d121e037e1d7fac4e3631eb92560fad2ef131450d8a6cfe7a6f456040ac70ef
list-query.ts https://github.com/simstudioai/sim/pull/6636/files#diff-32aecd996eadcd96f7be5ec1b731ed5e4221e4d9114ed295dbaa5f5fb13648f0
.agents/skills/v2-api-conventions/SKILL.mdhttps://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
View file https://github.com/simstudioai/sim/blob/f27c7d6efc627965970736f89b98333c053823c7/.agents/skills/v2-api-conventions/SKILL.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6636/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
https://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
https://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
https://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
https://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
https://github.com/simstudioai/sim/pull/6636/files#diff-8ece2aa9a15122239fc217eb94d684ef57b385916b95bed160ad4b424543edc5
.claude/commands/v2-api-conventions.mdhttps://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
View file https://github.com/simstudioai/sim/blob/f27c7d6efc627965970736f89b98333c053823c7/.claude/commands/v2-api-conventions.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6636/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
https://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
https://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
https://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
https://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
https://github.com/simstudioai/sim/pull/6636/files#diff-34b6597331f2a9dd49c38118ef0f0555424f9f0c762ce33549141e71f9c470c4
.cursor/commands/v2-api-conventions.mdhttps://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
View file https://github.com/simstudioai/sim/blob/f27c7d6efc627965970736f89b98333c053823c7/.cursor/commands/v2-api-conventions.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6636/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
https://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
https://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
https://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
https://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
https://github.com/simstudioai/sim/pull/6636/files#diff-dc6f94499025928e979e62a01a870f67c12a2ce9e0622b4dcb33310eb23b968e
apps/sim/lib/api/list-query.test.tshttps://github.com/simstudioai/sim/pull/6636/files#diff-7d121e037e1d7fac4e3631eb92560fad2ef131450d8a6cfe7a6f456040ac70ef
View file https://github.com/simstudioai/sim/blob/f27c7d6efc627965970736f89b98333c053823c7/apps/sim/lib/api/list-query.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/6636/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/6636/files#diff-7d121e037e1d7fac4e3631eb92560fad2ef131450d8a6cfe7a6f456040ac70ef
Please reload this pagehttps://github.com/simstudioai/sim/pull/6636/files
https://github.com/simstudioai/sim/pull/6636/files#diff-7d121e037e1d7fac4e3631eb92560fad2ef131450d8a6cfe7a6f456040ac70ef
https://github.com/simstudioai/sim/pull/6636/files#diff-7d121e037e1d7fac4e3631eb92560fad2ef131450d8a6cfe7a6f456040ac70ef
https://github.com/simstudioai/sim/pull/6636/files#diff-7d121e037e1d7fac4e3631eb92560fad2ef131450d8a6cfe7a6f456040ac70ef
Please reload this pagehttps://github.com/simstudioai/sim/pull/6636/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/6636/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.