detached b788892

fix(client): fall back after resume expiry (#237)

commit
b788892be7ee068d33e8120296559e760062b367
author
bnema · · 2026-08-29 08:29 UTC
committer
GitHub · · 2026-08-29 08:29 UTC
parent
ff4fca7
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
3 files · +64 -2
M docs/remote-resilience.md +4 -2
@@ -127,8 +127,10 @@ picker selection changes.
127127 canonical encoding. The protocol validates the compression kind, declared
128128 decoded length, stream integrity, and trailing bytes before terminal output
129129 is applied.
130-- The attachment reconnects with its resume token after a path change. The
131- remote session and its PTYs remain in place while the attachment is offline.
130+- The attachment reconnects with its resume token after a path change. If the
131+ attachment resume window expires but its exact session lifecycle still
132+ exists, the client opens a fresh exact attachment instead. The remote session
133+ and its PTYs remain in place while the attachment is offline.
132134
133135 The raw UDP AEAD key is held only in memory during bootstrap and transport
134136 setup. It is not written to durable state. Key buffers are cleared on the
@@ -127,8 +127,10 @@ picker selection changes.
127 canonical encoding. The protocol validates the compression kind, declared127 canonical encoding. The protocol validates the compression kind, declared
128 decoded length, stream integrity, and trailing bytes before terminal output128 decoded length, stream integrity, and trailing bytes before terminal output
129 is applied.129 is applied.
130-- The attachment reconnects with its resume token after a path change. The130+- The attachment reconnects with its resume token after a path change. If the
131- remote session and its PTYs remain in place while the attachment is offline.131+ attachment resume window expires but its exact session lifecycle still
132+ exists, the client opens a fresh exact attachment instead. The remote session
133+ and its PTYs remain in place while the attachment is offline.
132 134
133 The raw UDP AEAD key is held only in memory during bootstrap and transport135 The raw UDP AEAD key is held only in memory during bootstrap and transport
134 setup. It is not written to durable state. Key buffers are cleared on the136 setup. It is not written to durable state. Key buffers are cleared on the
M internal/usecase/client/client.go +8 -0
@@ -927,6 +927,14 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error)
927927 enterHomePicker()
928928 continue
929929 }
930+ if attemptRequest.Intent == protocol.IntentResume && !result.welcomed &&
931+ attemptRequest.ExactTarget != nil && resumeNeedsExactAttach(result.err) {
932+ attemptRequest.Intent = protocol.IntentAttach
933+ attemptRequest.RemoteTarget = nil
934+ resumeToken = 0
935+ backoff = defaultReconnectBackoff.initial
936+ continue
937+ }
930938 if !shouldReconnect(result.err) || resumeToken == 0 || ctx.Err() != nil {
931939 if clearErr := reconnect.clear(); clearErr != nil {
932940 return errors.Join(result.err, clearErr)
@@ -927,6 +927,14 @@ func (r *Runner) Run(ctx context.Context, request AttachRequest) (retErr error)
927 enterHomePicker()927 enterHomePicker()
928 continue928 continue
929 }929 }
930+ if attemptRequest.Intent == protocol.IntentResume && !result.welcomed &&
931+ attemptRequest.ExactTarget != nil && resumeNeedsExactAttach(result.err) {
932+ attemptRequest.Intent = protocol.IntentAttach
933+ attemptRequest.RemoteTarget = nil
934+ resumeToken = 0
935+ backoff = defaultReconnectBackoff.initial
936+ continue
937+ }
930 if !shouldReconnect(result.err) || resumeToken == 0 || ctx.Err() != nil {938 if !shouldReconnect(result.err) || resumeToken == 0 || ctx.Err() != nil {
931 if clearErr := reconnect.clear(); clearErr != nil {939 if clearErr := reconnect.clear(); clearErr != nil {
932 return errors.Join(result.err, clearErr)940 return errors.Join(result.err, clearErr)
M internal/usecase/client/client_test.go +52 -0
@@ -1854,6 +1854,58 @@ func TestRunReconnectsWithRotatedTokenAndSameClientID(t *testing.T) {
18541854 require.Contains(t, term.out.String(), "\x1b[2K")
18551855 }
18561856
1857+func TestExpiredResumeFallsBackToFreshExactAttach(t *testing.T) {
1858+ term := newRunTerminal()
1859+ defer term.in.unblock()
1860+ target := protocol.ExactSessionTarget{
1861+ LifecycleID: domain.SessionLifecycleID{7, 8, 9},
1862+ SessionName: "work",
1863+ }
1864+ remoteTarget := domain.RemoteSessionTarget{
1865+ Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: target.LifecycleID,
1866+ SessionName: target.SessionName, LiveTabID: "stale-tab",
1867+ }
1868+ welcome := func(token uint64) wire.Frame {
1869+ return frameOf(wire.MsgWelcome, wire.MarshalWelcome(protocol.Welcome{
1870+ SessionID: "work", SessionName: "work", ResumeToken: token, Capabilities: protocol.CapabilityResume,
1871+ CommittedIdentity: &protocol.CommittedRouteIdentity{Target: target},
1872+ }))
1873+ }
1874+ tr1 := &recordingTransport{recvs: []recvItem{{f: welcome(11)}, {err: io.EOF}}}
1875+ tr2 := &recordingTransport{recvs: []recvItem{{f: frameOf(wire.MsgError, wire.MarshalErrorMsg(protocol.ErrorMsg{
1876+ Code: protocol.ErrNoSuchSession, Text: "resume token is no longer valid",
1877+ }))}}}
1878+ tr3 := &recordingTransport{recvs: []recvItem{
1879+ {f: welcome(22)},
1880+ {f: frameOf(wire.MsgDetached, wire.MarshalDetached(protocol.Detached{Reason: protocol.ReasonDetach}))},
1881+ }}
1882+ dialer := &sequenceDialer{trs: []wire.Transport{tr1, tr2, tr3}}
1883+ clock := &reconnectTestClock{}
1884+ result := make(chan error, 1)
1885+ go func() {
1886+ result <- runTestClient(context.Background(), testDependencies(dialer, term, clock, nil, nil), client.AttachRequest{
1887+ Intent: protocol.IntentAttach, SessionName: "work", Remote: true,
1888+ Origin: protocol.RouteOriginDiscovery, OriginKey: "remote", RemoteTarget: &remoteTarget,
1889+ EnvironmentPolicy: protocol.EnvironmentPolicyDaemonOwned,
1890+ })
1891+ }()
1892+
1893+ clock.fireReconnect(t)
1894+ require.NoError(t, <-result)
1895+ require.Equal(t, int32(3), dialer.calls.Load())
1896+
1897+ initialHello := helloFromSend(t, tr1)
1898+ resumeHello := helloFromSend(t, tr2)
1899+ fallbackHello := helloFromSend(t, tr3)
1900+ require.Equal(t, protocol.IntentResume, resumeHello.Intent)
1901+ require.Equal(t, uint64(11), resumeHello.ResumeToken)
1902+ require.Equal(t, protocol.IntentAttach, fallbackHello.Intent)
1903+ require.Zero(t, fallbackHello.ResumeToken)
1904+ require.Equal(t, &target, fallbackHello.ExactTarget)
1905+ require.Nil(t, fallbackHello.RemoteTarget)
1906+ require.Equal(t, initialHello.ClientID, fallbackHello.ClientID)
1907+}
1908+
18571909 func TestReconnectRestoresLastPublishedRouteTab(t *testing.T) {
18581910 term := newRunTerminal()
18591911 defer term.in.unblock()
@@ -1854,6 +1854,58 @@ func TestRunReconnectsWithRotatedTokenAndSameClientID(t *testing.T) {
1854 require.Contains(t, term.out.String(), "\x1b[2K")1854 require.Contains(t, term.out.String(), "\x1b[2K")
1855 }1855 }
1856 1856
1857+func TestExpiredResumeFallsBackToFreshExactAttach(t *testing.T) {
1858+ term := newRunTerminal()
1859+ defer term.in.unblock()
1860+ target := protocol.ExactSessionTarget{
1861+ LifecycleID: domain.SessionLifecycleID{7, 8, 9},
1862+ SessionName: "work",
1863+ }
1864+ remoteTarget := domain.RemoteSessionTarget{
1865+ Endpoint: "remote", DisplayOrigin: "remote", LifecycleID: target.LifecycleID,
1866+ SessionName: target.SessionName, LiveTabID: "stale-tab",
1867+ }
1868+ welcome := func(token uint64) wire.Frame {
1869+ return frameOf(wire.MsgWelcome, wire.MarshalWelcome(protocol.Welcome{
1870+ SessionID: "work", SessionName: "work", ResumeToken: token, Capabilities: protocol.CapabilityResume,
1871+ CommittedIdentity: &protocol.CommittedRouteIdentity{Target: target},
1872+ }))
1873+ }
1874+ tr1 := &recordingTransport{recvs: []recvItem{{f: welcome(11)}, {err: io.EOF}}}
1875+ tr2 := &recordingTransport{recvs: []recvItem{{f: frameOf(wire.MsgError, wire.MarshalErrorMsg(protocol.ErrorMsg{
1876+ Code: protocol.ErrNoSuchSession, Text: "resume token is no longer valid",
1877+ }))}}}
1878+ tr3 := &recordingTransport{recvs: []recvItem{
1879+ {f: welcome(22)},
1880+ {f: frameOf(wire.MsgDetached, wire.MarshalDetached(protocol.Detached{Reason: protocol.ReasonDetach}))},
1881+ }}
1882+ dialer := &sequenceDialer{trs: []wire.Transport{tr1, tr2, tr3}}
1883+ clock := &reconnectTestClock{}
1884+ result := make(chan error, 1)
1885+ go func() {
1886+ result <- runTestClient(context.Background(), testDependencies(dialer, term, clock, nil, nil), client.AttachRequest{
1887+ Intent: protocol.IntentAttach, SessionName: "work", Remote: true,
1888+ Origin: protocol.RouteOriginDiscovery, OriginKey: "remote", RemoteTarget: &remoteTarget,
1889+ EnvironmentPolicy: protocol.EnvironmentPolicyDaemonOwned,
1890+ })
1891+ }()
1892+
1893+ clock.fireReconnect(t)
1894+ require.NoError(t, <-result)
1895+ require.Equal(t, int32(3), dialer.calls.Load())
1896+
1897+ initialHello := helloFromSend(t, tr1)
1898+ resumeHello := helloFromSend(t, tr2)
1899+ fallbackHello := helloFromSend(t, tr3)
1900+ require.Equal(t, protocol.IntentResume, resumeHello.Intent)
1901+ require.Equal(t, uint64(11), resumeHello.ResumeToken)
1902+ require.Equal(t, protocol.IntentAttach, fallbackHello.Intent)
1903+ require.Zero(t, fallbackHello.ResumeToken)
1904+ require.Equal(t, &target, fallbackHello.ExactTarget)
1905+ require.Nil(t, fallbackHello.RemoteTarget)
1906+ require.Equal(t, initialHello.ClientID, fallbackHello.ClientID)
1907+}
1908+
1857 func TestReconnectRestoresLastPublishedRouteTab(t *testing.T) {1909 func TestReconnectRestoresLastPublishedRouteTab(t *testing.T) {
1858 term := newRunTerminal()1910 term := newRunTerminal()
1859 defer term.in.unblock()1911 defer term.in.unblock()

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close