Skip to content

fix(plugin): add context.Context to HookFunc for cooperative cancellation#16

Merged
zeroedin merged 1 commit into
mainfrom
fix/issue-13-hookfunc-context
Apr 13, 2026
Merged

fix(plugin): add context.Context to HookFunc for cooperative cancellation#16
zeroedin merged 1 commit into
mainfrom
fix/issue-13-hookfunc-context

Conversation

@zeroedin

Copy link
Copy Markdown
Owner

Summary

  • Changes HookFunc signature from func(payload interface{}) (interface{}, error) to func(ctx context.Context, payload interface{}) (interface{}, error)
  • Run() passes context.Background() to each hook
  • RunWithTimeout() uses context.WithTimeout() and passes the derived context, enabling cooperative cancellation
  • Implements the full hook registry (was stubs on main): registration, chaining, timeout with warnings
  • Updates PLAN.md and IMPLEMENTATION.md to document the context-aware hook API

Closes #13

Test plan

  • All 24 hooks tests pass with updated context.Context signatures
  • Timeout tests verify context-based cancellation behavior
  • Registry/node/wasm tests unaffected (separate stub implementations)

🤖 Generated with Claude Code

@zeroedin zeroedin left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code Review: fix(plugin): add context.Context to HookFunc for cooperative cancellation

Verdict: Approve with merge sequencing note

Correctly addresses the goroutine leak I flagged on PR #8. The HookFunc signature now carries a context.Context with the timeout deadline, enabling cooperative cancellation.

Check Result
Hooks tests 24/24 pass
Other plugin tests 35 fail (pre-existing on main: 0/59 pass without Phase 5)
go vet Clean
Regressions None

Implementation review:

  • Run() correctly passes context.Background() — no timeout for direct execution
  • RunWithTimeout() creates context.WithTimeout() per hook, passes the derived context, cancels in both branches (success and timeout)
  • Timeout behavior preserved: pre-hook payload kept on timeout, warning logged, build continues
  • Hook functions can now check ctx.Done() for cooperative cancellation

Test changes: All 24 test modifications are mechanical — adding _ context.Context as the first parameter to match the new signature. Test assertions are unchanged. The hooks are intentionally context-unaware in tests to verify the timeout safety net works even without cooperation.

Merge sequencing concern: PR #8 (Phase 5) also implements hooks.go from stubs with the old HookFunc signature. When both PRs merge to main, they will conflict on hooks.go and hooks_test.go. Recommendation: merge this PR first, then rebase PR #8 to adopt the context.Context signature.

PLAN.md/IMPLEMENTATION.md updated with the context-aware hook API documentation. Clean fix.

@zeroedin
zeroedin force-pushed the fix/issue-13-hookfunc-context branch from 1095f8e to 318cc6d Compare April 13, 2026 03:35
…tion

Change HookFunc signature from func(payload) to func(ctx, payload).
Run() passes context.Background(). RunWithTimeout() uses
context.WithTimeout() and passes the derived context to each hook,
enabling cooperative cancellation.

Updates spec (PLAN.md) and implementation plan to document the
context-aware hook API.

Closes #13

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zeroedin
zeroedin force-pushed the fix/issue-13-hookfunc-context branch from 318cc6d to 7896690 Compare April 13, 2026 03:39
@zeroedin
zeroedin merged commit 8a5f90b into main Apr 13, 2026
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.

RunWithTimeout: goroutine leak on hook timeout

1 participant