GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — improvement(db): add session statement/lock timeouts; simplify KB doc tx by TheodoreSpeaks · Pull Request #4593 · simstudioai/sim

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented May 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

  • Add server-side lock_timeout=5s / statement_timeout=30s session defaults via connection: {...} startup params in packages/db/db.ts. Converts silent pool wedges into loud server-side cancellations.
  • Workspace archival tx keeps its own ceiling via SET LOCAL statement_timeout='5min' and lock_timeout='30s' — rare admin op stays atomic without tripping the new global default.
  • KB document creation (bulk + single) drops the db.transaction + SELECT 1 ... FOR UPDATE wrapper. Because KB delete is soft (deletedAt = now) the FK alone can't guard a concurrent delete, so the new insertDocumentsIfKbAlive helper does the existence check and the insert in a single statement via INSERT...SELECT...WHERE EXISTS over jsonb_to_recordset. Atomic at the MVCC snapshot — race-free, no transaction, no row lock. Side effect: removes a processDocumentTags-uses-db-inside-tx deadlock surface.

Type of Change

  • Bug fix

Testing

Tested manually. bun run lint clean. bun run check:api-validation:strict passes. Vitest: workspace lifecycle 2/2, billing 29/29, knowledge 49/49, webhook trigger 17/17.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
waleedlatif1 and others added 30 commits April 3, 2026 23:30
@waleedlatif1
v0.6.23: MCP fixes, remove local state in favor of server state, moth…
0b9019d
…ership workflow edits via sockets, ui improvements
@waleedlatif1
v0.6.24: copilot feedback wiring, captcha fixes
a54dcbe
@waleedlatif1
v0.6.25: cloudwatch, cloudformation, live kb sync, linear fixes, post…
28af223
…hog upgrade
@waleedlatif1
v0.6.26: ui improvements, multiple response blocks, docx previews, ol…
d889f32
…lama fix
@waleedlatif1
v0.6.27: new triggers, mothership improvements, files archive, queuei…
316bc8c
…ng improvements, posthog, secrets mutations
@waleedlatif1
v0.6.28: new docs, delete confirmation standardization, dagster integ…
3f508e4
…ration, signup method feature flags, SSO improvements
@TheodoreSpeaks
v0.6.29: login improvements, posthog telemetry (#4026)
d6ec115
* feat(posthog): Add tracking on mothership abort (#4023)

Co-authored-by: Theodore Li <[email protected]>

* fix(login): fix captcha headers for manual login  (#4025)

* fix(signup): fix turnstile key loading

* fix(login): fix captcha header passing

* Catch user already exists, remove login form captcha
@waleedlatif1
v0.6.30: slack trigger enhancements, connectors performance improveme…
d7da35b
…nts, secrets performance, polling refactors, drag resources in mothership
@waleedlatif1
v0.6.31: elevenlabs voice, trigger.dev fixes, cloud whitelabeling for…
cf233bb
… enterprises
@waleedlatif1
v0.6.32: BYOK fixes, ui improvements, cloudwatch tools, jsm tools ext…
f8f3758
…ension
@waleedlatif1
v0.6.33: polling improvements, jsm forms tools, credentials reactquer…
3c8bb40
…y invalidation, HITL docs
@waleedlatif1
v0.6.34: trigger.dev fixes, CI speedup, atlassian error extractor
d33acf4
@waleedlatif1
v0.6.35: additional jira fields, HITL docs, logs cleanup efficiency
4f40c4c
@waleedlatif1
v0.6.36: new chunkers, sockets state machine, google sheets/drive/cal…
cbfab1c
…endar triggers, docs updates, integrations/models pages improvements
@waleedlatif1
v0.6.37: audit logs page, isolated-vm worker rotation, permission gro…
4309d06
…ups ui
@waleedlatif1
v0.6.38: models page
8b57476
@waleedlatif1
v0.6.39: billing fixes, tools audit, landing fix
e3d0e74
@waleedlatif1
v0.6.40: mothership tool loop, new skills, agiloft, STS, IAM integrat…
0ac0539
…ions, jira forms endpoints
@waleedlatif1
v0.6.41: webhooks fix, workers removal
3838b6e
@waleedlatif1
v0.6.42: mothership nested file reads, search modal improvements
fc07922
@waleedlatif1
v0.6.43: mothership billing idempotency, env var resolution fixes
3a1b1a8
@waleedlatif1
v0.6.44: streamdown, mothership intelligence, excel extension
46ffc49
@Sg312
v0.6.45: superagent, csp, brightdata integration, gemini response for…
010435c
…mat, logs performance improvements

fix(csp): add missing analytics domains, remove unsafe-eval, fix workspace CSP gap (#4179)
fix(landing): return 404 for invalid dynamic route slugs (#4182)
improvement(seo): optimize sitemaps, robots.txt, and core web vitals across sim and docs (#4170)
fix(gemini): support structured output with tools on Gemini 3 models (#4184)
feat(brightdata): add Bright Data integration with 8 tools (#4183)
fix(mothership): fix superagent credentials (#4185)
fix(logs): close sidebar when selected log disappears from filtered list; cleanup (#4186)
@icecrasher321
Merge pull request #4190 from simstudioai/staging
c0bc62c
v0.6.46: mothership streaming fixes, brightdata integration
@waleedlatif1
v0.6.46: mothership queueing, web vitals
387cc97
@waleedlatif1
v0.6.47: files focusing, documentation, opus 4.7
2dbc7fd
@waleedlatif1
v0.6.48: import csv into tables, subflow fixes, CSP updates
8a50f18
@waleedlatif1
v0.6.49: deploy sockets event, resolver, logs improvements, monday.co…
dcf3302
…m integration, atlassian triggers
@icecrasher321
v0.6.50: ppt/doc/pdf worker isolation, docs, chat, sidebar improvements
bc09865
@waleedlatif1
v0.6.51: tables improvements, billing fixes, 404 pages, code hygiene
5f56e46
waleedlatif1 and others added 16 commits May 2, 2026 09:30
@waleedlatif1
v0.6.63: knowledgebase UI, folder search in mothership
d445b9c
@waleedlatif1
v0.6.64: table limits env vars, workspace files improvements, integra…
4bc6a17
…tion blocks/connectors updates
@waleedlatif1
v0.6.65: memory fix, image uploads in files
5be12f8
@waleedlatif1
v0.6.66: child trace spans, reranker controls, attachment previews, l…
4253e57
…ogs block, parallel-in-loop wall clock, gpt-image-2
@TheodoreSpeaks
v0.6.67: VFS upload fix, posthog/copilot correlation, exa date filter…
8d6b615
…s, logs panel width, tables UI/DB decoupling

v0.6.67: VFS upload fix, posthog/copilot correlation, exa date filters, logs panel width, tables UI/DB decoupling
@waleedlatif1
v0.6.68: atlassian service accounts, 30 day wait block, markdown rend…
efcd51a
…ering upgrades, data drains, security hardening, paginated dropdowns
@waleedlatif1
v0.6.69: security hardening, nextjs upgrade, SAP Concur, Emailbison i…
8d934f3
…ntegrations, robots.txt update, workday hardening
@icecrasher321
v0.6.70: legacy workflow sanitization
5ea80a8
@icecrasher321
v0.6.71: build error fix
3cc581e
@TheodoreSpeaks
Merge pull request #4496 from simstudioai/staging
273e608
v0.6.72: billing pool contention fix
@waleedlatif1
v0.6.72: tables improvements, search and replace, logs with files, im…
07b8f1b
…personation fixes, md rendering, doc/pdf/pptx generation improvements
@icecrasher321
v0.6.73: zustand v5 migration fix
dcaf3e9
@waleedlatif1
v0.6.74: security hardening, workers recycling, next-mdx-remote and o…
6aeb981
…pentelemetry updates, data drains to snowflake, blob, datadog, bigquery
@TheodoreSpeaks
v0.6.75: scheduler claim-budget drain, helm chart hardening, mothersh…
3e9849b
…ip md polish

v0.6.75: scheduler claim-budget drain, helm chart hardening, mothership md polish
@waleedlatif1
v0.6.76: helm updates, media centering, lazy loading, security hardening
64d855a
@TheodoreSpeaks
improvement(db): add session statement/lock timeouts; simplify KB doc tx
0ad209f
@vercel

vercel Bot commented May 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 14, 2026 4:24pm

Request Review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gitguardian

gitguardian Bot commented May 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
29606901 Triggered Generic High Entropy Secret a54dcbe apps/sim/providers/utils.test.ts View secret
32763747 Triggered Generic Password 3e9849b helm/sim/tests/validators_test.yaml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider

  • following these best practices for managing and storing secrets including API keys and other credentials
  • install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.

🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cursor

cursor Bot commented May 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

PR Summary

Medium Risk
Introduces global Postgres lock_timeout/statement_timeout defaults, which can cause previously-long or lock-waiting queries to start failing and needs validation in production workloads. Also changes knowledge-base document creation semantics by removing a transaction/lock, so knowledge_base.updatedAt is no longer updated atomically with the insert.

Overview
Adds default Postgres session guards in packages/db/db.ts (lock_timeout=5s, statement_timeout=30s) so lock waits and long-running queries fail fast instead of wedging connections.

Updates workspace archival to SET LOCAL higher per-transaction timeouts (5min statement, 30s lock) to keep this rare, large operation reliable under the new global defaults.

Simplifies knowledge-base document creation (createDocumentRecords, createSingleDocument) by dropping the explicit transaction and SELECT ... FOR UPDATE lock, relying on FK constraints/atomic inserts and reducing deadlock/pool checkout overhead.

Reviewed by Cursor Bugbot for commit 0ad209f. Bugbot is set up for automated code reviews on this repo. Configure here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot deployed to Preview May 14, 2026 02:50
View deployment
@greptile-apps

greptile-apps Bot commented May 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds server-side lock_timeout=5s and statement_timeout=30s session defaults to the postgres.js connection pool, converting silent long-running query hangs into loud server-side cancellations. It also refactors KB document creation to use a single INSERT...SELECT...WHERE EXISTS statement rather than an explicit transaction with a row-level lock, and overrides the new shorter defaults in the workspace archival transaction with SET LOCAL.

  • packages/db/db.ts: Adds connection: { lock_timeout: 5_000, statement_timeout: 30_000 } so every connection in the pool inherits these session-level guards at connection startup.
  • apps/sim/lib/workspaces/lifecycle.ts: Prepends SET LOCAL overrides at the start of the archival transaction so the 30s default doesn't abort legitimate large-workspace cleanup operations.
  • apps/sim/lib/knowledge/documents/service.ts: Replaces the explicit db.transaction + SELECT ... FOR UPDATE pattern with a new insertDocumentsIfKbAlive helper that does the existence check and insert atomically in one SQL statement via INSERT...SELECT...WHERE EXISTS.

Confidence Score: 4/5

The timeout and lock changes are safe; open questions remain around the KB document creation path that were raised in previous review threads.

The db.ts and lifecycle.ts changes are straightforward and mechanically correct — session timeouts are set at startup, and the archival transaction correctly overrides them with SET LOCAL before any DML. The insertDocumentsIfKbAlive helper is a genuine improvement for combining the soft-delete guard and insert into one SQL statement. The two open issues from prior review threads (the soft-delete race window at READ COMMITTED isolation and the non-atomic updatedAt update) are still present in this revision and would benefit from being addressed before merging to a production path.

apps/sim/lib/knowledge/documents/service.ts — the document creation path still has the two open concerns from prior review threads worth re-examining before merge.

Important Files Changed

Filename Overview
packages/db/db.ts Adds session-level lock_timeout (5s) and statement_timeout (30s) via postgres.js connection startup params; values are correct integer milliseconds accepted by PostgreSQL.
apps/sim/lib/workspaces/lifecycle.ts Adds SET LOCAL statement_timeout='5min' and SET LOCAL lock_timeout='30s' at the top of the archival transaction to correctly override session defaults for this rare, long-running admin operation.
apps/sim/lib/knowledge/documents/service.ts Introduces insertDocumentsIfKbAlive using INSERT…SELECT…WHERE EXISTS to combine the soft-delete guard and insert into one statement; the updatedAt update remains outside any transaction (as flagged in existing review threads).
apps/sim/lib/workspaces/lifecycle.test.ts Adds execute: vi.fn().mockResolvedValue([]) to the transaction mock to handle the two new SET LOCAL calls; change is correct and minimal.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[createDocumentRecords / createSingleDocument] --> B{Upfront KB check\ndb.select WHERE deletedAt IS NULL}
    B -- KB not found --> C[throw 'Knowledge base not found']
    B -- KB alive --> D[Process tag data\nprocessDocumentTags]
    D --> E[Build NewDocumentRow array]
    E --> F[insertDocumentsIfKbAlive\nINSERT...SELECT...WHERE EXISTS\ndeleted_at IS NULL]
    F -- 0 rows returned\nKB soft-deleted in window --> G[throw 'Knowledge base not found']
    F -- N rows returned --> H[Log success]
    H --> I[db.update knowledgeBase\nset updatedAt - separate statement]
    I --> J[Return document data]
Loading

Reviews (2): Last reviewed commit: "fix(knowledge): close soft-delete TOCTOU..." | Re-trigger Greptile

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot]
greptile-apps Bot reviewed May 14, 2026
View reviewed changes
Comment thread apps/sim/lib/knowledge/documents/service.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread apps/sim/lib/knowledge/documents/service.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed May 14, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0ad209f. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread apps/sim/lib/knowledge/documents/service.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@TheodoreSpeaks
fix(knowledge): close soft-delete TOCTOU on KB document insert
512e887
Fix the race the bots flagged: KB delete is soft (`deletedAt = now`) so
the FK can't catch a concurrent KB delete between the existence check
and the document insert.

- Add `insertDocumentsIfKbAlive` helper that gates the insert on
  `EXISTS(SELECT 1 FROM knowledge_base WHERE id=$kb AND deleted_at IS NULL)`
  in the same statement via INSERT...SELECT...WHERE EXISTS. Atomic at the
  MVCC snapshot — no transaction, no row lock.
- Use jsonb_to_recordset to declare column types once, avoiding per-param
  casts for nullable columns.
- Wire into both `createDocumentRecords` (bulk) and `createSingleDocument`.
- Keep the upfront KB existence check as a fast-path early-out for the
  common case; the atomic insert is the race guard.
@vercel
vercel Bot temporarily deployed to Preview May 14, 2026 16:24 Inactive
@TheodoreSpeaks

TheodoreSpeaks commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TheodoreSpeaks
TheodoreSpeaks merged commit 4295a5c into staging May 14, 2026
13 of 14 checks passed

Uh oh!

There was an error while loading. Please reload this page.

TheodoreSpeaks added a commit that referenced this pull request May 14, 2026
@TheodoreSpeaks
Revert "improvement(db): add session statement/lock timeouts; simplif…
b1a87d5
…y KB doc tx (#4593)" (#4599)

This reverts commit 4295a5c.
@waleedlatif1
waleedlatif1 deleted the fix/threshold-billing-pool-deadlock branch May 14, 2026 18:57
@waleedlatif1 waleedlatif1 mentioned this pull request May 15, 2026
v0.6.80: security hardening, nextjs minor version bump, cloudwatch tools, seo fixes #4608
Merged

This branch was previously deployed

1 inactive deployment
Preview — 512e8870 Deployed May 14, 2026 by vercel[bot]
View deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@greptile-apps greptile-apps[bot] greptile-apps[bot] left review comments
@cursor cursor[bot] cursor[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@TheodoreSpeaks @waleedlatif1 @Sg312 @icecrasher321
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.