From 3d607a1f66e4a2cf0e4ae76892b24eb308dbe973 Mon Sep 17 00:00:00 2001 From: "linear-code[bot]" <222613912+linear-code[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:13:51 -0500 Subject: [PATCH] docs: Capture prevention lessons from weekly merge review (#14819) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com> --- AGENTS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index bd8cde3822..032e8e2346 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -127,6 +127,7 @@ yarn sequelize migration:create --name=add-field-to-table - Use transactions for multi-table operations. - Add appropriate indexes for query performance. - Always handle database errors gracefully. +- When independent Sequelize filters constrain the same field, intersect them with `Op.and` instead of overwriting operators. Test combined caller filters return only records satisfying every condition. - When updating Sequelize array or JSON attributes, replace the value instead of mutating it in place; reload the model in tests to verify persistence rather than trusting its in-memory state. - Schedule optional background work that depends on a transaction from `afterCommit`, and use non-fatal scheduling so a queue failure does not fail the committed operation. - When changing persisted task input fields, keep readers compatible with queued inputs or migrate them before removing old fields. @@ -143,6 +144,7 @@ yarn sequelize migration:create --name=add-field-to-table - Validate request data using the validation middleware and schemas - Use presenters to format API responses. - Keep API routes thin, use model methods for business logic, or commands if logic spans multiple models. +- After loading a document or collection from a slug-accepting parameter, use the loaded model's `id` for subsequent queries and writes. Test slug input succeeds and persisted foreign keys and response IDs contain the canonical UUID. - MCP tools that call commands directly must preserve REST cross-field validation before any mutation. For document edits, reject nonempty `findText` in default or explicit replace mode, require nonempty text for append/prepend, and require nonempty `findText` plus defined text for patch while allowing empty replacement text for deletion. Test invalid combinations leave title, content, and revision unchanged. ## Authentication & Authorization @@ -161,6 +163,8 @@ yarn sequelize migration:create --name=add-field-to-table - WebSocket connections for real-time updates. - Use Y.js for collaborative editing. - Handle connection state changes gracefully. +- In editor mouse handlers, normalize targets with `getEventTargetElement` before calling element methods. Verify Firefox Text node targets retain the interaction, and detached text nodes or missing targets are handled safely. +- When replacing document content on the server, normalize with `withTrailingNode` and update existing collaborative state with `DocumentHelper.applyToState`. Read state under a row lock held through the save to serialize with first-editor initialization. Reload and decode persisted state to verify the replacement and trailing paragraph, including concurrent initialization. - For bulk deletions that drive authorization or WebSocket processing, load affected models in the transaction and delete each with request context so downstream processors receive the expected per-item events. - Do not persist viewer-specific unfurls in shared document mentions; only store unfurls that map to a stable mention type. - When persisting pasted attachment URLs, use `signedUrlToAttachmentUrl` to convert this instance’s signed URLs to stable attachment redirects. Cover HTML, Markdown, and single-URL pastes, including pasting over selected text; document nodes and link marks must not retain expiring local URLs, and external URLs must remain unchanged. @@ -226,6 +230,8 @@ yarn test:shared # All shared code tests - Use `Redis.ephemeralClient` for request-path caches, rate limits, and locks, including lock extension and release. - Monitor performance with appropriate tools. - Lazy load routes and components where appropriate. +- For archive exports, stream attachments with `AttachmentHelper.addToArchive` and pass the client disconnect signal. Recheck cancellation after asynchronous stream acquisition, destroy abandoned streams, and forward input errors to the archive. Test cancellation during acquisition destroys the stream; HTML images selected for inlining still use bounded buffering. +- Keep Markdown token transforms linear with output arrays or stack passes instead of repeated `splice` calls or full-stream scans per item. Verify nested and surrounding content is preserved and check scaling with large tables and checklists. ## Security