Files
sim/apps
Waleed ce32993c76 fix(knowledge): fix chunk_index race and storage-quota check/increment race (#5544)
* fix(knowledge): fix chunk_index race and storage-quota check/increment race

- createChunk now serializes concurrent writes to the same document via a
  transactional advisory lock before computing the next chunk_index, fixing
  the unique-constraint collision behind the ITSM 'Failed to create chunk'
  incident (two overlapping workflow runs appending to the same shared KB
  document).
- Document uploads now check and increment storage quota atomically in a
  single conditional UPDATE inside the insert transaction, instead of
  check-then-insert-then-increment-after-commit, closing the window where
  two concurrent uploads could both pass the quota check and over-commit
  storage.

* fix(knowledge): bound the chunk advisory-lock wait with lock_timeout

Address Greptile P1: the advisory lock in createChunk could wait
indefinitely on a stalled same-document transaction while holding a pooled
connection. Set a 5s lock_timeout before acquiring it, matching the
set_config + pg_advisory_xact_lock pattern already used by every other
advisory lock in this codebase (org membership, table schema/row-ordering,
BYOK keys, workspace env, usage-log flush, execution-log reconciliation).
2026-07-09 14:54:46 -07:00
..