fix(inbound-api): ScriptLog durable write before the Live sink; prove the central write (Task 8 review)
This commit is contained in:
@@ -435,24 +435,40 @@ public class InboundScriptExecutor
|
||||
|
||||
// Flow Debugger step logs (design 2026-09-09 D4/D5/D7): the script's Log global.
|
||||
// Lines ALWAYS reach this node's logger; only a TRACED execution also builds
|
||||
// ScriptTrace/ScriptLog rows, which are fanned out to the Live run's inline sink and
|
||||
// written best-effort to the central store for Replay — exactly as RouteHelper does
|
||||
// for its RouteCall row. The row cap comes from options when they are available
|
||||
// (the sandbox/test providers that register none fall back to the documented default).
|
||||
var maxLogLines = scope?.ServiceProvider
|
||||
.GetService<IOptionsMonitor<InboundApiOptions>>()?.CurrentValue.MaxLogLinesPerRun
|
||||
?? InboundApiOptions.DefaultMaxLogLinesPerRun;
|
||||
var logTraceSink = route.TraceSink;
|
||||
// ScriptTrace/ScriptLog rows, which are written best-effort to the central store for
|
||||
// Replay and then handed to the Live run's inline sink — exactly as
|
||||
// RouteHelper.EmitRouteCall orders its RouteCall row. An untraced request builds no
|
||||
// delegate and resolves no extra service.
|
||||
var methodName = method.Name;
|
||||
scriptLogger = new InboundScriptLogger(
|
||||
_logger,
|
||||
emit: trace
|
||||
? evt =>
|
||||
var maxLogLines = InboundApiOptions.DefaultMaxLogLinesPerRun;
|
||||
Action<AuditEvent>? logEmit = null;
|
||||
if (trace)
|
||||
{
|
||||
// The row cap comes from options when they are available (a sandbox/test provider
|
||||
// that registers none falls back to the documented default).
|
||||
maxLogLines = scope?.ServiceProvider
|
||||
.GetService<IOptionsMonitor<InboundApiOptions>>()?.CurrentValue.MaxLogLinesPerRun
|
||||
?? InboundApiOptions.DefaultMaxLogLinesPerRun;
|
||||
var logTraceSink = route.TraceSink;
|
||||
logEmit = evt =>
|
||||
{
|
||||
// Durable first: the Replay row must never depend on the Live sink succeeding.
|
||||
WriteScriptLogBestEffort(auditWriter, evt, methodName);
|
||||
try
|
||||
{
|
||||
logTraceSink?.Invoke(evt);
|
||||
WriteScriptLogBestEffort(auditWriter, evt, methodName);
|
||||
}
|
||||
: null,
|
||||
catch (Exception)
|
||||
{
|
||||
// A debug observer must never fail the request: a misbehaving Live sink is
|
||||
// swallowed here so it cannot mask the durable write that already happened.
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
scriptLogger = new InboundScriptLogger(
|
||||
_logger,
|
||||
emit: logEmit,
|
||||
maxLines: maxLogLines,
|
||||
methodName: methodName,
|
||||
executionId: parentExecutionId,
|
||||
|
||||
Reference in New Issue
Block a user