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 — Revert "improvement(db): add session statement/lock timeouts; simplif… by TheodoreSpeaks · Pull Request #4599 · simstudioai/sim

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented May 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Forgot pg lock didn't work with pscale. Reverting.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Revert, no code changes

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)

Screenshots/Videos

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
@TheodoreSpeaks
Revert "improvement(db): add session statement/lock timeouts; simplif…
32d5dc4
…y KB doc tx (#4593)"

This reverts commit 4295a5c.
@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.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 14, 2026 5:19pm

Request Review

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
Changes transactional behavior around knowledge-base document creation and workspace archival, which can affect concurrency/locking and error modes under load. Also removes global Postgres timeout safeguards, potentially allowing longer-running or stuck queries.

Overview
Reverts the DB-level lock_timeout/statement_timeout configuration in packages/db/db.ts, removing the session-wide guardrails that cancelled long-running/blocked queries.

Reworks knowledge-base document creation (createDocumentRecords and createSingleDocument) to drop the atomic insertDocumentsIfKbAlive JSONB insert helper and instead run inside a transaction that SELECT ... FOR UPDATE locks the knowledge_base row, re-checks deleted_at, then inserts documents and updates knowledge_base.updated_at.

Removes the per-transaction SET LOCAL statement_timeout/lock_timeout overrides from workspace archival (archiveWorkspace) and updates the related lifecycle test mock accordingly.

Reviewed by Cursor Bugbot for commit 32d5dc4. 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 17:19
View deployment
@greptile-apps

greptile-apps Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR reverts the previous "improvement(db)" commit that added PostgreSQL-specific session-level lock_timeout/statement_timeout connection parameters, SET LOCAL timeout overrides inside transactions, and a jsonb_to_recordset-based atomic insert function — none of which are supported on pscale. It restores the prior approach of using db.transaction() with SELECT ... FOR UPDATE row locks.

  • packages/db/db.ts: Removes connection: { lock_timeout: 5000, statement_timeout: 30000 } from the postgres client config, which were PostgreSQL-only session params.
  • apps/sim/lib/workspaces/lifecycle.ts: Drops SET LOCAL statement_timeout and SET LOCAL lock_timeout from the workspace archival transaction.
  • apps/sim/lib/knowledge/documents/service.ts: Removes the insertDocumentsIfKbAlive helper (which used jsonb_to_recordset::jsonb and INSERT…SELECT…WHERE EXISTS) and reverts both createDocumentRecords and createSingleDocument to a transaction + FOR UPDATE pattern.

Confidence Score: 4/5

Safe to merge once the missing processingStatus field in createSingleDocument is confirmed to have a database-level default.

The revert is clean and consistent across all four files. The only uncertainty is whether the document.processing_status column carries a DB-level default of 'pending' — createSingleDocument no longer sets it explicitly while createDocumentRecords still does, and a missing default would cause every single-document insert to fail with a NOT NULL violation.

apps/sim/lib/knowledge/documents/service.ts — verify processing_status column default in the schema before merging.

Important Files Changed

Filename Overview
packages/db/db.ts Removes PostgreSQL-specific connection: { lock_timeout, statement_timeout } session-level params that aren't supported on pscale; restores clean postgres client config.
apps/sim/lib/workspaces/lifecycle.ts Removes SET LOCAL statement_timeout and SET LOCAL lock_timeout calls inside the archive transaction; these are PostgreSQL-only and were causing failures on pscale.
apps/sim/lib/workspaces/lifecycle.test.ts Removes the execute: vi.fn() mock from the transaction stub, consistent with lifecycle.ts no longer calling tx.execute() after the SET LOCAL commands are removed.
apps/sim/lib/knowledge/documents/service.ts Reverts from insertDocumentsIfKbAlive (PostgreSQL-specific jsonb_to_recordset + INSERT...SELECT...WHERE EXISTS) back to db.transaction() with SELECT ... FOR UPDATE; createSingleDocument no longer explicitly sets processingStatus: 'pending' — relies on a DB-level default.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant service.ts
    participant DB as DB (transaction)

    Note over service.ts, DB: createDocumentRecords / createSingleDocument (reverted)

    Caller->>service.ts: createDocumentRecords(docs, kbId)
    service.ts->>DB: BEGIN TRANSACTION
    service.ts->>DB: "SELECT 1 FROM knowledge_base WHERE id=kbId FOR UPDATE"
    service.ts->>DB: "SELECT id FROM knowledge_base WHERE id=kbId AND deleted_at IS NULL"
    alt KB not found / soft-deleted
        DB-->>service.ts: []
        service.ts-->>Caller: throw Error("Knowledge base not found")
    else KB alive
        service.ts->>DB: INSERT INTO document VALUES (...)
        service.ts->>DB: "UPDATE knowledge_base SET updated_at=now"
        DB-->>service.ts: COMMIT
        service.ts-->>Caller: DocumentData[]
    end
Loading

Reviews (1): Last reviewed commit: "Revert "improvement(db): add session sta..." | 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
Comment on lines 1300 to 1313
@@ -1430,21 +1307,31 @@ export async function createSingleDocument(
chunkCount: 0,
tokenCount: 0,
characterCount: 0,
processingStatus: 'pending',
enabled: true,
uploadedAt: now,
...processedTags,
}

@greptile-apps greptile-apps Bot May 14, 2026

Copy link
Copy Markdown
Contributor

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.

P1 Missing processingStatus in createSingleDocument

createDocumentRecords explicitly sets processingStatus: 'pending' as const, but createSingleDocument no longer does after this revert — ...processedTags only carries tag/number/date/boolean fields. If the document table column lacks a DEFAULT 'pending' at the DB level, every single-document insert will fail with a NOT NULL violation. Worth verifying the schema default exists, or restoring the explicit field here for symmetry.

Sorry, something went wrong.

Uh oh!

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

All reactions
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 32d5dc4. 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
}

const newDocument: NewDocumentRow = {
const newDocument = {

@cursor cursor Bot May 14, 2026

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.

Missing processingStatus in single document creation path

Low Severity

The createSingleDocument function no longer sets processingStatus: 'pending' in its newDocument object (lines 1300–1313), while the bulk createDocumentRecords path still explicitly includes processingStatus: 'pending' as const (line 816). The database column has a DEFAULT 'pending' so the insert succeeds, but the two code paths are now inconsistent — and the object returned to API callers from the single-document path will be missing the processingStatus property in the JSON response.

Additional Locations (1)
  • apps/sim/lib/knowledge/documents/service.ts#L805-L836
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 32d5dc4. Configure here.

Sorry, something went wrong.

Uh oh!

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

All reactions

@TheodoreSpeaks TheodoreSpeaks May 14, 2026

Copy link
Copy Markdown
Contributor Author

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.

Lets do a full revert ill follow up after.

Sorry, something went wrong.

Uh oh!

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

All reactions
@TheodoreSpeaks
TheodoreSpeaks merged commit b1a87d5 into staging May 14, 2026
14 checks passed

Uh oh!

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

@TheodoreSpeaks
TheodoreSpeaks deleted the revert/pg-lock branch May 14, 2026 17:42
@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 successfully deployed

1 active deployment
Preview — 32d5dc46 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.

1 participant

@TheodoreSpeaks
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.