improvement(db): add session statement/lock timeouts; simplify KB doc tx#4593
Conversation
…ership workflow edits via sockets, ui improvements
…ng improvements, posthog, secrets mutations
…ration, signup method feature flags, SSO improvements
…nts, secrets performance, polling refactors, drag resources in mothership
…y invalidation, HITL docs
…endar triggers, docs updates, integrations/models pages improvements
…ions, jira forms endpoints
…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)
v0.6.46: mothership streaming fixes, brightdata integration
…m integration, atlassian triggers
…rizations, mothership positional table row insertion, CI improvements, org-external users, file viewer improvements
v0.6.62: fix new copilot chat creation and selection on refresh
…ixes, db query optimizations, contract boundaries code hygiene, CORS, toast improvements, tables infinite query, executor robustness, reranker support
…tion blocks/connectors updates
…ogs block, parallel-in-loop wall clock, gpt-image-2
…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
…ering upgrades, data drains, security hardening, paginated dropdowns
…ntegrations, robots.txt update, workday hardening
v0.6.72: billing pool contention fix
…personation fixes, md rendering, doc/pdf/pptx generation improvements
…pentelemetry updates, data drains to snowflake, blob, datadog, bigquery
…ip md polish v0.6.75: scheduler claim-budget drain, helm chart hardening, mothership md polish
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
| 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
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- 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.
PR SummaryMedium Risk Overview Updates workspace archival to Simplifies knowledge-base document creation ( Reviewed by Cursor Bugbot for commit 0ad209f. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR adds server-side
Confidence Score: 4/5The 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
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]
Reviews (2): Last reviewed commit: "fix(knowledge): close soft-delete TOCTOU..." | Re-trigger Greptile |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
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.
|
@greptile review |

Summary
lock_timeout=5s/statement_timeout=30ssession defaults viaconnection: {...}startup params inpackages/db/db.ts. Converts silent pool wedges into loud server-side cancellations.SET LOCAL statement_timeout='5min'andlock_timeout='30s'— rare admin op stays atomic without tripping the new global default.db.transaction+SELECT 1 ... FOR UPDATEwrapper. Because KB delete is soft (deletedAt = now) the FK alone can't guard a concurrent delete, so the newinsertDocumentsIfKbAlivehelper does the existence check and the insert in a single statement viaINSERT...SELECT...WHERE EXISTSoverjsonb_to_recordset. Atomic at the MVCC snapshot — race-free, no transaction, no row lock. Side effect: removes aprocessDocumentTags-uses-db-inside-txdeadlock surface.Type of Change
Testing
Tested manually.
bun run lintclean.bun run check:api-validation:strictpasses. Vitest: workspace lifecycle 2/2, billing 29/29, knowledge 49/49, webhook trigger 17/17.Checklist