Skip to content

feat(hook): honor before_processing return value to gate chain execution - #172

Merged
pavanputhra merged 1 commit into
mainfrom
pavankumar/hook-return-value-contract
May 20, 2026
Merged

pavanputhra merged 1 commit into
mainfrom
pavankumar/hook-return-value-contract

Conversation

@pavanputhra

@pavanputhra pavanputhra commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make hook.before_processing honor its return value the same way chain links do:

  • Return the vcon_id (or any truthy value) → continue chain processing as before.
  • Return None / False / "" → skip the chain for this vCon. No exception, no DLQ push. after_processing still runs in finally.

The default hook is updated to explicitly return vcon_id so the default behaviour is preserved.

Motivation

Today the only way a hook can stop chain processing is to raise an exception, which the worker treats as a chain failure and pushes to the DLQ. That's the right behaviour for unexpected errors, but it conflates "the hook wants to defer this vCon" with "chain processing failed". Hooks that legitimately want to skip a vCon (for example, to defer it to a custom retry queue) had no way to do so without unwanted DLQ side effects.

This mirrors the existing chain-link should_continue_chain pattern (module.run returns the vcon_id to continue, falsy to halt) — so the contract is consistent for links and hooks.

Breaking change

Hooks that previously relied on the implicit None return will now skip the chain instead of continuing. Custom before_processing implementations must explicitly return vcon_id for normal continuation. The bundled default hook is updated accordingly.

Recommended release tag

v2.0.0 (MAJOR bump from v1.0.2, per SemVer for a breaking contract change).

Suggested annotated-tag message:

v2.0.0

BREAKING CHANGE: hook.before_processing now uses its return value to gate chain execution.
Returning None (the previous implicit default) now causes the vCon to be skipped instead
of processed. Custom hooks must explicitly `return vcon_id` for normal continuation.

See #172.

Test plan

  • Run conserver test suite inside Docker (docker exec ... pytest)
  • Default hook: vCon processes normally end-to-end (chain runs, storage writes, no DLQ on success, DLQ on link exception)
  • Custom hook returning None: process() is not called, no DLQ entry, after_processing still invoked with error=None

🤖 Generated with Claude Code

before_processing now follows the same continue/halt contract as chain
links: a truthy return (vcon_id) means continue, a falsy return means
skip the chain for this vCon without raising and without sending it to
the DLQ. The default hook returns vcon_id so existing behaviour is
preserved. The worker logs the skip and after_processing still runs.

This gives hooks a graceful "defer" signal so they can manage their own
retry/back-off state without forcing the worker to DLQ the vCon.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pavanputhra
pavanputhra merged commit 5a90c6d into main May 20, 2026
1 check passed
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.

1 participant