Repository navigation
feat(bun): introduce ScriptTrigger & CommandsTrigger for the Bun plugin - #433
Conversation
jymaire
left a comment
There was a problem hiding this comment.
Automated correctness review (6 findings).
|
Acknowledging this review. Findings 1, 2 and 6 (lastMatched not surviving the scheduler's per-poll reconstruction, and the test masking it by reusing one instance) are the exact same systemic defect a human reviewer independently caught on the sibling #436 (PowerShell) PR - confirmed real there, not fixed in place since it's copied from the already-merged go/node/python/ruby/shell plugins and needs a real cross-poll state mechanism, not a narrow per-plugin patch. I documented the limitation explicitly (code comment + corrected schema description + a note on the test that only proves same-instance dedup) rather than leave it silently broken, and I'll bring the same documentation fix here plus to #434/#435 in a follow-up pass, together with whatever the tracked Finding 5 (regex recompiled every poll) is a fair, easy catch I'll fold into that same follow-up. Finding 4 ( Finding 3 (vars=null on failure, so non- 🤖 AI-assisted - I read and independently verified this review's reasoning against the code rather than taking it at face value. |
304521b to
050d2fa
Compare
|
Pushed 050d2fa, as promised in my earlier note. Going through the six findings:
Also 13/13 unit tests pass locally, and breaking the exit-code branch of 🤖 AI-assisted, as noted in the description. Update: findings 1, 2, 5 and 6 are fixed for real in dada7bf (edge state in the namespace KV store, cached regex, edge tests on a serialized copy), and I have since run the container-backed tests locally (31 across the five trigger test classes, all passing). Findings 3 and 4 are still documented, see the review threads. |
|
Hello @InnoxCodes , it will be difficult for me to merge this PR if all the bugs found during review are only documented and not fixed. |
Part of kestra-io#313. plugin-scripts wants every submodule to expose a ScriptTrigger and a CommandsTrigger so a flow can be triggered whenever the underlying script/commands execution completes, with an exit condition deciding whether the trigger fires. plugin-script-bun was missing both. Ports the pattern already established in plugin-script-go and plugin-script-node (the two existing reference implementations checked against): a polling trigger that runs the sub-plugin's Script/Commands task once per poll, matches the rendered exitCondition against either the exit code ('exit N') or a regex/substring against the emitted vars and failure logs, and supports edge mode (default on) to emit only on a not-matching-to-matching transition. - ScriptTrigger wraps io.kestra.plugin.scripts.bun.Script - CommandsTrigger wraps io.kestra.plugin.scripts.bun.Commands - Both default containerImage to 'oven/bun', matching the existing Script/Commands tasks' default Fixes kestra-io#422
Ports the review fixes from the PowerShell PR. - ScriptTriggerTest no longer asserts against a private copy of the matching logic. matchesCondition is package-private and the tests call it on a real ScriptTrigger (CsvSource table for exit codes). - Documented the edge mode limitation instead of leaving it silently broken: lastMatched is a plain field that does not survive the worker's serialize/deserialize round trip, so in a distributed deployment edge mode fires on every matching poll. Code comment, corrected schema descriptions, and a note on the edge test that only proves same-instance dedup. The real fix needs a cross-poll state mechanism shared by the whole plugin family and is tracked separately. - Removed the "failure logs" claim from the docs: a failed run passes null vars, so only 'exit N' can match a failure. - @EqualsAndHashCode.Exclude on lastMatched, with a comment that says only what the exclusion does (equals already falls back to object identity via AbstractTrigger and callSuper=call). - Example intervals PT10S -> PT60S, matching the coded default.
The edge flag lived in an AtomicBoolean on the trigger, but a polling trigger is rebuilt on every poll, so with the default edge=true a condition that stays true fired on every interval. The previous result is now stored under a length prefixed key built from the flow and trigger ids in the namespace KV store and updated on every poll. Also from the review: - the condition regex is compiled once and cached in a small bounded static map, since the trigger itself is rebuilt on every poll - an empty exitCondition now fails with a clear message instead of silently never matching - class level @Schema descriptions are text blocks - the edge tests run the second poll on a serialized copy of the trigger - add a Docker backed ScriptTrigger#evaluate test - add KV state tests that run without Docker - document the triggers in the module doc and list them in AGENTS.md
050d2fa to
dada7bf
Compare
|
Thanks @jymaire, fair point. I pushed dada7bf, which fixes what can be fixed in this PR: the edge state is now kept in the namespace KV store (the bug QA reproduced), the condition regex is cached, and the edge tests run every poll on a serialized copy of the trigger. It is all in the PR description too. Two things are still documented rather than changed, and I explained why on the threads: a failed run has no vars, so only |
Aligns the R triggers with the pattern merged for Bun in kestra-io#433. - Persist edge state in the namespace KV store instead of an in-memory AtomicBoolean. This drops the field the review flagged for breaking Lombok equals/hashCode (AtomicBoolean has identity equality), and also fixes kestra-io#449: a rebuilt or rehydrated trigger no longer re-fires. - Replace the CompletableFuture regex timeout with a bounded LRU cache of compiled patterns. The abandoned future leaked a ForkJoinPool.commonPool() worker on timeout, since Matcher#find() is not interruptible. - Fail loudly when the required exitCondition renders empty, instead of silently coercing it to "" and never matching. - Remove the TODO comments from both trigger classes. - Document both triggers in the plugin how-to doc. - Replace the edge-mode tests that asserted AtomicBoolean arithmetic with tests that drive shouldEmit and evaluate() for real, and randomize trigger ids now that edge state persists between runs. - Revert the scheduler/worker test dependencies, which are not needed. Co-Authored-By: Claude Opus 5 <[email protected]>
* feat/r-script-commands-triggers * fix(r): address review feedback on R triggers Aligns the R triggers with the pattern merged for Bun in #433. - Persist edge state in the namespace KV store instead of an in-memory AtomicBoolean. This drops the field the review flagged for breaking Lombok equals/hashCode (AtomicBoolean has identity equality), and also fixes #449: a rebuilt or rehydrated trigger no longer re-fires. - Replace the CompletableFuture regex timeout with a bounded LRU cache of compiled patterns. The abandoned future leaked a ForkJoinPool.commonPool() worker on timeout, since Matcher#find() is not interruptible. - Fail loudly when the required exitCondition renders empty, instead of silently coercing it to "" and never matching. - Remove the TODO comments from both trigger classes. - Document both triggers in the plugin how-to doc. - Replace the edge-mode tests that asserted AtomicBoolean arithmetic with tests that drive shouldEmit and evaluate() for real, and randomize trigger ids now that edge state persists between runs. - Revert the scheduler/worker test dependencies, which are not needed. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: François Delbrayelle <[email protected]> Co-authored-by: Claude Opus 5 <[email protected]>
Summary
Fixes #422, part of #313.
plugin-scriptswants every submodule to expose aScriptTriggerand aCommandsTrigger, so a flow can be triggered whenever the underlying script/commands execution completes, with an exit condition deciding whether the trigger fires.plugin-script-bunwas missing both.Implementation
Ports the pattern already established in
plugin-script-goandplugin-script-node(checked both as reference implementations, per the issue), with the edge state kept in the namespace KV store instead of an in-memory field. A polling trigger that:Script/Commandstask once per pollexitConditionagainst either the exit code (exit N) or a regex/substring against the emitted vars. A failed run has no vars, so onlyexit Ncan match a failureScriptTriggerwrapsio.kestra.plugin.scripts.bun.Script;CommandsTriggerwrapsio.kestra.plugin.scripts.bun.Commands. Both defaultcontainerImagetooven/bun, matching the existingScript/Commandstasks' own default. The module doc has a Triggers section andAGENTS.mdlists both classes.An image that cannot be pulled (or any other error thrown before the task returns) is logged as a warning and does not count as a run: nothing is emitted and the edge state is left as it was.
Testing
Ran locally with Docker, 31 tests across these five classes, all passing:
ScriptTriggerTest(13): pure condition-matching unit tests that call the real package-privatematchesCondition, no Docker neededEdgeStateTest(8): edge state in the KV store, no Docker needed. Each poll runs on a JSON round-tripped copy of the trigger, and there are cases foredge: false, for state being scoped per flow and per trigger, and for the key format. Removing thekvStore.putmakes 4 of them failConditionPatternTest(3): the regex cache returns the same compiled pattern and stays correct past its size limitScriptTriggerEvaluateTest(3): runs the realScriptTrigger#evaluatein a container (fires onexit 1, stays quiet onexit 0, suppresses the second poll in edge mode)CommandsTriggerTest(4): same forCommandsTrigger. Its edge test now runs the second poll on a serialized copy and also fails without the KV write./gradlew :plugin-script-bun:spotlessCheckpasses🤖 AI-assisted: I used Claude Code to help draft and verify this fix, and cross-checked it against the existing Go/Node reference implementations before opening this PR.