-
Notifications
You must be signed in to change notification settings - Fork 0
FE-763: Petrinaut event stream — initial markings + transition firings #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ka/fe-762-petri-blueprint-export
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,14 +65,24 @@ export type FiringPolicy = 'serial' | 'parallel'; | |
| /** Event kinds aligned with spec doc §7. */ | ||
| export type NetEventKind = 'transition_fired' | 'net_deadlocked' | 'net_halted'; | ||
|
|
||
| /** Structured event emitted during net execution. */ | ||
| /** | ||
| * Structured event emitted during net execution. | ||
| * | ||
| * `consumed` / `produced` are place-name lists (one entry per arc). The | ||
| * parallel `consumedTokens` / `producedTokens` carry the actual tokens | ||
| * that traversed each arc, indexed the same way — they are populated for | ||
| * `transition_fired` events so downstream adapters (e.g. the FE-763 | ||
| * Petrinaut event stream) can include token payload in the wire format. | ||
| */ | ||
| export type NetEvent = { | ||
| kind: NetEventKind; | ||
| ts: string; | ||
| transitionId?: string; | ||
| contract?: TransitionContract; | ||
| consumed?: string[]; | ||
| consumedTokens?: Token[][]; | ||
| produced?: string[]; | ||
| producedTokens?: Token[][]; | ||
| }; | ||
|
|
||
| /** Sink for structured net events. Optional — defaults to no-op. */ | ||
|
|
@@ -138,11 +148,14 @@ export class PetriNet { | |
| transitionId: string, | ||
| contract: TransitionContract | undefined, | ||
| consumedPlaces: string[], | ||
| consumedTokens: Token[], | ||
| work: Promise<{ place: string; token: Token }[]>, | ||
| ): void { | ||
| this.pendingDeferred++; | ||
| work | ||
| .then((outputs) => this.completeDeferred(transitionId, contract, consumedPlaces, outputs)) | ||
| .then((outputs) => | ||
| this.completeDeferred(transitionId, contract, consumedPlaces, consumedTokens, outputs), | ||
| ) | ||
| .catch((err) => { | ||
| this.deferredError ??= err; | ||
| this.pendingDeferred--; | ||
|
|
@@ -154,20 +167,25 @@ export class PetriNet { | |
| transitionId: string, | ||
| contract: TransitionContract | undefined, | ||
| consumedPlaces: string[], | ||
| consumedTokens: Token[], | ||
| outputs: { place: string; token: Token }[], | ||
| ): void { | ||
| const producedPlaces: string[] = []; | ||
| const producedTokens: Token[][] = []; | ||
| for (const { place, token } of outputs) { | ||
| this.addToken(place, token); | ||
| producedPlaces.push(place); | ||
| producedTokens.push([token]); | ||
| } | ||
| this.deferredEventSink?.emit({ | ||
| kind: 'transition_fired', | ||
| ts: new Date().toISOString(), | ||
| transitionId, | ||
| contract, | ||
| consumed: consumedPlaces, | ||
| consumedTokens: consumedTokens.map((t) => [t]), | ||
| produced: producedPlaces, | ||
| producedTokens, | ||
| }); | ||
| this.pendingDeferred--; | ||
| this.wakeOneWaiter(); | ||
|
|
@@ -273,22 +291,26 @@ export class PetriNet { | |
| } | ||
|
|
||
| private depositClaim( | ||
| { transition, consumed: _consumed }: TransitionClaim, | ||
| { transition, consumed }: TransitionClaim, | ||
| outputs: { place: string; token: Token }[], | ||
| eventSink?: NetEventSink, | ||
| ): void { | ||
| const producedPlaces: string[] = []; | ||
| const producedTokens: Token[][] = []; | ||
| for (const { place, token } of outputs) { | ||
| this.addToken(place, token); | ||
| producedPlaces.push(place); | ||
| producedTokens.push([token]); | ||
| } | ||
| eventSink?.emit({ | ||
| kind: 'transition_fired', | ||
| ts: new Date().toISOString(), | ||
| transitionId: transition.id, | ||
| contract: transition.contract, | ||
| consumed: transition.inputs, | ||
| consumedTokens: consumed.map((t) => [t]), | ||
| produced: producedPlaces, | ||
| producedTokens, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deferred handlers emit duplicate transition_fired events with consumed tokensMedium Severity For deferred fire handlers (action, run-tests, assess-semantic, verify-epic), Additional Locations (1)Reviewed by Cursor Bugbot for commit 9c0641c. Configure here. |
||
| }); | ||
| } | ||
|
|
||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test description mentions
net_halted, but the assertions below expect zeronet_halted/net_deadlockedevents on the happy path; consider updating the description to match the intended behavior.Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.