← Back to Pull requests

feat(server): a --workers flag — one process per CPU-bound read path #507

Merged
smith-xyz merged 3 files (79 lines) on Nov 18, 2026 04:15 UTC
View on GitHub
smith-xyz smith-xyz commented on Nov 18, 2026 03:58 UTC
Author

What


  • traust-server --workers N (default 1, nothing changes without it): uvicorn multi-process via an import-string factory; the config path rides TRAAST_SERVER_CONFIG to each spawned worker, which rebuilds the app (feeds, rate card) exactly as the single-process path does

  • make serve / make serve-local take WORKERS=N

  • Cut from main, one commit — no development drift (supersedes #506, which carried the development branch's history)
  • Why


    The insight reads are CPU-bound and serialize in one process. Measured on the rig (350,100 findings, 7 concurrent dashboard reads): 29.4s p50 single-process, 14.2s at 4 workers, +76% throughput, zero failures — while stage shows core at a third of its 2-CPU limit, unable to use the rest. Relief, not a fix: the read-time root causes (SQL batch tax, the 7.55MB report-shaped payload) are on the schema-audit plan's sequence and unaffected by process count.

    Tests


    make lint clean, make test 13,692 passed on this branch (main's suite). Smoke: make serve-local WORKERS=2 + make token + curl → 200 (both workers bootstrapped).

    Deployment note


    No image change: the exec-form ENTRYPOINT takes --workers N via pod args. Check the memory limit first (stage: 1.9Gi of 4Gi at one process) and count pool multiplication (N x 15) against the DB's 181 max_connections.

    Plan


    traust-foundry plans/stable-platform/features/2026-11-schema-performance-audit.md (session checkpoint: the worker receipt and its caveats)

    Diff: 79 lines (+72 / -7) across 3 files Reviewer: gurnben Review duration: 17m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.32) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.32 · 79 lines diff across 3 files
    0.32
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.94 · 4 substantive comment(s)
    0.94
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.262
    Real PR Conversation Timeline
    6 items
    qodo-for-traust-sci[bot] qodo-for-traust-sci[bot] commented on Nov 18, 2026 03:59 UTC
    Bot

    <h3>PR Summary by Qodo</h3>

    Add configurable Uvicorn worker processes to traust-server

    <!-- qodo-describe-risk-badge -->
    <!-- /qodo-describe-risk-badge -->
    <code>✨ Enhancement</code> <code>🕐 40+ Minutes</code>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">

    <details>
    <summary>AI Description</summary>

    <dl>
    <dd>
    <br/>

    ><pre>
    >• Add <b><i>--workers</i></b> to let CPU-bound dashboard reads run across multiple server processes.
    >• Rebuild each worker’s app from its config path, preserving feed and rate-card setup.
    >• Support <b><i>WORKERS=N</i></b> in Make targets; deployments remain single-process by default.
    ></pre>

    </dd>
    </dl>

    </details>

    <!-- qodo-describe-risk-slot -->

    <details>
    <summary>Diagram</summary>

    <dl>
    <dd>

    <br/>

    graph TD
      CLI["Server CLI"] --> Single["Single process"] --> Bootstrap["App bootstrap"] --> API["FastAPI app"]
      CLI --> Workers["Uvicorn workers"] --> Factory["Worker factory"] --> Bootstrap
      Config[("Config YAML")] --> Factory
      Config --> Bootstrap
    

    </dd>
    </dl>

    </details>

    <details>
    <summary>High-Level Assessment</summary>

    <dl>
    <dd>

    <br/>

    >The following are alternative approaches to this PR:

    <details>
    <summary><b>1. Use the importable factory for every worker count</b></summary>

    <dl>
    <dd>

  • ➕ One startup path reduces differences between single- and multi-process serving.

  • ➖ Changes the existing default startup path and requires config handoff even for one process.
  • </dd>
    </dl>

    </details>

    >Recommendation: Keep the PR’s split startup paths to preserve default behavior, with shared app bootstrap to limit divergence. Review worker-count sizing against per-process memory use and database connection pools before deployment.

    </dd>
    </dl>

    </details>

    <details>
    <summary> Files changed (2) <code> +48 / -7 </code> </summary>

    <dl>
    <dd>

    <br/>

    <details>
    <summary>Enhancement (2) <code> +48 / -7 </code></summary>

    <dl>
    <dd>

    <details>
    <summary>Makefile<code>Expose worker count in server Make targets</code> <code>+2/-2</code></summary>

    <br/>

    >Expose worker count in server Make targets

    ><pre>

    >• &#x27;make serve&#x27; and &#x27;make serve-local&#x27; pass &#x27;--workers&#x27; when &#x27;WORKERS&#x27; is supplied. Without it, both targets retain their existing invocation behavior.
    ></pre>
    ><a href='https://github.com/traust-security/traust-core/pull/507/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52'>Makefile</a>

    </details>

    <details>
    <summary>server.py<code>Add multi-process startup with per-worker app creation</code> <code>+46/-5</code></summary>

    <br/>

    >Add multi-process startup with per-worker app creation

    ><pre>

    >• Adds a default-one &#x27;--workers&#x27; option and uses Uvicorn’s importable factory for multi-process serving. Spawned workers reload the config path from the environment and share the existing feed and rate-card bootstrap with single-process serving.
    ></pre>
    ><a href='https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775'>src/traust_core/v1/rest/server.py</a>

    </details>

    </dd>
    </dl>

    </details>

    </dd>
    </dl>

    </details>

    <!-- qodo-describe-head:63b7be86a8713f302c87c6ddfc7fe83b5530f14b -->

    qodo-for-traust-sci[bot] qodo-for-traust-sci[bot] commented on Nov 18, 2026 04:01 UTC
    Bot

    <h3>Code Review by Qodo</h3>

    <br/>

    <details><summary><ins><strong>View medium (4)</strong></ins></summary><br/>
    <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">

    <details>
    <summary> 1. Two new helpers lack return type hints <code>📜 Skill insight</code></summary>

    <br/>

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    >The newly added functions <b><i>_app</i></b> and <b><i>_worker_app</i></b> in <b><i>server.py</i></b> declare no return annotation,
    >although the rule requires one on every function. The gap is triggered on every call, and
    ><b><i>_worker_app</i></b> is the factory uvicorn invokes in each spawned worker, so its untyped return hides the
    >app type from type checkers and later readers.
    ></pre>
    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >Issue description
    >The new functions `_app` and `_worker_app` in `src/traust_core/v1/rest/server.py` have no return type annotation. Checklist rule 6146 requires every function to declare its return type.
    >
    >Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[56-58]
    >- src/traust_core/v1/rest/server.py[76-83]
    >
    >Recommended Fix
    >Add a return annotation to `_app` and `_worker_app`. Use the type that `create_app` in `traust_core/v1/rest/app.py` declares as its return type, and import it under `TYPE_CHECKING` if the REST extra is optional at import time.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    </details>

    <details>
    <summary> 2. Workers can serve the wrong configuration <code>🐞 Bug</code></summary>

    <br/>

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>main()</i></b> leaves <b><i>TRAAST_SERVER_CONFIG</i></b> untouched when <b><i>--config</i></b> is omitted, while <b><i>_worker_app()</i></b>
    >treats any inherited value as the worker’s config path. If that variable is already set, the parent
    >selects <b><i>Config()</i></b> but every spawned worker loads the named file, which can change their database,
    >identity settings, and adjacent rate card.
    ></pre>
    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >An inherited `TRAAST_SERVER_CONFIG` changes the configuration of multi-worker serving when the CLI omits `--config`, despite the parent selecting the default configuration.
    >
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[39-53]
    >- src/traust_core/v1/rest/server.py[76-83]
    >
    >## Recommended Fix
    >Make the worker configuration handoff explicit for both cases: set the path when provided and remove any inherited handoff value when absent. Add a regression test that sets the environment variable, starts the multi-worker path without `--config`, and checks that the factory uses the default configuration.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    </details>

    <details>
    <summary> 3. Workers load config outside Context <code>📜 Skill insight</code></summary>

    <br/>

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>_worker_app</i></b> reads <b><i>TRAAST_SERVER_CONFIG</i></b> from the environment and calls <b><i>Config.from_file</i></b> inside
    >the REST adapter module, instead of Context performing that read and injecting the result. Every
    >spawned worker runs this path, so a later change to config loading must also find and update this
    >second loader.
    ></pre>
    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >The multi-worker bootstrap in `src/traust_core/v1/rest/server.py` reads `TRAAST_SERVER_CONFIG` from the environment and loads `Config` itself inside `_worker_app`. Compliance rule 6199 requires configuration and environment reads to be performed by Context, which then injects the values.
    >
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[82-83]
    >- src/traust_core/v1/rest/server.py[56-84]
    >
    >## Recommended Fix
    >Keep the environment handoff only at the process boundary, since uvicorn spawned workers cannot receive the object. Move the environment read and `Config.from_file` call into a single Context-owned factory, or have the existing config loader resolve the path, and have `_worker_app` call that. Add a test that asserts the worker factory obtains its config through that owner, so the adapter performs no direct environment or file reads.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    </details>

    <details>
    <summary> 4. Concurrent workers can lose rotated logs <code>🐞 Bug</code></summary>

    <br/>

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>_app()</i></b> installs a separate <b><i>RotatingFileHandler</i></b> in each worker, with every handler targeting the
    >same configured log file and backup names. When multiple workers reach the size threshold, their
    >independent rollover operations can race over those files, losing rotated records or producing
    >logging errors; the default configuration enables file logging.
    ></pre>
    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >Multi-worker serving gives independent rotating handlers ownership of one log file and its backups, so simultaneous rollovers can collide.
    >
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[39-50]
    >- src/traust_core/v1/rest/server.py[56-73]
    >- src/traust_core/v1/context/logging.py[154-174]
    >
    >## Recommended Fix
    >For multi-worker serving, route file logs through one process-safe writer or use distinct per-worker files with an aggregation strategy; do not let independent rotating handlers manage the same backup names. Add focused coverage for the selected multi-worker logging setup and rollover behavior.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    </details>

    </details>

    <br/>

    <!-- qodo-self-review-slot -->
    <!-- https://github.com/traust-security/traust-core/commit/3fe400f8466eb38f180fd70dc95cb169a2da2149 -->

    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 18, 2026 04:03 UTC
    Bot

    <h3>Code Review by Qodo</h3>

    <code>🐞 Bugs (5)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">

    <br/>

    <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">

    <details>
    <summary> 1. Invalid worker counts start one process <code>🐞 Bug</code> <code>≡ Correctness</code> <code>⭐ New</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>--workers</i></b> accepts any integer, but <b><i>main()</i></b> enters the multi-process path only when args.workers
    >&gt; 1<b><i>. Passing </i></b>--workers 0<b><i> or a negative count, including through </i></b>make serve WORKERS=0
    , starts a
    >single-process server instead of rejecting the invalid setting.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R106-108]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R106-R108)</code>

    >
    >+        "--workers",
    >+        type=int,
    >+        default=1,
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The new argument uses <b><i>type=int</i></b> without a lower bound; the new branch checks only <b><i>&gt; 1</i></b>, and all
    >other values call <b><i>uvicorn.run</i></b> without a workers argument. The Makefile forwards a supplied count
    >unchanged.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[105-111\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L105-L111)</code>

    <code>[src/traust_core/v1/rest/server.py\[37-51\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L37-L51)</code>

    <code>[Makefile\[142-150\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/Makefile/#L142-L150)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >The server silently serves with one process when `--workers` is zero or negative.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[105-111]
    >- tests/v1/rest/test_server.py[1-88]
    >## Recommended Fix
    >Validate that the parsed worker count is positive and fail through argparse for invalid values. Add regression cases for zero and negative counts, and retain the existing default of one.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <details>
    <summary> 2. Workers can lose logs during rotation <code>🐞 Bug</code> <code>◔ Observability</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    >Each worker calls <b><i>_app()</i></b> and installs its own rotating file handler for the same configured log
    >path without coordinating rollover with other processes. When workers cross the file-size threshold
    >together, competing renames can fail and drop the records that triggered rotation, even though
    >ordinary appends use separate append-mode descriptors.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R82-83]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R82-R83)</code>

    >
    >+    path = os.environ.get(_CONFIG_PATH)
    >+    return _app(Config.from_file(Path(path)) if path else Config(), Path(path) if path else None)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The factory runs logging setup independently in each process. That setup creates rotating handlers
    >for the same default file, with a 10 MB rollover threshold and only process-local synchronization.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[56-73\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L56-L73)</code>

    <code>[src/traust_core/v1/rest/server.py\[76-83\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L76-L83)</code>

    <code>[src/traust_core/v1/context/config.py\[133-145\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/config.py/#L133-L145)</code>

    <code>[src/traust_core/v1/context/logging.py\[18-23\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/logging.py/#L18-L23)</code>

    <code>[src/traust_core/v1/context/logging.py\[164-177\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/logging.py/#L164-L177)</code>

    <code>[src/traust_core/v1/context/logging.py\[204-224\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/logging.py/#L204-L224)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >Separate worker processes rotate the same default log file without cross-process coordination, risking dropped records at rollover.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[76-83]
    >- src/traust_core/v1/context/logging.py[164-177]
    >- src/traust_core/v1/context/logging.py[204-224]
    >## Recommended Fix
    >Use a process-safe logging and rotation strategy for multi-worker serving, or direct workers to an external log collector without silently discarding explicitly configured file output. Cover concurrent rollover with a multi-process regression test.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <details>
    <summary> 3. Workers can serve the wrong configuration <code>🐞 Bug</code> <code>≡ Correctness</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>main()</i></b> sets <b><i>TRAAST_SERVER_CONFIG</i></b> only when <b><i>--config</i></b> is supplied, but <b><i>_worker_app()</i></b> uses any
    >value already present in that environment variable. With <b><i>--workers</i></b> and no <b><i>--config</i></b>, an inherited
    >or stale value makes workers load a file while the parent selected <b><i>Config()</i></b> defaults, changing the
    >database and identity settings they serve.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R42-43]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R42-R43)</code>

    >
    >+        if args.config is not None:
    >+            os.environ[_CONFIG_PATH] = str(args.config)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The parent selects <b><i>Config()</i></b> without a CLI path, whereas the new worker factory independently
    >selects <b><i>Config.from_file()</i></b> whenever the environment variable has a value.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[23-26\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L23-L26)</code>

    <code>[src/traust_core/v1/rest/server.py\[39-43\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L39-L43)</code>

    <code>[src/traust_core/v1/rest/server.py\[76-83\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L76-L83)</code>

    <code>[src/traust_core/v1/context/config.py\[366-379\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/config.py/#L366-L379)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >Workers can inherit a configuration path that the current CLI invocation did not select.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[39-43]
    >- src/traust_core/v1/rest/server.py[76-83]
    >## Recommended Fix
    >Set the worker configuration transport deterministically for both explicit-config and default-config invocations, removing an inherited path in default mode. Test both modes with the environment variable initially populated.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <details><summary><ins><strong>View medium (1)</strong></ins></summary><br/>
    <details>
    <summary> 4. First requests can fail on a fresh server <code>🐞 Bug</code> <code>☼ Reliability</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    >The multi-worker path creates separate contexts whose database initialization can each observe an
    >empty local store and attempt the same schema bootstrap. When concurrent first requests reach
    >different workers, the losing schema creation raises a repository error rather than retrying against
    >the now-created database.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R48-49]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R48-R49)</code>

    >
    >+            workers=args.workers,
    >+            factory=True,
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >Each new worker builds its own context; database initialization occurs lazily on a request. The
    >empty-table check precedes unguarded DDL, whose driver errors become repository errors.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[39-51\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L39-L51)</code>

    <code>[src/traust_core/v1/rest/server.py\[76-83\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L76-L83)</code>

    <code>[src/traust_core/v1/rest/common/deps.py\[16-20\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/common/deps.py/#L16-L20)</code>

    <code>[src/traust_core/v1/context/context.py\[757-774\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/context.py/#L757-L774)</code>

    <code>[src/traust_core/v1/repositories/sql.py\[158-173\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/repositories/sql.py/#L158-L173)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >Concurrent workers can both attempt initial schema creation for the same empty local SQLite database, failing a first request.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[44-51]
    >- src/traust_core/v1/context/context.py[757-774]
    >- src/traust_core/v1/repositories/sql.py[158-173]
    >## Recommended Fix
    >Make initial bootstrap safe when another worker wins, verifying that the complete schema exists before accepting a competing bootstrap as successful. Add a concurrent-first-request regression test against an empty local database.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    </details>
    <br/>

    <img src="https://img.shields.io/badge/Low-634FD1?style=flat-square" height="20px" alt="Informational">

    <details>
    <summary> 5. Missing REST packages lose the helpful error <code>🐞 Bug</code> <code>☼ Reliability</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    >Moving the <b><i>create_app</i></b> import into <b><i>_app()</i></b> puts its <b><i>ModuleNotFoundError</i></b> outside the handler that
    >explains how to install the REST extra. If uvicorn is installed but FastAPI or Starlette is missing,
    >single-process startup now emits a raw import traceback instead of the previous installation
    >message.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R71-73]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R71-R73)</code>

    >
    >+    from traust_core.v1.rest.app import create_app
    >+
    >+    return create_app(context)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The handler now surrounds only <b><i>import uvicorn</i></b>; the relocated application import occurs later, and
    >the application module imports FastAPI and Starlette.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[29-37\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L29-L37)</code>

    <code>[src/traust_core/v1/rest/server.py\[53-73\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L53-L73)</code>

    <code>[src/traust_core/v1/rest/app.py\[1-12\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/app.py/#L1-L12)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >The relocated application import bypasses the existing missing-REST-extra error handler.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[29-37]
    >- src/traust_core/v1/rest/server.py[71-73]
    >## Recommended Fix
    >Keep missing REST dependency detection around application import in the single-process path, preserving the existing installation message without masking unrelated missing modules. Add a regression test for a partial REST-extra installation.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">

    <!-- qodo-self-review-slot -->

    <!-- qodo-context:start -->
    <details><summary><strong>Context sources</strong></summary>

    <div>&#x2705; Linked PRs:</div>
    <div>&nbsp;&nbsp;<code>🌐 PR #506</code></div>
    <div>Review mode: <code>Auto: ⚖️ Balanced</code>: Downgraded extended -&gt; standard: change is below the extended eligibility bar (hunks 5/18, lines 79/200; both must reach the floor). Router rationale: Multi-process startup, configuration, logging, and initialization create several independent defect paths.</div>
    <!-- qodo-context:end -->
    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">

    <!-- qodo-daily-tip:start -->

    <details>
    <summary><strong>Tip of the day</strong></summary>

    <br/>

    <pre>💡 Did you know, you can type &#x27;qodo, fix this&#x27; on a finding and the fix lands right on your PR</pre>

    <a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>

    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
    <!-- qodo-daily-tip:end -->

    <!-- https://github.com/traust-security/traust-core/commit/3fe400f8466eb38f180fd70dc95cb169a2da2149 -->

    <!-- qodo-previous-reviews:start -->
    <!-- FOLDED_SECTION_START -->

    <details>
    <summary><strong>Previous reviews</strong></summary>

    <br/>

    Review updated until commit <a href="https://github.com/traust-security/traust-core/commit/3fe400f8466eb38f180fd70dc95cb169a2da2149">3fe400f</a>

    <details><summary>Results up to commit 63b7be8 <code>⚖️ Balanced</code></summary>

    <br><code>🐞 Bugs (4)</code> <code>📘 Rule violations (0)</code> <code>📎 Requirement gaps (0)</code> <code>🎨 UX issues (0)</code> <code>🔗 Cross-repo conflicts (0)</code> <code>📜 Skill insights (0)</code>

    <br/>

    <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">

    <details>
    <summary> 1. First requests can fail on a fresh server <code>🐞 Bug</code> <code>☼ Reliability</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    >The multi-worker path creates separate contexts whose database initialization can each observe an
    >empty local store and attempt the same schema bootstrap. When concurrent first requests reach
    >different workers, the losing schema creation raises a repository error rather than retrying against
    >the now-created database.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R48-49]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R48-R49)</code>

    >
    >+            workers=args.workers,
    >+            factory=True,
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >Each new worker builds its own context; database initialization occurs lazily on a request. The
    >empty-table check precedes unguarded DDL, whose driver errors become repository errors.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[39-51\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L39-L51)</code>

    <code>[src/traust_core/v1/rest/server.py\[76-83\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L76-L83)</code>

    <code>[src/traust_core/v1/rest/common/deps.py\[16-20\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/common/deps.py/#L16-L20)</code>

    <code>[src/traust_core/v1/context/context.py\[757-774\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/context.py/#L757-L774)</code>

    <code>[src/traust_core/v1/repositories/sql.py\[158-173\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/repositories/sql.py/#L158-L173)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >Concurrent workers can both attempt initial schema creation for the same empty local SQLite database, failing a first request.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[44-51]
    >- src/traust_core/v1/context/context.py[757-774]
    >- src/traust_core/v1/repositories/sql.py[158-173]
    >## Recommended Fix
    >Make initial bootstrap safe when another worker wins, verifying that the complete schema exists before accepting a competing bootstrap as successful. Add a concurrent-first-request regression test against an empty local database.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <details>
    <summary> 2. Workers can lose logs during rotation <code>🐞 Bug</code> <code>◔ Observability</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    >Each worker calls <b><i>_app()</i></b> and installs its own rotating file handler for the same configured log
    >path without coordinating rollover with other processes. When workers cross the file-size threshold
    >together, competing renames can fail and drop the records that triggered rotation, even though
    >ordinary appends use separate append-mode descriptors.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R82-83]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R82-R83)</code>

    >
    >+    path = os.environ.get(_CONFIG_PATH)
    >+    return _app(Config.from_file(Path(path)) if path else Config(), Path(path) if path else None)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The factory runs logging setup independently in each process. That setup creates rotating handlers
    >for the same default file, with a 10 MB rollover threshold and only process-local synchronization.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[56-73\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L56-L73)</code>

    <code>[src/traust_core/v1/rest/server.py\[76-83\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L76-L83)</code>

    <code>[src/traust_core/v1/context/config.py\[133-145\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/config.py/#L133-L145)</code>

    <code>[src/traust_core/v1/context/logging.py\[18-23\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/logging.py/#L18-L23)</code>

    <code>[src/traust_core/v1/context/logging.py\[164-177\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/logging.py/#L164-L177)</code>

    <code>[src/traust_core/v1/context/logging.py\[204-224\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/logging.py/#L204-L224)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >Separate worker processes rotate the same default log file without cross-process coordination, risking dropped records at rollover.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[76-83]
    >- src/traust_core/v1/context/logging.py[164-177]
    >- src/traust_core/v1/context/logging.py[204-224]
    >## Recommended Fix
    >Use a process-safe logging and rotation strategy for multi-worker serving, or direct workers to an external log collector without silently discarding explicitly configured file output. Cover concurrent rollover with a multi-process regression test.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <details>
    <summary> 3. Workers can serve the wrong configuration <code>🐞 Bug</code> <code>≡ Correctness</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>main()</i></b> sets <b><i>TRAAST_SERVER_CONFIG</i></b> only when <b><i>--config</i></b> is supplied, but <b><i>_worker_app()</i></b> uses any
    >value already present in that environment variable. With <b><i>--workers</i></b> and no <b><i>--config</i></b>, an inherited
    >or stale value makes workers load a file while the parent selected <b><i>Config()</i></b> defaults, changing the
    >database and identity settings they serve.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R42-43]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R42-R43)</code>

    >
    >+        if args.config is not None:
    >+            os.environ[_CONFIG_PATH] = str(args.config)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The parent selects <b><i>Config()</i></b> without a CLI path, whereas the new worker factory independently
    >selects <b><i>Config.from_file()</i></b> whenever the environment variable has a value.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[23-26\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L23-L26)</code>

    <code>[src/traust_core/v1/rest/server.py\[39-43\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L39-L43)</code>

    <code>[src/traust_core/v1/rest/server.py\[76-83\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L76-L83)</code>

    <code>[src/traust_core/v1/context/config.py\[366-379\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/context/config.py/#L366-L379)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >Workers can inherit a configuration path that the current CLI invocation did not select.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[39-43]
    >- src/traust_core/v1/rest/server.py[76-83]
    >## Recommended Fix
    >Set the worker configuration transport deterministically for both explicit-config and default-config invocations, removing an inherited path in default mode. Test both modes with the environment variable initially populated.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <br/>

    <img src="https://img.shields.io/badge/Low-634FD1?style=flat-square" height="20px" alt="Informational">

    <details>
    <summary> 4. Missing REST packages lose the helpful error <code>🐞 Bug</code> <code>☼ Reliability</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    >Moving the <b><i>create_app</i></b> import into <b><i>_app()</i></b> puts its <b><i>ModuleNotFoundError</i></b> outside the handler that
    >explains how to install the REST extra. If uvicorn is installed but FastAPI or Starlette is missing,
    >single-process startup now emits a raw import traceback instead of the previous installation
    >message.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/rest/server.py[R71-73]](https://github.com/traust-security/traust-core/pull/507/files#diff-887c95782b00c1b6801c3fd49a5fd0ea0aec6dc77042f0b0eb8df643c7d4a775R71-R73)</code>

    >
    >+    from traust_core.v1.rest.app import create_app
    >+
    >+    return create_app(context)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The handler now surrounds only <b><i>import uvicorn</i></b>; the relocated application import occurs later, and
    >the application module imports FastAPI and Starlette.
    ></pre>
    > <code>[src/traust_core/v1/rest/server.py\[29-37\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L29-L37)</code>

    <code>[src/traust_core/v1/rest/server.py\[53-73\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/server.py/#L53-L73)</code>

    <code>[src/traust_core/v1/rest/app.py\[1-12\]](https://github.com/traust-security/traust-core/blob/3fe400f8466eb38f180fd70dc95cb169a2da2149/src/traust_core/v1/rest/app.py/#L1-L12)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >The relocated application import bypasses the existing missing-REST-extra error handler.
    >## Fix Focus Areas
    >- src/traust_core/v1/rest/server.py[29-37]
    >- src/traust_core/v1/rest/server.py[71-73]
    >## Recommended Fix
    >Keep missing REST dependency detection around application import in the single-process path, preserving the existing installation message without masking unrelated missing modules. Add a regression test for a partial REST-extra installation.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <!-- qodo-self-review-slot -->

    </details>

    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
    <!-- qodo-previous-reviews:end -->

    <a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>

    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 18, 2026 04:06 UTC
    Bot
    gurnben gurnben approved these changes on Nov 18, 2026 04:11 UTC
    Approved Reviewer

    /lgtm
    /approve

    Reviewers
    Assignees
    smith-xyz smith-xyz
    Labels
    risk: low confidence: 87.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 32.1% (LOW) · Higher = larger blast radius
    32.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.2% · Lower = rushed or shallow review
    87.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.1% · Safe to merge
    4.1%