Repository navigation
Description
Summary
The SpaceBattle demo's documented deep-profiling switch does not work. Flipping EnableDeepProfiling to true produces no trace file, no warning, and no error — the run completes normally and silently writes nothing.
The engine is not at fault: TYPHON__PROFILER__TRACE works correctly when set before process start. The bug is that the demo sets it inside Main, by which point Typhon.Engine's [ModuleInitializer] has already read and frozen the configuration.
Where it breaks
ProfilerBootstrap.Initialize runs at assembly load and calls TelemetryConfig.EnsureInitialized(), which builds the merged configuration (typhon.telemetry.json overlaid with TYPHON__PROFILER__*) once and caches it. ProfilerLaunchConfig.FromConfiguration then reads Typhon:Profiler:Trace from that frozen snapshot.
Program.ConfigureDeepProfiling sets the variables from inside Main:
// 必须先于 Typhon.Engine 的静态 telemetry 初始化设置,避免 JIT 固化关闭的事件门控。
Environment.SetEnvironmentVariable("TYPHON__PROFILER__ENABLED", "true");
Environment.SetEnvironmentVariable("TYPHON__PROFILER__TRACE", SpaceBattleProductionSettings.GetProfilerTracePath(databaseLocation));The comment anticipates exactly this hazard — but Main is itself too late, because Main references engine types and so triggers the assembly load (and its module initializer) before its first statement runs. Typhon:Profiler:Trace stays null, no output channel is opened, and the profiler produces nothing.
Reproduction — verified both ways
Same binary, same variable, only the timing differs:
How TYPHON__PROFILER__TRACE is set |
Result |
|---|---|
| Externally, before process start | ✅ trace written (8.4 MB for 500 ships × 60 ticks) |
Inside Main via ConfigureDeepProfiling (current code) |
❌ no file, no warning, exit code unchanged |
# Fails silently — current documented path
# (EnableDeepProfiling = true in Program.cs)
dotnet run --project demo/SpaceBattle/SpaceBattle.Main -c Release
# Works
TYPHON__PROFILER__TRACE=ext.typhon-trace ./SpaceBattle.Main.exeAdding "Trace": "default.typhon-trace" to a typhon.telemetry.json beside the assembly also works, since that file is read during the same static init.
Impact
doc/demos/space-battle.mddocuments this switch as the way to emit a.typhon-trace. As written it cannot work, so the demo's profiling story is unusable as documented.- SpaceBattle ships no
typhon.telemetry.json, so even when the profiler is enabled every sub-gate (GcTracing, CpuSampling, Scheduler, Runtime, ECS, Spatial, …) stays at its disabled default. Both AntHill projects carry one; SpaceBattle was never given the equivalent. - The failure mode is the problem as much as the bug: a user follows the documentation, gets a clean run and no output, with nothing pointing at the cause.
Suggested fix
- Demo: add
demo/SpaceBattle/SpaceBattle.Main/typhon.telemetry.json(mirroring AntHill's gate set) with aTracekey, wired via<Content Include="typhon.telemetry.json" CopyToOutputDirectory="PreserveNewest" />. DropConfigureDeepProfiling's env-var writes, or keep them only as an override documented as "must be set before launch". - Docs: correct
doc/demos/space-battle.md:77to describe the config-file / pre-launch-env route. - Engine (the durable fix): make the silent case observable. When
TelemetryConfig.ProfilerActiveis true but no output channel resolved, emit one warning atProfilerBootstrap.TryStart— "profiler enabled but no Trace/Live channel configured; no output will be produced". That converts a silent no-op into a one-line diagnostic and would have caught this immediately.
Optionally, TelemetryConfig could expose whether a late Environment.SetEnvironmentVariable was ignored, but the warning above covers the realistic case.
Notes
Found while configuring the demo for a tracing run during a review of demo/SpaceBattle/. With the config-file route in place the demo traces correctly — a 10,000-ship × 800-tick run produced a valid 1.02 GiB TYTR v11 trace including 811,347 CPU samples, so nothing else in the profiling path is broken.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Estimate
Area
Start date
Target date
Bug status
Product
Projects
- StatusShow more project fieldsDone
Activity
nockawa commentedon Aug 14, 2026
Engine fix landed (03bf261); the demo half is already done on the demo branch; one new trap found
③ Engine — done
ProfilerBootstrap.TryStartreturned silently when the master switch was on and neitherTracenorLiveresolved. It now emits one diagnostic, once per process, onConsole.Error:The last sentence is the part that is not guessable from the symptom, and it is the whole reason this issue exists.
Console.Errorrather than[LoggerMessage]is deliberate:ProfilerBootstrapis a static pre-DI bootstrap with noILogger, and the startup-failure path a few lines below already usesConsole.Error— a host with no logging configured is precisely the host that needs to see this. Say the word if you would rather it went through a logger.BuildInertProfilerWarningis a purenull-or-text function with the one-shot latch left in the caller, so its 8 tests need neither the frozenTelemetryConfigsingleton norConsoleredirection — both of which would have made them order-dependent under parallel fixtures.① and ② — the premise has moved
This issue states SpaceBattle ships no
typhon.telemetry.json. Onfeature/796-simple-space-battleit does, with"Enabled": trueand"Trace": "default.typhon-trace"already set — i.e. the config-file route this issue recommends has since been implemented. I traced the demo successfully through exactly that path today.doc/demos/space-battle.mddoes not exist onmainor on the demo branch (doc/demos/holds onlyanthill.md,index.md,toc.yml), so ② has nothing to correct. Note also that neitherdemo/SpaceBattlenordemo/SimpleSpaceBattleexists onmain— everyblob/main/demo/…link in this issue is a 404.Suggest closing once someone confirms ①, since ③ has landed and ② has no target.
A new trap, worth its own issue
Program.EnableDeepProfilingis aconst bool = false, andBuildDefinition()gates the tick and ship-count overrides behind it:So with the const off,
SPACEBATTLE_TRACE_TICKSandSPACEBATTLE_TRACE_SHIPSare silently ignored and the run falls back toDefaultMaximumCompletedTicks = 45_000— about 4.5 hours at this demo's ~200 ms/tick. Anyone trying to take a bounded trace hits that with no indication why. Filing separately.Second, smaller: the run persists its state, and a prior
TimedOutrun makes the next launch throwSimulationRun 状态 TimedOut 不可恢复. The database has to be cleared between bounded runs.#792 #803 #696 #802 Four bug-bash fixes, and three performance issues…
nockawa commentedon Aug 15, 2026
Closing — all three parts are resolved.
Mainconstraint.feature/796-simple-space-battle:SpaceBattle.Main/typhon.telemetry.jsoncarries"Enabled": trueand"Trace": "default.typhon-trace". Verified by using exactly that route to capture a.typhon-tracefrom the demo.doc/demos/space-battle.mddoes not exist onmainor on the demo branch, so there is nothing to correct.The residual traps found while confirming this are filed as #806 (the
EnableDeepProfilingconst silently disabling the tick/ship overrides, and the non-resumableTimedOutrun) rather than kept here.