Skip to content

feat: allow trigger tests to terminate early on skill invocation#207

Merged
spboyer merged 2 commits into
mainfrom
squad/188-trigger-early-termination
Apr 21, 2026
Merged

feat: allow trigger tests to terminate early on skill invocation#207
spboyer merged 2 commits into
mainfrom
squad/188-trigger-early-termination

Conversation

@spboyer

@spboyer spboyer commented Apr 21, 2026

Copy link
Copy Markdown
Member

Closes #188

Summary

Trigger tests now terminate early when the target skill is invoked, instead of waiting for the agent to finish its full turn. This reduces execution time for trigger test suites, particularly in CI environments with hard time limits.

Approach

Added a CancelOnSkillInvocation flag to ExecutionRequest that hooks into the event stream at the execution layer:

  1. SessionEventsCollector — Added an optional onSkillInvoked callback that fires when a SkillInvoked event arrives with a valid Name or Path
  2. CopilotEngine.Execute() — When the flag is set, derives a cancellable context and registers the callback to cancel it on skill invocation. Context cancellation from this path is treated as success (not an error)
  3. trigger/runner.go — Sets CancelOnSkillInvocation=true on all trigger test execution requests

Why the execution layer?

The key insight from the rubber-duck review: SendAndWait() blocks until the agent finishes its full turn. By the time the trigger runner checks SkillInvocations, the wait is already over. The fix has to happen mid-stream — cancelling the context while SendAndWait is still blocking.

Tests

  • TestSessionEventsCollector_OnSkillInvokedCallback — callback fires on invocation, skips invalid events, nil callback is safe
  • TestCopilotExecute_CancelOnSkillInvocation — mocked engine proves SendAndWait returns early when skill fires (completes in <5s vs 30s timeout)
  • TestCopilotExecute_CancelOnSkillInvocation_NoSkillFired — flag is safe when no skill fires (completes normally)
  • TestRunnerSetsCancelOnSkillInvocation — trigger runner sets the flag on execution requests

All existing tests pass: go test -mod=readonly ./... ✅ and go vet -mod=readonly ./...

@github-actions github-actions Bot enabled auto-merge (squash) April 21, 2026 19:28
Add CancelOnSkillInvocation flag to ExecutionRequest that cancels the
execution context as soon as a SkillInvoked event is received. This
allows trigger tests to return immediately once the target skill fires,
instead of waiting for the agent to complete its full turn.

Implementation:
- Add onSkillInvoked callback to SessionEventsCollector
- Wire up context cancellation in CopilotEngine.Execute when flag is set
- Trigger runner sets CancelOnSkillInvocation=true on all test prompts
- Context cancellation from skill invocation is treated as success

Tests:
- SessionEventsCollector callback fires on skill invocation
- CopilotEngine cancels SendAndWait early when skill invoked
- CopilotEngine completes normally when no skill fires (flag is safe)
- Trigger runner sets the CancelOnSkillInvocation flag

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@spboyer spboyer force-pushed the squad/188-trigger-early-termination branch from 6badcbf to 822fb92 Compare April 21, 2026 19:33
- Rename cancelledForSkill to canceledForSkill (American spelling)
- Fix 'cancelled' misspelling in comments
- Add mutex to capturingEngine to prevent data race in trigger tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@spboyer spboyer force-pushed the squad/188-trigger-early-termination branch from 95f131e to c44dcdd Compare April 21, 2026 19:44
@spboyer spboyer merged commit 956beaa into main Apr 21, 2026
5 of 6 checks passed
@spboyer spboyer deleted the squad/188-trigger-early-termination branch April 21, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: allow trigger tests to terminate early on skill invocation or other conditions

2 participants