Title: fix(mothership): number recovered turns past an unreadable ring and floor the replay TTL by waleedlatif1 · Pull Request #8501 · simstudioai/sim · GitHub
Open Graph Title: fix(mothership): number recovered turns past an unreadable ring and floor the replay TTL by waleedlatif1 · Pull Request #8501 · simstudioai/sim
X Title: fix(mothership): number recovered turns past an unreadable ring and floor the replay TTL by waleedlatif1 · Pull Request #8501 · simstudioai/sim
Description: Summary This PR fixes two Chat stream-recovery findings from the release review. Neither one is a regression against the current release, and neither blocks it. 1. A recovered turn can number its events at 0 over an unreadable ring (recover-stream.ts) Release-review finding: a recovery whose readEvents comes back empty resumes numbering at 0, even though the stream's seq counter has survived. Root cause. readEvents skips any ring entry that fails envelope parsing. If every retained entry is unreadable, events is empty. startsAtReplayHead(undefined) is true, so the code took the "ring intact" branch with resumeSeq = events.at(-1)?.seq ?? 0 = 0. The writer then numbers new events from 1. The append script ZADDs them next to the old scores and SETs the counter, which moves it backwards (N → k). A live tail whose cursor sits between the old and new numbering can then silently skip new events. The empty-events path predates the lost-head branch added in #8469; prod has the same behaviour. Fix. Use the recovered event's seq only when an event was actually recovered. Otherwise resume from the stream's counter (getLatestSeq), which still falls back to 0 when the key is missing. The lost-head branch already took this path. The controller still starts from an empty context and re-attaches with an empty receipt, so nothing else changes. 2. A configured replay TTL below the heartbeat lets an idle live buffer expire (buffer.ts) Release-review finding: the 20 s chat-lock heartbeat refreshes the live buffer's TTL, but COPILOT_STREAM_TTL_SECONDS accepted any value of 1 s or more. Root cause. With a TTL under about 20 s, a run that goes quiet loses its events and seq keys between refreshes. The refresh only calls EXPIRE, so it cannot bring them back. The default (3600 s) is unaffected, and nothing in the repo sets the variable. Fix. getStreamConfig floors the configured live TTL at 60 s, which is three heartbeats. The default and every value of 60 s or more behave as before. The completed-stream TTL is unchanged. Behaviour changes A recovery with no readable ring events numbers new events after the stream's counter instead of from 1. Readers use zrangebyscore, so the gap is harmless. COPILOT_STREAM_TTL_SECONDS values below 60 now act as 60. Not changed Both findings are real. Neither one was rejected. A broader variant, max(lastRecoveredSeq, counter), would also cover a corrupt tail behind a readable head. I left it out: the finding was the empty-ring case, and that variant adds a Redis read to every recovery for a case that needs corrupt data mid-ring. Test plan stream-recovery.integration.ts: new case, a ring whose entries are all unreadable recovers with new events numbered after the counter (min seq 5). Fails on the pre-fix code. buffer-ttl.integration.ts: new case, a live buffer under a 5 s configured TTL gets at least 60 s. Fails on the pre-fix code. The existing park test now shortens the event and seq keys' TTLs explicitly, since the floor no longer lets the env do it. Both new tests checked red with the fix reverted and green with it applied (bun run test:integration buffer-ttl.integration.ts stream-recovery.integration.ts, disposable Postgres/Redis). recover-stream.test.ts and the session/ unit tests pass. bun run lint, bun run type-check (apps/sim), bun run check:audits pass. Full bun run test:integration (left to CI).
Open Graph Description: Summary This PR fixes two Chat stream-recovery findings from the release review. Neither one is a regression against the current release, and neither blocks it. 1. A recovered turn can number its e...
X Description: Summary This PR fixes two Chat stream-recovery findings from the release review. Neither one is a regression against the current release, and neither blocks it. 1. A recovered turn can number its e...
Opengraph URL: https://github.com/simstudioai/sim/pull/8501
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:66784a47-c1dd-3926-b978-bee0f703d93c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DD9C:196274:32A2F1:4572DF:6AFB95F8 |
| html-safe-nonce | 15a5008e8bb10f74f63411ae5ca286a56c72ac31717cce3003187aaf31cae374 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDlDOjE5NjI3NDozMkEyRjE6NDU3MkRGOjZBRkI5NUY4IiwidmlzaXRvcl9pZCI6IjYyODYxMjgzMDEwMjI2MTUwMzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 415f5c4863331d9a5bc4e7b838c59314d1c6e00f4566e88db9ce90a963fe91fb |
| hovercard-subject-tag | pull_request:4698036072 |
| 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/8501/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 | Summary This PR fixes two Chat stream-recovery findings from the release review. Neither one is a regression against the current release, and neither blocks it. 1. A recovered turn can number its e... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4f01efe06174a5ba6342fd58e42d02295e0675bedbb465d6bef2dbaec8e46556 |
| 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 | a52db8866b6543b4e83730cd6a6b1360f1a9e4dc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width