You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(files): open the agent-stream shadow lazily on lead (no stale handoff)
Greptile round 6 (P1): the leader race — (a) a mid-stream leadership handoff
could apply from a stale pre-stream shadow, and (b) two tabs starting the same
stream before awareness converges could both lead briefly.
- (a) fixed: the shadow is now opened LAZILY in the tick, only when this client
actually leads, seeded from the CURRENT doc — so a handoff successor diffs
against the prior leader's ops (never a stale base) and a non-leader builds no
shadow at all. Announce candidacy via a dedicated ref (decoupled from the
shadow); settle still gates the final apply on didApplyStreamRef (leader-only).
- (b) the pure startup race is inherent to eventually-consistent election. It is
now the only residual: bounded to two tabs starting the SAME stream within the
awareness-propagation window, transient (converges in a frame or two), and
never persisted (SYNC_NO_PERSIST + the durable edit_content reconcile). Resumes
are sequential, so the common multi-tab case elects cleanly. Documented inline;
a server-granted lease would close it fully but at a round-trip cost on the
common single-tab path, which isn't worth it.
Copy file name to clipboardExpand all lines: apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-editor.tsx
+31-22Lines changed: 31 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -399,6 +399,8 @@ export function LoadedRichMarkdownEditor({
399
399
* durable write instead. Reset on settle.
400
400
*/
401
401
constdidApplyStreamRef=useRef(false)
402
+
/** True once this client has announced candidacy in the agent-stream election for the current stream. */
403
+
constagentAnnouncedRef=useRef(false)
402
404
constrouter=useRouter()
403
405
constrouterRef=useRef(router)
404
406
routerRef.current=router
@@ -886,16 +888,15 @@ export function LoadedRichMarkdownEditor({
886
888
// re-runs and applies once it lands (the read-only placeholder shows the base content meanwhile —
887
889
// see `showPlaceholder`).
888
890
if(!collabReady)return
889
-
// Open the stream's shadow on the FIRST ready frame so it captures the pre-stream base (immune to
890
-
// later peer edits) — including for an `update`, whose frames are all held until settle, so settle
891
-
// still has a shadow through which to apply the final rewrite. Announce candidacy in the
892
-
// single-writer election so only one tab/window actually applies this stream (see the tick).
0 commit comments