-
Notifications
You must be signed in to change notification settings - Fork 101
fix(#6936): persist token telemetry when agents are cancelled #6938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a41e109
fix(#6936): persist token telemetry when agents are cancelled
fullsend-ai-coder[bot] 37bc3fc
fix(#6938): align cancellation warning with existing error message co…
fullsend-ai-coder[bot] d2e0857
test(#6938): increase code coverage for signal handling and cancellat…
fullsend-ai-coder[bot] 4a67379
fix(#6938): document cost limitation and use idiomatic ctx.Err check
fullsend-ai-coder[bot] a7038c0
Merge remote-tracking branch 'origin/main' into agent/6936-persist-ca…
ascerra 78d6425
test(#6938): cover the cancellation short-circuit and tighten the cle…
fullsend-ai-coder[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| // TestSignalContext_CancelsOnFirstSignal verifies that signalContext returns | ||
| // a context that is cancelled when the process receives the first SIGINT. | ||
| // This is the primary invariant for #6936: the first signal must cancel the | ||
| // context so the cleanup path (metrics, telemetry) can run. | ||
| func TestSignalContext_CancelsOnFirstSignal(t *testing.T) { | ||
| ctx, cleanup := signalContext() | ||
| defer cleanup() | ||
|
|
||
| // Send SIGINT to ourselves. | ||
| proc, err := os.FindProcess(os.Getpid()) | ||
| if err != nil { | ||
| t.Fatalf("FindProcess: %v", err) | ||
| } | ||
| if err := proc.Signal(syscall.SIGINT); err != nil { | ||
| t.Fatalf("Signal: %v", err) | ||
| } | ||
|
|
||
| select { | ||
| case <-ctx.Done(): | ||
| // Expected: context cancelled on first signal. | ||
| case <-time.After(2 * time.Second): | ||
| t.Fatal("context was not cancelled within 2s after SIGINT") | ||
| } | ||
| } | ||
|
|
||
| // TestSignalContext_AbsorbsSubsequentSignals verifies that after the first | ||
| // signal cancels the context, further SIGINT/SIGTERM deliveries are absorbed | ||
| // (they do not kill the process). This is the second invariant for #6936: | ||
| // GitHub Actions sends SIGINT then SIGTERM ~7.5 s later; the second signal | ||
| // must not trigger the default terminate handler. | ||
| func TestSignalContext_AbsorbsSubsequentSignals(t *testing.T) { | ||
| ctx, cleanup := signalContext() | ||
| defer cleanup() | ||
|
|
||
| proc, err := os.FindProcess(os.Getpid()) | ||
| if err != nil { | ||
| t.Fatalf("FindProcess: %v", err) | ||
| } | ||
|
|
||
| // First signal: cancels the context. | ||
| if err := proc.Signal(syscall.SIGINT); err != nil { | ||
| t.Fatalf("first Signal: %v", err) | ||
| } | ||
|
|
||
| select { | ||
| case <-ctx.Done(): | ||
| // Good — context cancelled. | ||
| case <-time.After(2 * time.Second): | ||
| t.Fatal("context was not cancelled after first SIGINT") | ||
| } | ||
|
|
||
| // Second signal: must be absorbed (not kill the process). | ||
| if err := proc.Signal(syscall.SIGTERM); err != nil { | ||
| t.Fatalf("second Signal: %v", err) | ||
| } | ||
|
|
||
| // If we reach this point without dying, the signal was absorbed. | ||
| // Give a short window for the signal to be delivered and handled. | ||
| time.Sleep(50 * time.Millisecond) | ||
| } | ||
|
|
||
| // TestSignalContext_CleanupStopsForwarding verifies that after cleanup() is | ||
| // called, signal forwarding to signalContext's channel is disabled: a signal | ||
| // sent after cleanup() must not cancel ctx. A probe registered independently | ||
| // via signal.Notify confirms the signal was actually delivered by the OS | ||
| // (so the assertion isn't vacuously true because the signal never arrived), | ||
| // without relying on ctx or signalContext's own (now-detached) channel and | ||
| // without killing the test process. | ||
| func TestSignalContext_CleanupStopsForwarding(t *testing.T) { | ||
| ctx, cleanup := signalContext() | ||
| cleanup() | ||
|
|
||
| probe := make(chan os.Signal, 1) | ||
| signal.Notify(probe, syscall.SIGINT) | ||
| defer signal.Stop(probe) | ||
|
|
||
| proc, err := os.FindProcess(os.Getpid()) | ||
| if err != nil { | ||
| t.Fatalf("FindProcess: %v", err) | ||
| } | ||
| if err := proc.Signal(syscall.SIGINT); err != nil { | ||
| t.Fatalf("Signal: %v", err) | ||
| } | ||
|
|
||
| select { | ||
| case <-probe: | ||
| // Expected: the OS still delivered SIGINT to an independent | ||
| // receiver, so the process is alive and the signal was sent. | ||
| case <-time.After(2 * time.Second): | ||
| t.Fatal("probe did not receive SIGINT within 2s; signal was never delivered") | ||
| } | ||
|
|
||
| select { | ||
| case <-ctx.Done(): | ||
| t.Fatal("context was cancelled after cleanup(); signal.Stop did not disable forwarding") | ||
| default: | ||
| // Expected: forwarding disabled, context still active. | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.