Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

laya-go: Close and callHook docs say a started hook is always waited for

Adeshina Lasisi40d6c7daa0e6
diff --git a/laya-go/agent/agent.go b/laya-go/agent/agent.go
index c2e8ec48..e2f50350 100644
--- a/laya-go/agent/agent.go
+++ b/laya-go/agent/agent.go
@@ -132,10 +132,13 @@ func (a *Agent) Config() Config {
}
// Close marks the agent closed, waits for calls in flight and closes the session. Close blocks
-// until calls in flight return; cancel their contexts to bound it. A call that has not yet
-// entered returns ErrClosed without waiting. Close is idempotent: a second call, concurrent or
-// not, waits for the first and returns the same error. Close must not be called from inside a
-// call (from the session's Run): it would wait for that call, which waits for Close.
+// until calls in flight return. Cancelling a call's context ends it between chunks and releases a
+// call still queued for the serial hook lock, but a hook that has started is always waited for:
+// only WithHookTimeout bounds that wait. A call that has not yet entered returns ErrClosed without
+// waiting. Close is idempotent: a second call, concurrent or not, waits for the first and returns
+// the same error. Close must not be called from inside a call, from the session's Run or from a
+// hook: it would wait for that call, which waits for Close (with a hook timeout set, a hook's
+// Close returns only after the timeout releases its call).
func (a *Agent) Close() error {
a.once.Do(func() {
defer func() {
@@ -148,7 +151,7 @@ func (a *Agent) Close() error {
a.shut = true
a.closed.Store(true)
a.mu.Unlock()
- a.hk.quit() // a call waiting on a hook gives up, so the wait below ends
+ a.hk.quit() // releases calls queued for the serial lock before OnPredictStart
a.inflight.Wait()
if a.sess != nil {
a.closeErr = a.sess.Close()
diff --git a/laya-go/agent/hooks.go b/laya-go/agent/hooks.go
index b9af01e3..2fa58824 100644
--- a/laya-go/agent/hooks.go
+++ b/laya-go/agent/hooks.go
@@ -429,8 +429,8 @@ func (a *Agent) dispatch(ctx context.Context, ev hookEvent, hooks []Hook, pc *Pr
return nil
}
-// callHook runs one hook in its own goroutine, so a timeout, Close or the caller's context can
-// stop the wait. Under the serial lock the lock covers the wait, not the goroutine, as in Python.
+// callHook runs one hook in its own goroutine, so a timeout can stop the wait for a started
+// hook; Close and the caller's context only end a wait for the serial lock before OnPredictStart. Under the serial lock the lock covers the wait, not the goroutine, as in Python.
func (a *Agent) callHook(ctx context.Context, ev hookEvent, h Hook, pc *PredictContext) error {
hk := a.hk
if hk.serial {