Skip to content

entrypoint: don't cache a call that threw - #137

Merged
TomChv merged 2 commits into
mainfrom
entrypoint-failure-not-cached
Nov 16, 2026
Merged

TomChv merged 2 commits into
mainfrom
entrypoint-failure-not-cached

Conversation

@vito

@vito vito commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #136.

When a function in an entrypoint module throws, the failure is no longer cached and replayed.

The dispatcher used to exit 0 after writing an { error } reply. That made the exec a cached success under the call digest, so every later evaluation of the failed call got the same error back without running the function. The dispatcher now exits 2 after an error reply, so the exec fails and isn't cached. This matches what the Go, Java and Python entrypoints do, and what the builtin runtime always did.

Changes

  • Dispatcher (dispatch_v2.ts.gtpl):
    • It still writes the same stdout reply, then sets process.exitCode = 2 when the function threw.
    • The entrypoint reads the reply back from the failed exec's stdout tail, which the engine caps at 100 KiB. So an error message is cut until the encoded reply fits in 96 KiB. It keeps any [traceparent:…] markers from the cut part.
  • Entrypoint (main.dang.gtpl):
    • It rescues the failed exec, decodes the reply from err.extensions.stdout, and raises its message. When there is no reply, for example when the dispatcher crashed, it re-raises the exec's own error.
    • The container is synced before the exec, outside the rescue, so a failed install still fails with its own error and values. On engines before dang: fail a function with the Error it raises dagger#15161, a rescued error raised again keeps only its message.
    • An { error } reply on an exec that succeeded anyway is still raised.
  • Docs: §6.3 of design/module-entrypoint.md and the comments now describe this protocol.

Tests

  • New check runtimes:entrypoint-failure-reruns-check. The node, bun and deno fixtures gain nonceFailure(), which throws a fresh UUID. The check calls it twice in one session and requires the nonces to differ.
    • Before the fix, on node, both calls failed with the same nonce and the second took 0.0s.
    • With the fix, all three runtimes pass. That also confirms each interpreter honors process.exitCode.
  • Other checks:
    • e2e:generate/entrypoint-reports-errors-check and e2e:version/core-from-bundle-check assert the new recipe shape.
    • The codegen unit tests and goldens are updated.
  • Full runs: the suite passes through engine-e2e/checks-check, with 129 checks. engine-e2e/generate writes no changes.

Not covered

  • Output on stdout from user code, for example console.log, likely still lands in the reply channel. Review flagged this and I haven't reproduced it. If so, a function that logs and then throws gets the bare exit-code error, and one that logs and returns fails to decode. That would have been true before this change too, and needs its own fix.
  • Only the message crosses. A thrown error's values still don't reach the caller.

vito added 2 commits November 12, 2026 23:44
The dispatcher of an entrypoint module exited 0 when the function threw,
replying with the error on stdout for the entrypoint to raise. The exec
therefore succeeded and was cached under the call digest: dagql keeps no
result for the failed call, so the next evaluation ran the entrypoint again,
its exec answered from the cache, and the same error came back without the
function running. A flaky failure stuck until the exec was pruned.

The dispatcher now exits 2 after an error reply, so the exec fails and is
not cached. A failed exec keeps the tail of its stdout in its error, so the
entrypoint rescues it and raises the message from the reply there, or the
exec's own error when there is none. The message is capped to fit that
tail, keeping the traceparents it cuts.

runtimes:entrypoint-failure-reruns-check calls a function that throws a new
nonce twice, on node, bun and deno; before this it got the same nonce back.

Signed-off-by: Alex Suraci <[email protected]>
Review follow-ups to the previous commit. The call's container is synced
before the dispatcher's exec, outside the rescue, so a failed install keeps
its own error and values instead of only the message a re-raise keeps on
engines before dagger/dagger#15161. The error reply is cut to the bytes it
can take in the failed exec's 100 KiB stdout tail, measured on the encoded
reply, rather than to 16 Ki characters, so a long ASCII report is no longer
cut short. The comments say what tells a function's failure from the
dispatcher's: the reply, not the exit code.

Signed-off-by: Alex Suraci <[email protected]>
@TomChv
TomChv merged commit aeaf264 into main Nov 16, 2026
6 checks 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.

Entrypoint modules cache a function's failure and replay it

3 participants