From 0db793494d5d357bacf37bed6a517a010f1f421f Mon Sep 17 00:00:00 2001 From: flemming-it Date: Tue, 27 Oct 2026 01:32:58 +0100 Subject: [PATCH] feat: idempotency key, the INTERRUPTED phase, and a real-hub skew suite The hub now takes an idempotency key and reports INTERRUPTED for a run its process did not survive, so the client exposes both. The real-hub suite gained the cross-language half of the idempotency guard: a repeated key has to answer with the first run's outputs, which only a real hub can prove. Signed-off-by: flemming-it --- proto/CHECKSUMS | 2 +- proto/chain/v1/hub.proto | 4 ++++ src/client.ts | 14 +++++++++++++- test/real_hub.test.ts | 21 +++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/proto/CHECKSUMS b/proto/CHECKSUMS index 457d47f..f85aead 100644 --- a/proto/CHECKSUMS +++ b/proto/CHECKSUMS @@ -1,4 +1,4 @@ 98a68dd39de4f98d965baf87eca60acc53bb393bd90ae9feb2c07b98071823d9 chain/v1/common.proto -b38ade1faa50cd5e645b040001b3d2e32b287b128556694837a1a30083b8416e chain/v1/hub.proto +78964aaff179fc43d59776a0f81e57197aff3f1ae61fabdc4b186abfdb4279d6 chain/v1/hub.proto 1b2742775d3abe0bcbdcb4a56c14b434e8547f672ea10a7f648ad14c7e14bef7 chain/v1/module.proto 47d3af9df026a40f5f5a76311965f719e3ceb49ad944c4393e02158a0bdb1873 chain/v1/federation.proto diff --git a/proto/chain/v1/hub.proto b/proto/chain/v1/hub.proto index 8519776..831d2a3 100644 --- a/proto/chain/v1/hub.proto +++ b/proto/chain/v1/hub.proto @@ -439,6 +439,10 @@ message InvocationStatus { SUCCEEDED = 3; FAILED = 4; CANCELLED = 5; + // The hub went down while this run was executing (added in hub + // 0.25). The run did not finish and did not fail on its own; a + // caller that owns the work decides whether to submit it again. + INTERRUPTED = 6; } Phase phase = 1; // Step currently executing (RUNNING), empty otherwise. diff --git a/src/client.ts b/src/client.ts index ed2898d..286659c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -77,7 +77,19 @@ export interface FlowResult { /** Where a detached run stands. */ export interface InvocationStatus { - phase: 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'CANCELLED' | 'PHASE_UNKNOWN'; + /** + * `INTERRUPTED` means the hub went down while this run was + * executing: it neither finished nor failed on its own, and the + * caller that owns the work decides whether to submit it again. + */ + phase: + | 'PENDING' + | 'RUNNING' + | 'SUCCEEDED' + | 'FAILED' + | 'CANCELLED' + | 'INTERRUPTED' + | 'PHASE_UNKNOWN'; /** Step currently executing, empty unless running. */ currentStep: string; startedAt: string; diff --git a/test/real_hub.test.ts b/test/real_hub.test.ts index e36454d..4d87e1a 100644 --- a/test/real_hub.test.ts +++ b/test/real_hub.test.ts @@ -111,6 +111,27 @@ describe('client against a real hub', { skip: available ? false : `no hub binary assert.equal(err.retryable, false); }); + it('answers a repeated idempotency key with the first run', async () => { + // The cross-language half of the idempotency guard: the field has + // to survive this client's encoding and the hub's decoding, which + // the fake hub cannot prove. + const key = `e2e-${Date.now()}`; + const first = await client.submit({ + flowYaml: HELLO, + inputs: { name: 'first' }, + idempotencyKey: key, + }); + const again = await client.submit({ + flowYaml: HELLO, + inputs: { name: 'second' }, + idempotencyKey: key, + }); + assert.equal(again.invocationId, first.invocationId); + // The replay answers with what the first run produced, not with + // the second request's input. + assert.equal(asText(again.outputs.greeting), 'Hello, first'); + }); + it('refuses a flow whose module is not installed, as not_found', async () => { const err = (await client .submit({