Title: fix(db): reconcile folders stranded by old pods during the cutover drain by waleedlatif1 · Pull Request #6049 · simstudioai/sim · GitHub
Open Graph Title: fix(db): reconcile folders stranded by old pods during the cutover drain by waleedlatif1 · Pull Request #6049 · simstudioai/sim
X Title: fix(db): reconcile folders stranded by old pods during the cutover drain by waleedlatif1 · Pull Request #6049 · simstudioai/sim
Description: Adds 0275, the post-drain reconcile for the generic-folder cutover shipped in #6045. Why this exists 0272 and 0274 both ran while the previous app version was still serving. During the blue/green window the old pods write the legacy folder tables exclusively while the new pods write folder exclusively, so any folder an old pod creates between the migration and its own termination lives only in the legacy table and is invisible to the new code. 0274's header asked to be run again once the deploy drained. A journaled migration never replays, so that re-run has to be its own file. This is it. The stranding window did materialize in production — measured live at 06:52Z, mid-drain: rows to insert workflow_folder 1 (archived, no parent, no workflows inside) workspace_file_folders 0 The single stranded row has no user impact — it was created and archived within 100ms by canary traffic. The count at execution time may be higher, since old pods were still serving when that was taken. Covers both trees, where 0274 covered only file. The workflow side is the higher-volume one and is where the stranded row actually landed. Design Insert-only for ids missing from folder, never a mirror upsert. 0274 could upsert every column because file folders can never diverge in name — workspace_file_folders enforces the same active-unique key folder does. That does not hold here: 0272's dedup renamed 47 workflow folders across 35 collision groups, so folder is deliberately different from workflow_folder for those rows. An upsert would revert all 47 to their colliding names and violate folder_workspace_resource_parent_name_active_unique in the process. First free suffix, not a row number. The target name may already be held by a row this block is not inserting, so the dedup probes upward until it finds a genuinely free name. Only active rows dedupe. The partial unique index ignores soft-deleted rows, so an archived folder keeps its original name and reappears under it if restored. Depth-ordered inserts. A parent always lands before its children — the self-referencing FK is checked immediately and the folder_parent_resource_type_match trigger reads the parent row, so a child inserted first fails both. Wrapped in a DO block, for the same reason 0274 is: 0272 ends with an embedded COMMIT for its trailing CONCURRENTLY index builds, so files after it are not guaranteed to run inside drizzle's batch transaction. Verification Executed the actual migration file against Postgres 17 with adversarial fixtures. Every case a naive implementation gets wrong: Fixture Expected Result Row 0272 renamed to Reports (2) untouched ✅ not reverted Stranded active Reports, with Reports (2) already taken Reports (3) ✅ Stranded archived row with colliding name keeps Reports ✅ no suffix Fully-stranded 3-level chain parents insert first ✅ Stranded child colliding with a sibling dedupes within parent ✅ Nested (2) Same name in another workspace untouched ✅ File Reports vs workflow Reports independent ✅ resource_type scoped Idempotency: three consecutive runs, byte-identical state. bun run check:migrations passes. Operational note — this has a deadline Run before the soft-delete cleanup job purges expired folder rows. Cleanup hard-deletes from folder but never from the legacy tables, so a run landing after a purge would reinstate every purged folder as a soft-deleted phantom in Recently Deleted whose files and workflows are already gone. The retention window is far longer than any drain, so shipping promptly is sufficient — but this is the one constraint that makes deferring it indefinitely dangerous rather than merely redundant. Not in this PR — dropping the legacy tables Deliberately held. Verified for a future contract PR, but not acted on: Application code is already fully clean — zero reads, zero writes, zero dual-read fallbacks to either legacy table. The reader-removal precondition is satisfied by #6045, which is deployed. Structurally the drop is trivial: the only inbound FKs are self-references. Nothing else in the database depends on either table. Full-row comparison (not just counts) is clean on both trees: 1,495/1,495 file rows match on every column; the workflow side shows zero parent drift, with the only material difference being the one stranded row. What is not satisfied is rollback posture. The tables are the only rollback path, KB/Tables folders have hours of production exposure with no meaningful user traffic yet, and schema.ts carries a binding policy that dropping on the strength of "no code references it" alone destroys that path. They cost essentially nothing to keep. That call belongs to the repo owner once the new folder trees have seen real usage. ⚠️ For whoever writes that drop PR: do not let any script glob workflow_folder* when dropping indexes. workflow_folder_sort_idx is an index on the live workflow table, not on the legacy folder table. It looks obviously safe in review and is not.
Open Graph Description: Adds 0275, the post-drain reconcile for the generic-folder cutover shipped in #6045. Why this exists 0272 and 0274 both ran while the previous app version was still serving. During the blue/green w...
X Description: Adds 0275, the post-drain reconcile for the generic-folder cutover shipped in #6045. Why this exists 0272 and 0274 both ran while the previous app version was still serving. During the blue/green w...
Opengraph URL: https://github.com/simstudioai/sim/pull/6049
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:8edc1c74-97d9-faa5-d668-44862f965bdf |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A334:2F3575:59B9A4:80BBF4:6AFB4353 |
| html-safe-nonce | cbf2519f6afc31949a1f91d57bdba3c1bdd5b86476e2090a371e25e40d9e8290 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzM0OjJGMzU3NTo1OUI5QTQ6ODBCQkY0OjZBRkI0MzUzIiwidmlzaXRvcl9pZCI6Ijc4NTg3NDI5Mjc3NTI3MzI5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 17d39bf2cb9553517d9559454c04c38af573506cd372ffd9a2099a7c1fb9a73c |
| hovercard-subject-tag | pull_request:4157940802 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6049/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Adds 0275, the post-drain reconcile for the generic-folder cutover shipped in #6045. Why this exists 0272 and 0274 both ran while the previous app version was still serving. During the blue/green w... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d849b928f455c800985398e7f1b659425adb312a5fa14fba5d9a14e62e9fe5dd |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a6c2f87cbcb6414452377b4967858ed6a66f1109 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width