Release native chat runtimes on lifecycle changes
Ensure /new and chat close stop native foreground and background work before changing registry state. Preserve transcripts while surfacing release and recovery cleanup failures instead of reporting false success, with focused adapter and server regressions.
This commit is contained in:
@@ -322,6 +322,30 @@ func (c *Chat) Interrupt(ctx context.Context, id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReleaseSession stops active and background work for an explicit operator
|
||||
// close or /new without deleting the persisted native conversation. OpenCode
|
||||
// interrupt only stops the foreground drain; running shells are separate native
|
||||
// operations and must be terminated individually.
|
||||
func (c *Chat) ReleaseSession(ctx context.Context, id string) error {
|
||||
if err := c.Interrupt(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
shells, err := c.Shells(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, shell := range shells {
|
||||
if shell.Status != protocol.ChatShellRunning {
|
||||
continue
|
||||
}
|
||||
if _, err := c.call(ctx, "delete", "/api/shell/"+url.PathEscape(shell.ID), nil); err != nil {
|
||||
return fmt.Errorf("stop shell %s: %w", shell.ID, err)
|
||||
}
|
||||
}
|
||||
c.ReleaseShells(id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Detach is the server-restart shutdown (chatShutdownDetacher). Sessions, turns, questions,
|
||||
// permissions and shells live in the OpenCode service, not in this adapter, so
|
||||
// there is nothing to stop: the connection's owner decides whether the service
|
||||
|
||||
Reference in New Issue
Block a user