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-profiling | 0 |
| react-import-map | react,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-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ef7087e8-c2c4-bf84-1735-0c8fb8d3096d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AE78:2D7CAE:5B95BB:82425A:6AFB4320 |
| html-safe-nonce | 7473b77c4a5f0cf719434a14d76bc456e8a1bc29984efc845c41941f156677f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTc4OjJEN0NBRTo1Qjk1QkI6ODI0MjVBOjZBRkI0MzIwIiwidmlzaXRvcl9pZCI6IjQxNzUwNTAyNjg5OTcyNzIzNTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fa180fc44cc7d5df3a0f5feed57a055763f6a18e8823ff1e1360ac417dfe0b9c |
| hovercard-subject-tag | pull_request:4265086400 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | ///pull_requests/show/files |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6636/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | 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... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d849b928f455c800985398e7f1b659425adb312a5fa14fba5d9a14e62e9fe5dd |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a6c2f87cbcb6414452377b4967858ed6a66f1109 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Skip to content | https://github.com/simstudioai/sim/pull/6636/files#start-of-content |
| https://github.com/ |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6636%2Ffiles |
| GitHubRepository hosting, code review, and collaboration | https://github.com/platform |
| CopilotAI coding agent for tasks, projects, and automated work | https://github.com/features/copilot |
| ActionsCI/CD and automation | https://github.com/features/actions |
| Code QualityQuality analysis, fixes, and enforcement | https://github.com/features/code-quality |
| CodespacesCloud development environments | https://github.com/features/codespaces |
| Code SecurityVulnerability detection and remediation | https://github.com/security/advanced-security/code-security |
| Secret ProtectionSecret scanning and leak prevention | https://github.com/security/advanced-security/secret-protection |
| All Features | https://github.com/features |
| Documentation | https://docs.github.com/en |
| Training | https://learn.github.com/skills |
| Certifications | https://learn.github.com/credentials |
| Build with Copilot | https://github.com/features/ai |
| Customize Copilot | https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview |
| Integrations | https://github.com/marketplace |
| Trending repos | https://github.com/trending |
| GitHub Sponsors | https://github.com/open-source/sponsors |
| Developer articles | https://github.com/resources/articles |
| ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place. | https://github.blog/changelog/ |
| Enterprises | https://github.com/enterprise |
| Team | https://github.com/team |
| Startups | https://github.com/enterprise/startups |
| Nonprofits | https://github.com/solutions/industry/nonprofits |
| Healthcare | https://github.com/solutions/industry/healthcare |
| Financial services | https://github.com/solutions/industry/financial-services |
| Manufacturing | https://github.com/solutions/industry/manufacturing |
| Government | https://github.com/solutions/industry/government |
| See all industries | https://github.com/solutions/industry |
| Why GitHub | https://github.com/why-github |
| Customer Stories | https://github.com/customer-stories |
| Business insights | https://github.com/solutions/executive-insights |
| Trust Center | https://github.com/trust-center |
| GitHub Advanced SecurityEnterprise-grade code security | https://github.com/security/advanced-security |
| Copilot for businessEnterprise-grade AI features | https://github.com/features/copilot/copilot-business |
| Premium SupportEnterprise-grade 24/7 support | https://github.com/enterprise/premium-support |
| Documentation | https://docs.github.com/en |
| Resource center | https://github.com/resources |
| Blog | https://github.blog/ |
| Events & webinars | https://github.com/resources/events |
| Community Forum | https://github.com/orgs/community/discussions |
| Customer Stories | https://github.com/customer-stories |
| Integrations | https://github.com/marketplace |
| Customer support | https://help.github.com/ |
| Training | https://learn.github.com/skills |
| GitHub Status | https://www.githubstatus.com/ |
| About | https://github.com/about |
| Partners | https://github.com/partners |
| Changelog | https://github.blog/changelog/ |
| GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub. | https://githubuniverse.com/ |
| Pricing | https://github.com/pricing |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F6636%2Ffiles |
| Sign up | https://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 |
| Reload | https://github.com/simstudioai/sim/pull/6636/files |
| Reload | https://github.com/simstudioai/sim/pull/6636/files |
| Reload | https://github.com/simstudioai/sim/pull/6636/files |
| simstudioai | https://github.com/simstudioai |
| sim | https://github.com/simstudioai/sim |
| Code | https://github.com/simstudioai/sim |
| Issues129 (129) | https://github.com/simstudioai/sim/issues |
| Pull requests200 (200) | https://github.com/simstudioai/sim/pulls |
| Actions | https://github.com/simstudioai/sim/actions |
| Projects | https://github.com/simstudioai/sim/projects |
| Security and quality | https://github.com/simstudioai/sim/security |
| Insights | https://github.com/simstudioai/sim/pulse |
| Sign up for GitHub
| https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose |
| terms of service | https://docs.github.com/terms |
| privacy statement | https://docs.github.com/privacy |
| Sign in | https://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose |
| waleedlatif1 | https://github.com/waleedlatif1 |
| staging | https://github.com/simstudioai/sim/tree/staging |
| fix/v2-keyset-timestamp-cursor | https://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 page | https://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 page | https://github.com/simstudioai/sim/pull/6636/files |
| Please reload this page | https://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.md | https://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.md | https://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.md | https://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.ts | https://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 page | https://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 page | https://github.com/simstudioai/sim/pull/6636/files |
| Please reload this page | https://github.com/simstudioai/sim/pull/6636/files |
|
| https://github.com |
| Terms | https://docs.github.com/site-policy/github-terms/github-terms-of-service |
| Privacy | https://docs.github.com/site-policy/privacy-policies/github-privacy-statement |
| Security | https://github.com/security |
| Status | https://www.githubstatus.com/ |
| Community | https://github.community/ |
| Docs | https://docs.github.com/ |
| Contact | https://support.github.com?tags=dotcom-footer |
Viewport: width=device-width
URLs of crawlers that visited me.