Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions pkgs/mcpx/internal/daemon/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"
"strconv"
"time"

"github.com/developing-today/code/pkgs/mcpx/internal/defaults"
"github.com/developing-today/code/pkgs/mcpx/internal/elicit"
Expand Down Expand Up @@ -286,14 +285,13 @@ func (r *Registry) elicitViaBroker(ctx context.Context, server, key string, para
// migrated; they expire by TTL.
brokerID := brokerRowID(server, p.ElicitationID)
req := elicit.Request{
ID: brokerID,
Server: server,
Mode: mode,
Message: p.Message,
Schema: p.RequestedSchema,
URL: p.URL,
Trace: r.askIDFor(ctx, server, key),
ExpiresAt: time.Now().Add(defaults.ElicitTTL),
ID: brokerID,
Server: server,
Mode: mode,
Message: p.Message,
Schema: p.RequestedSchema,
URL: p.URL,
Trace: r.askIDFor(ctx, server, key),
}
if !r.hasAnswerer(req) {
return nil, noAudience("elicitation/create", req)
Expand Down Expand Up @@ -388,11 +386,10 @@ func (r *Registry) sampleViaBroker(ctx context.Context, server, key string, para
// A sampling request has no question as such. The system prompt is
// the closest thing to one, and it is what a human reading the
// queue needs to see first.
Message: firstNonEmptyStr(p.SystemPrompt, server+" asks for a model completion"),
Schema: params,
Audience: elicit.ToAgent,
Reason: "sampling asks a model, and the agent driving mcpx has one",
ExpiresAt: time.Now().Add(defaults.ElicitTTL),
Message: firstNonEmptyStr(p.SystemPrompt, server+" asks for a model completion"),
Schema: params,
Audience: elicit.ToAgent,
Reason: "sampling asks a model, and the agent driving mcpx has one",
}
if !r.hasAnswerer(req) {
return nil, noAudience("sampling/createMessage", req)
Expand Down Expand Up @@ -461,13 +458,12 @@ func (r *Registry) rootsViaBroker(ctx context.Context, server, key string, param
return nil, mcpclient.ErrNotRelayed
}
req, err := r.broker.OpenRequest(elicit.Request{
Server: server,
Trace: r.askIDFor(ctx, server, key),
Mode: elicit.Roots,
Message: server + " asks for the client's roots",
Audience: elicit.ToAgent,
Reason: "roots are the client's own, and only it can list them",
ExpiresAt: time.Now().Add(defaults.ElicitTTL),
Server: server,
Trace: r.askIDFor(ctx, server, key),
Mode: elicit.Roots,
Message: server + " asks for the client's roots",
Audience: elicit.ToAgent,
Reason: "roots are the client's own, and only it can list them",
})
if err != nil {
return nil, err
Expand Down
62 changes: 62 additions & 0 deletions pkgs/mcpx/internal/e2e/effect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ var implementedEffectProbes = map[string]string{
"protoTasks.maxPerRequestor": "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment",
"protoTasks.perMinute": "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment",
"events.history": "TestEventsHistoryBoundsTheReplay",
"elicit.ttl": "TestElicitTTLSetsAnUpstreamQuestionsDeadlineFromTheEnvironment",
"elicit.maxAge": "TestElicitMaxAgeCapsAnUpstreamQuestionsDeadlineFromTheEnvironment",
"elicit.pendingLimit": "TestElicitPendingLimitBoundsTheListingFromTheEnvironment",
"elicit.askTimeout": "TestElicitAskTimeoutBoundsTheWaitForAnAnswerFromTheEnvironment",
"artifacts.idleTtl": "TestArtifactsIdleTTLRenewsAReadArtifactFromTheEnvironment",
Expand Down Expand Up @@ -277,6 +279,8 @@ var effectProbeFuncs = map[string]func(*testing.T){
"TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment": TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment,
"TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment": TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment,
"TestEventsHistoryBoundsTheReplay": TestEventsHistoryBoundsTheReplay,
"TestElicitTTLSetsAnUpstreamQuestionsDeadlineFromTheEnvironment": TestElicitTTLSetsAnUpstreamQuestionsDeadlineFromTheEnvironment,
"TestElicitMaxAgeCapsAnUpstreamQuestionsDeadlineFromTheEnvironment": TestElicitMaxAgeCapsAnUpstreamQuestionsDeadlineFromTheEnvironment,
"TestElicitPendingLimitBoundsTheListingFromTheEnvironment": TestElicitPendingLimitBoundsTheListingFromTheEnvironment,
"TestElicitAskTimeoutBoundsTheWaitForAnAnswerFromTheEnvironment": TestElicitAskTimeoutBoundsTheWaitForAnAnswerFromTheEnvironment,
"TestArtifactsIdleTTLRenewsAReadArtifactFromTheEnvironment": TestArtifactsIdleTTLRenewsAReadArtifactFromTheEnvironment,
Expand Down Expand Up @@ -3557,6 +3561,64 @@ func TestElicitPendingLimitBoundsTheListingFromTheEnvironment(t *testing.T) {
}
}

// upstreamQuestionLife raises one question from an upstream server (the
// ask fixture's need_repo) under env, reads its listed deadline, answers
// it and returns the deadline's distance from the question's creation.
func upstreamQuestionLife(t *testing.T, env ...string) time.Duration {
t.Helper()
e := askWith(t, `{"sharing":"shared","scope":"global"}`)
e.setenv(env...)
e.run("refresh")
beAnswerer(t, e)
c := e.longSocketClient(t)
done := make(chan struct{})
go func() {
sockDo(t, c, http.MethodPost, "/v1/call", map[string]any{"server": "ask", "tool": "need_repo"})
close(done)
}()
ids := waitQuestions(t, e, 1)
var listed []struct {
Created time.Time `json:"created"`
ExpiresAt time.Time `json:"expiresAt"`
}
out := e.run("--json", "elicit", "list")
if err := json.Unmarshal([]byte(out), &listed); err != nil || len(listed) != 1 {
t.Fatalf("one question should be listed (%v):\n%s", err, out)
}
e.run("elicit", "answer", ids[0], `{"repo":"probe"}`)
select {
case <-done:
case <-time.After(30 * time.Second):
t.Fatal("the answered call never finished")
}
return listed[0].ExpiresAt.Sub(listed[0].Created).Round(time.Second)
}

// TestElicitTTLSetsAnUpstreamQuestionsDeadlineFromTheEnvironment is the
// effect probe for elicit.ttl. A question an upstream server asks lives
// the built-in two minutes by default and seven with elicit.ttl=7m.
func TestElicitTTLSetsAnUpstreamQuestionsDeadlineFromTheEnvironment(t *testing.T) {
if got := upstreamQuestionLife(t); got != 2*time.Minute {
t.Fatalf("oracle: an upstream question should live the default 2m, got %v", got)
}
if got := upstreamQuestionLife(t, "MCPX_ELICIT_TTL=7m"); got != 7*time.Minute {
t.Fatalf("with elicit.ttl=7m the question should live 7m, got %v", got)
}
}

// TestElicitMaxAgeCapsAnUpstreamQuestionsDeadlineFromTheEnvironment is
// the effect probe for elicit.maxAge. Under elicit.ttl=7m the question
// lives seven minutes by default (the 30m ceiling is far off) and one
// with elicit.maxAge=1m.
func TestElicitMaxAgeCapsAnUpstreamQuestionsDeadlineFromTheEnvironment(t *testing.T) {
if got := upstreamQuestionLife(t, "MCPX_ELICIT_TTL=7m"); got != 7*time.Minute {
t.Fatalf("oracle: under elicit.ttl=7m the question should live 7m, got %v", got)
}
if got := upstreamQuestionLife(t, "MCPX_ELICIT_TTL=7m", "MCPX_ELICIT_MAX_AGE=1m"); got != time.Minute {
t.Fatalf("with elicit.maxAge=1m the question should live 1m, got %v", got)
}
}

// TestDaemonAddressIsReachableFromTheEnvironment is the effect probe
// for daemon.address (#8468 chain 1). The exemption it replaced said
// a bind address is a network identity the harness cannot vary
Expand Down
2 changes: 0 additions & 2 deletions pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ setting output.color no integration-test exercise yet; burn-down #8467 (settings
setting paths.config no integration-test exercise yet; burn-down #8467 (settings core-paths family); needs an EffectProbes entry + e2e test
setting elicit.disambiguate no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting elicit.disambiguateDefault no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting elicit.maxAge no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting elicit.ttl no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting embeddings.apiKey no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting embeddings.backend no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
setting embeddings.model no integration-test exercise yet; burn-down #8471 (settings model-ai family); needs an EffectProbes entry + e2e test
Expand Down
Loading