Files
hexis/internal/provider/registry.go
T
kami be08938f1f Thread context through Provider.Execute and stop reporting read failures as unknown
Finding 6 of REVIEW-2026-07-30.md. runWithTimeout could not cancel anything,
because Provider.Execute took no context: the goroutine ran on to the HTTP
client's 60s timeout, outliving the 30s capability timeout. Provider.Execute
now takes a context carrying that timeout, and the workspace provider issues
its tool call with http.NewRequestWithContext, so a timed-out execution
actually tears the request down.

A read-only capability whose provider call times out now resolves to failed
rather than unknown. Spec §4.3 reserves unknown for executions whose side
effect may or may not have landed, and never retries them — which made read
failures both unretryable and indistinguishable from genuinely ambiguous
mutations, for calls that by definition have no side effect. Mutating
capabilities still resolve to unknown.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uea55zaiWuEByEDC4UBSdd
2026-07-30 23:39:50 +04:00

56 lines
1.2 KiB
Go

package provider
import (
"context"
"fmt"
"sync"
"github.com/kami/hexis/internal/domain"
)
type Provider interface {
Name() string
// Execute performs the capability's side effect. The context carries the
// capability's timeout: implementations MUST propagate it into every
// blocking call they make so that a timed-out execution is genuinely
// cancelled rather than abandoned to run on in the background.
Execute(ctx context.Context, capability *domain.Capability, req *domain.ExecuteRequest) (map[string]any, error)
}
type Registry struct {
mu sync.RWMutex
providers map[string]Provider
}
func NewRegistry() *Registry {
return &Registry{
providers: make(map[string]Provider),
}
}
func (r *Registry) Register(p Provider) {
r.mu.Lock()
defer r.mu.Unlock()
r.providers[p.Name()] = p
}
func (r *Registry) Get(name string) (Provider, error) {
r.mu.RLock()
defer r.mu.RUnlock()
p, ok := r.providers[name]
if !ok {
return nil, fmt.Errorf("provider %q not found", name)
}
return p, nil
}
func (r *Registry) List() []string {
r.mu.RLock()
defer r.mu.RUnlock()
var names []string
for n := range r.providers {
names = append(names, n)
}
return names
}