fix(session): contain post-commit observers

This commit is contained in:
Tianyi Cui
2026-07-12 18:57:42 +08:00
parent 50873b8bd0
commit e8fed4fb66
31 changed files with 1166 additions and 475 deletions

View File

@@ -253,6 +253,12 @@ const DYNAMIC_EVENT_DISPATCHERS: Array<{ event: string; pkg: string; method: str
// and contains each listener directly rather than rebuilding via agentEvents.
{ event: 'agent/disposed', pkg: 'agent', method: 'events.dispatch' },
{ event: 'session/created', pkg: 'session', method: 'events.dispatch' },
// Session event callbacks are likewise resolved before the log push, then
// invoked individually after commit so observer failures are contained.
{ event: 'session/event', pkg: 'session', method: 'events.dispatch' },
// Flush resolves the scoped callback set directly so internal instrumentation
// cannot substitute the accepted session before parallel invocation.
{ event: 'session/flush', pkg: 'session', method: 'events.dispatch' },
// Session disposal uses direct callback resolution so teardown contains each
// synchronous throw and returned-promise rejection independently.
{ event: 'session/disposed', pkg: 'session', method: 'events.dispatch' },
@@ -278,6 +284,12 @@ const DYNAMIC_EVENT_DISPATCHERS: Array<{ event: string; pkg: string; method: str
{ event: 'workflow/end', pkg: 'workflow', method: 'events.dispatch' },
]
const DYNAMIC_EVENT_LISTENERS: Array<{ event: string; pkg: string }> = [
// The invariants oracle marks the session started from its global
// internal/dispatch listener before product session-start callbacks run.
{ event: 'agent/session-start', pkg: 'invariants' },
]
function generatedHeader(title: string): string[] {
return [
'<!-- Generated by scripts/gen-doc-graphs.ts - do not edit by hand.',
@@ -596,6 +608,9 @@ function collectEventRelations(): Map<string, EventRelation> {
methods.add(entry.method)
relation.dispatchers.set(entry.pkg, methods)
}
for (const entry of DYNAMIC_EVENT_LISTENERS) {
ensure(entry.event).listeners.add(entry.pkg)
}
return out
}