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
43 changes: 43 additions & 0 deletions pkgs/mcpx/internal/e2e/effect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ var implementedEffectProbes = map[string]string{
"protoTasks.maxTTL": "TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment",
"protoTasks.maxPerRequestor": "TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment",
"protoTasks.perMinute": "TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment",
"protoTasks.cancelGrace": "TestProtoTasksCancelGraceExpiresACancelledTaskFromTheEnvironment",
"events.history": "TestEventsHistoryBoundsTheReplay",
"events.reconnect": "TestEventsReconnectWaitsForTheConfiguredDelay",
"script.checkOnUnsupported": "TestScriptCheckOnUnsupportedDecidesWhatANonDenoCheckDoes",
Expand Down Expand Up @@ -366,6 +367,7 @@ var effectProbeFuncs = map[string]func(*testing.T){
"TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment": TestProtoTasksMaxTTLClampsATasksRetentionFromTheEnvironment,
"TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment": TestProtoTasksMaxPerRequestorCapsUnfinishedTasksFromTheEnvironment,
"TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment": TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment,
"TestProtoTasksCancelGraceExpiresACancelledTaskFromTheEnvironment": TestProtoTasksCancelGraceExpiresACancelledTaskFromTheEnvironment,
"TestEventsHistoryBoundsTheReplay": TestEventsHistoryBoundsTheReplay,
"TestEventsReconnectWaitsForTheConfiguredDelay": TestEventsReconnectWaitsForTheConfiguredDelay,
"TestScriptCheckOnUnsupportedDecidesWhatANonDenoCheckDoes": TestScriptCheckOnUnsupportedDecidesWhatANonDenoCheckDoes,
Expand Down Expand Up @@ -1848,6 +1850,47 @@ func TestProtoTasksPerMinuteWindowsTaskReadsFromTheEnvironment(t *testing.T) {
}
}

// protoTasks.cancelGrace is how long work on the modern tasks
// extension path may still finish after a tasks/cancel before the
// store records the cancellation anyway (cooperative Store.Cancel).
// The task is a two-second script; cancelling it starts an unwind
// that takes measurable time to record the script's own outcome, so
// the window's edge is observable: a window no work can finish
// inside loses the record to the cancellation, a wide one keeps it.
// Oracle: with MCPX_PROTO_TASKS_CANCEL_GRACE=1us the store records
// the task cancelled; with a 30s grace the work's own outcome
// stands and the task reads completed.
func TestProtoTasksCancelGraceExpiresACancelledTaskFromTheEnvironment(t *testing.T) {
statusAfterCancel := func(env ...string) string {
t.Helper()
rpc := tasksClient(t, env...)
res, _ := startSlowTask(t, rpc)["result"].(map[string]any)
id, _ := res["taskId"].(string)
if id == "" {
t.Fatalf("no task was started: %v", res)
}
rpc("tasks/cancel", map[string]any{"taskId": id})
// Read until the record turns terminal; either outcome
// lands within moments of the cancel.
deadline := time.Now().Add(10 * time.Second)
for {
got, _ := rpc("tasks/get", map[string]any{"taskId": id})["result"].(map[string]any)
status, _ := got["status"].(string)
if status == "cancelled" || status == "completed" || status == "failed" || time.Now().After(deadline) {
return status
}
time.Sleep(25 * time.Millisecond)
}
}

if got := statusAfterCancel("MCPX_PROTO_TASKS_CANCEL_GRACE=1us"); got != "cancelled" {
t.Fatalf("protoTasks.cancelGrace=1us should record the task cancelled once the grace expires, got status %q", got)
Comment on lines +1886 to +1887

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Control task completion instead of racing a microsecond timer

Under scheduler contention, the short-grace case can return completed even when cancellation works correctly. Store.CancelWithReason schedules expiry with time.AfterFunc, but Store.finish accepts completion and stops that timer if it acquires the lock before the callback; it does not check whether the grace duration has elapsed. A 1µs duration therefore does not guarantee cancellation wins, and the two-second script provides no synchronization barrier. Use a controllable fixture that holds completion until cancellation expiry is observed, with a separately controlled completion for the long-grace case, so this probe does not introduce intermittent CI failures.

AGENTS.md reference: pkgs/mcpx/internal/AGENTS.md:L13-L14

Useful? React with 👍 / 👎.

}
if got := statusAfterCancel("MCPX_PROTO_TASKS_CANCEL_GRACE=30s"); got != "completed" {
t.Fatalf("with a 30s protoTasks.cancelGrace the cancelled task's own outcome should stand, got status %q", got)
}
}

// replayFromStart reads what /v1/events replays from sequence zero. The
// stream stays open for live events, so it reads until the client's short
// deadline and keeps whatever arrived.
Expand Down
1 change: 0 additions & 1 deletion pkgs/mcpx/internal/e2e/feature_coverage_exemptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ setting daemon.inlineStartPoll no integration-test exercise yet; burn-down #8468
setting daemon.tsnet.hostname no integration-test exercise yet; burn-down #8468 (settings daemon family); needs an EffectProbes entry + e2e test
setting daemon.tsnetUpTimeout no integration-test exercise yet; burn-down #8468 (settings daemon family); needs an EffectProbes entry + e2e test
setting http.streamBufferInit allocation-capacity hint only; output and line ceiling are unchanged, so allocation size has no stable e2e behavior oracle
setting protoTasks.cancelGrace no integration-test exercise yet; burn-down #8473 (settings proto family); needs an EffectProbes entry + e2e test
setting plugin.disabledTools no integration-test exercise yet; burn-down #8472 (settings plugin family); needs an EffectProbes entry + e2e test
setting embeddings.wasmPath embeddings backend: needs a compiled wasm model fixture the harness does not provide; no embed-exporting model ships with the repo
Loading