feat(app): service dependency graph with fail-fast and topological startup#17
Merged
BlindMaster24 merged 4 commits intoApr 27, 2026
Merged
Conversation
5cf7b0f to
1d3c58f
Compare
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
d3f59a0 to
62a43bf
Compare
This was referenced Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Declarative service dependency graph for
src/app.ts. Every service now declares required/optional deps in one place; the app validates them at construction (fail-fast with a clear message) and boots services in topological order — both locally and inside Docker.Why: previously
config.serviceswas accepted as-is, so disablinghttpwhileapiwas on would pass constructor, then crash deep inApi.run()withService 'http' not registered. With the graph declared explicitly, anyconfig.servicescombination is safe: invalid combos fail at boot with the exact list of missing edges; valid combos start dependencies before dependents automatically.What's new:
src/services/registry.ts:serviceDependencies: Record<AppServiceName, { required, optional }>— single source of truth for the graph. Current edges:api,alice,vkApp→http(required)viber→bot,http(required)tg,vk→bot(required);image,timetable(optional)google_calendar→http,bot(required)timetable→parser(optional);image→http(optional)http,parser,bot— no required depsvalidateServiceDependencies(enabled)— throwsServiceDependencyErrorlisting every missing edge. Example:topologicalSort(enabled)— Kahn's algorithm with input-order-stable tie-breaking. ThrowsServiceCycleErrorif a cycle is ever introduced.src/app.ts: constructor callsvalidateServiceDependencies+topologicalSortbefore registering services, sonew App(['api'])fails immediately instead of crashing mid-boot.Behavior changes (all positive, no API break):
config.services: ['api']→ now fails at boot with "'api' requires 'http'" instead of a stack trace insideapi/run().config.services.timetablewithoutparserstill runs self-heal, just skipsflushCache).Tests (
tests/services/registry.test.ts, 15 new cases):validateServiceDependencies: empty list, all deps present, missing required dep throws, multi-missing reports every edge, optional missing ignored.topologicalSort: empty input, required dep ordering, optional dep ordering (parser → timetable), realistic production set, stable under input permutations.Verification:
pnpm run test:all— 30 files / 202 tests passedpnpm run ts-check— cleanpnpm run lint— cleanpnpm run format:check— cleanpnpm audit --audit-level=low— no known vulnerabilitiesStacked on PR #16 (Docker).
Review & Testing Checklist for Human
config.services = ['api']inconfig.tsand runpnpm start— expectServiceDependencyErrorwith "'api' requires 'http' to be enabled" at boot (no stack trace from insideapi/run()).['http', 'parser', 'timetable', 'bot', 'tg', 'image', 'api']) still starts cleanly; log line "Загруженные сервисы: ..." shows services in dependency order.config.services = ['http', 'api', 'timetable']+docker compose up— expecthealthywith no bot code running.Notes
/api/healthso operators cancurlto see what's running.Link to Devin session: https://app.devin.ai/sessions/7732f5fd16e9448295cbabeb8b5f471a
Requested by: @BlindMaster24