Skip to content

feat: display 'Player #' in logs to distinguish log messages from different Conductors - #302

Merged
mattyg merged 7 commits into
fix/dht-sync-timing-outfrom
feat/player-id-in-logs
Oct 16, 2025
Merged

feat: display 'Player #' in logs to distinguish log messages from different Conductors#302
mattyg merged 7 commits into
fix/dht-sync-timing-outfrom
feat/player-id-in-logs

Conversation

@mattyg

@mattyg mattyg commented Oct 13, 2025

Copy link
Copy Markdown
Member

Summary

Adds a "label" string to the prefix string in conductor log messages. For conductors created by the addPlayers, addPlayersWithApps, or addPlayersWithSameApp functions, the label defaults to "Player X" (where X is the index of when the player was created, starting from 0).

image

I'm not sure of a good way to test this. If others think its important to have tests on it I can dig in further.

(merging into fix/dht-sync-timing-out for a clean diff)

TODO:

  • CHANGELOG mentions all code changes.
  • docs have been updated (npm run build && git add docs)

Summary by CodeRabbit

  • New Features

    • Optional label support for conductors and apps to tag and filter logs.
    • Scenario helpers auto-assign readable labels to players/apps (e.g., “Player 1”).
    • addConductor now accepts an optional label parameter to override defaults.
    • AppWithOptions includes an optional label field.
  • Refactor

    • Logging is now scoped per conductor instance and includes the provided label for clearer, isolated log output.

@coderabbitai

coderabbitai Bot commented Oct 13, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds an optional label for conductors and threads it into conductor creation and scenario helpers; replaces the module-scoped logger with a per-Conductor instance logger so each Conductor logs using its label. Documentation and CHANGELOG updated accordingly.

Changes

Cohort / File(s) Summary of Changes
Conductor code (label + per-instance logging)
ts/src/conductor.ts
Added optional label to ConductorOptions and CreateConductorOptions. createConductor forwards label. Conductor constructor accepts label?, constructs a per-instance logger (this._logger), and replaces module-scoped logger usages with the instance logger.
Scenario code (propagate labels to conductors / players)
ts/src/scenario.ts
Added label?: string to AppWithOptions. addConductor now accepts label?: string and passes it into conductor creation. Player helper methods generate and pass per-player labels (e.g., "Player N") when creating conductors.
Documentation & changelog updates
CHANGELOG.md, docs/tryorama.appwithoptions.label.md, docs/tryorama.appwithoptions.md, docs/tryorama.conductoroptions.label.md, docs/tryorama.conductoroptions.md, docs/tryorama.createconductoroptions.md, docs/tryorama.scenario.addconductor.md, docs/tryorama.scenario.md
Added documentation for the new optional label on AppWithOptions, ConductorOptions, and CreateConductorOptions. Updated addConductor docs to include the label parameter. Added CHANGELOG entry describing the labeling/logging change.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and succinctly describes the primary feature being introduced, namely displaying a Player identifier in conductor logs to distinguish messages from different instances, and follows conventional commit style without unnecessary detail.
Description Check ✅ Passed The pull request description matches the repository template by including a clearly labeled Summary section that explains the new label behavior in conductor logs and a TODO checklist with completed items for the changelog and documentation updates.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12ebb03 and 9344617.

📒 Files selected for processing (2)
  • ts/src/conductor.ts (18 hunks)
  • ts/src/scenario.ts (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
ts/src/scenario.ts (1)
ts/src/conductor.ts (1)
  • NetworkConfig (66-135)
ts/src/conductor.ts (1)
ts/src/logger.ts (1)
  • makeLogger (9-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (macos-latest)
🔇 Additional comments (13)
ts/src/scenario.ts (4)

46-46: LGTM!

Adding an optional label field to AppWithOptions is a clean way to support labeled conductors.


229-231: LGTM!

Correctly passes the label from appWithOptions to addConductor.


285-287: LGTM!

The map callback correctly uses the index parameter i to generate player labels.


105-127: All addConductor callsites match the new (label?, networkConfig?) signature.
No callers pass a NetworkConfig as the first argument.

ts/src/conductor.ts (9)

57-60: LGTM!

Adding an optional label field to ConductorOptions provides clear documentation and type safety for the labeling feature.


169-172: LGTM!

Correctly includes label in the CreateConductorOptions type alongside other conductor configuration options.


224-232: LGTM!

The constructor signature change is safe since it's private, and the instance logger is correctly initialized with the provided label.


250-274: LGTM!

Correctly uses defaultLogger in the static factory method since instance context isn't available yet. The label is passed to the constructor at line 255.


310-312: LGTM!

Correctly uses this._logger for instance logging, ensuring the conductor's label appears in network config update logs.


325-395: LGTM!

All logging calls consistently use this._logger throughout the startup and shutdown methods, ensuring proper label propagation.


403-463: LGTM!

Instance logger usage is consistent across all websocket connection methods.


508-513: LGTM!

Correctly uses this._logger for app installation logging.


537-537: LGTM!

Correctly uses defaultLogger in the standalone cleanAllConductors function since there's no instance context.

Comment thread ts/src/scenario.ts Outdated
@mattyg
mattyg force-pushed the feat/player-id-in-logs branch from 9344617 to adcdcaa Compare October 13, 2025 23:27
@mattyg
mattyg force-pushed the feat/player-id-in-logs branch from df7b611 to fc8acc7 Compare October 13, 2025 23:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
ts/src/scenario.ts (1)

145-147: Index usage fix acknowledged.

Using the index parameter ensures unique labels per player. Good catch.

🧹 Nitpick comments (5)
ts/src/conductor.ts (3)

24-24: Use a type-only import for Logger.

Avoids an unnecessary runtime import.

-import { Logger } from "winston";
+import type { Logger } from "winston";

221-231: Make the instance logger readonly.

Prevents accidental reassignment.

-  private _logger: Logger;
+  private readonly _logger: Logger;

250-271: Route creation-time logs through the instance logger (with label).

This preserves the conductor label in early logs and meets the PR’s goal more completely. Create the instance before logging and replace defaultLogger with the instance logger in the static create flow.

-    args.push(signalingServerUrl.href);
-    defaultLogger.debug("spawning hc sandbox with args:", args);
-    const createConductorProcess = spawn("hc", args);
+    args.push(signalingServerUrl.href);
+    const conductor = new Conductor(options?.label, options?.timeout);
+    conductor._logger.debug("spawning hc sandbox with args:", args);
+    const createConductorProcess = spawn("hc", args);
@@
-    const conductor = new Conductor(options?.label, options?.timeout);
     return new Promise<Conductor>((resolve, reject) => {
       createConductorProcess.stdout.on("data", (data: Buffer) => {
-        defaultLogger.debug(`creating conductor config\n${data.toString()}`);
+        conductor._logger.debug(`creating conductor config\n${data.toString()}`);
@@
-      createConductorProcess.stderr.on("data", (err) => {
-        defaultLogger.error(`error when creating conductor config: ${err}\n`);
+      createConductorProcess.stderr.on("data", (err) => {
+        conductor._logger.error(`error when creating conductor config: ${err}\n`);
         reject(err);
       });
     });
ts/src/scenario.ts (1)

266-271: Consider 1‑based player labels.

For human readability, “Player 1..N” may be preferable to “Player 0..N-1”. Optional.

-      new Array(amount).fill(0).map((_, i) =>
-        this.addPlayerWithApp({
-          label: `Player ${i}`, // default label
+      new Array(amount).fill(0).map((_, i) =>
+        this.addPlayerWithApp({
+          label: `Player ${i + 1}`, // default label
           ...appWithOptions,
         }),
       ),
-      appsWithOptions.map((appWithOptions, i) =>
-        this.addPlayerWithApp({
-          label: `Player ${i}`, // default label
+      appsWithOptions.map((appWithOptions, i) =>
+        this.addPlayerWithApp({
+          label: `Player ${i + 1}`, // default label
           ...appWithOptions,
         }),
       ),

Also applies to: 285-290

docs/tryorama.appwithoptions.md (1)

53-72: Ignore MD lint warning for generated docs (or exclude docs from lint).

MD036 (“Emphasis used instead of a heading”) is triggered by API Documenter’s “(Optional)” emphasis. Prefer excluding generated docs from markdownlint.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9344617 and 305ec51.

📒 Files selected for processing (10)
  • CHANGELOG.md (1 hunks)
  • docs/tryorama.appwithoptions.label.md (1 hunks)
  • docs/tryorama.appwithoptions.md (1 hunks)
  • docs/tryorama.conductoroptions.label.md (1 hunks)
  • docs/tryorama.conductoroptions.md (1 hunks)
  • docs/tryorama.createconductoroptions.md (1 hunks)
  • docs/tryorama.scenario.addconductor.md (2 hunks)
  • docs/tryorama.scenario.md (1 hunks)
  • ts/src/conductor.ts (18 hunks)
  • ts/src/scenario.ts (6 hunks)
✅ Files skipped from review due to trivial changes (2)
  • docs/tryorama.conductoroptions.md
  • docs/tryorama.appwithoptions.label.md
🧰 Additional context used
🧬 Code graph analysis (2)
ts/src/scenario.ts (1)
ts/src/conductor.ts (1)
  • NetworkConfig (66-135)
ts/src/conductor.ts (1)
ts/src/logger.ts (1)
  • makeLogger (9-27)
🪛 markdownlint-cli2 (0.18.1)
docs/tryorama.appwithoptions.md

69-69: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (1)
docs/tryorama.conductoroptions.label.md (1)

1-13: Docs entry looks good; ensure docs build step is completed.

Content is correct. Please run the documented build step and commit updated docs before merge.

Comment thread CHANGELOG.md Outdated
@mattyg mattyg changed the title feat: display 'Player #' in logs to distinguish log messages from different Conductors WIP feat: display 'Player #' in logs to distinguish log messages from different Conductors Oct 14, 2025
@mattyg mattyg changed the title WIP feat: display 'Player #' in logs to distinguish log messages from different Conductors feat: display 'Player #' in logs to distinguish log messages from different Conductors Oct 14, 2025
…y created players' label is incremented starting from number of existing players

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
CHANGELOG.md (1)

10-10: Tighten the relative clause

Consider inserting a comma before “which” so the sentence reads more cleanly: “It allows overriding the default label, which will prefix log messages …”.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 305ec51 and 56237d0.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • ts/src/scenario.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ts/src/scenario.ts
🧰 Additional context used
🪛 LanguageTool
CHANGELOG.md

[grammar] ~12-~12: There might be a mistake here.
Context: ...of that Conductor instance. ### Removed ### Changed - Log messages from Conductors t...

(QB_NEW_EN)


[grammar] ~13-~13: There might be a mistake here.
Context: ...uctor instance. ### Removed ### Changed - Log messages from Conductors that were c...

(QB_NEW_EN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (macos-latest)

@mattyg
mattyg requested a review from a team October 14, 2025 18:53
jost-s
jost-s previously approved these changes Oct 14, 2025

@jost-s jost-s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful!

jost-s
jost-s previously approved these changes Oct 14, 2025
@mattyg
mattyg enabled auto-merge (squash) October 14, 2025 21:41
matthme
matthme previously approved these changes Oct 15, 2025

@matthme matthme left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@coderabbitai coderabbitai Bot mentioned this pull request Oct 16, 2025
2 tasks
@mattyg
mattyg dismissed stale reviews from matthme and jost-s via 1b352a2 October 16, 2025 02:54
@cocogitto-bot

cocogitto-bot Bot commented Oct 16, 2025

Copy link
Copy Markdown

✔️ adcdcaa...1b352a2 - Conventional commits check succeeded.

@mattyg
mattyg changed the base branch from main to fix/dht-sync-timing-out October 16, 2025 02:54
@mattyg
mattyg merged commit 20ee01b into fix/dht-sync-timing-out Oct 16, 2025
4 checks passed
@mattyg
mattyg deleted the feat/player-id-in-logs branch October 16, 2025 02:54
@mattyg

mattyg commented Oct 16, 2025

Copy link
Copy Markdown
Member Author

I merged fix/dht-sync-timing-out into this branch and then changed the base for a clean diff. That caused this to be merged into fix/dht-sync-timing-out automatically, since the branch protection rules that require tests to pass don't apply. My bad.

@mattyg
mattyg restored the feat/player-id-in-logs branch October 16, 2025 03:09
mattyg added a commit that referenced this pull request Oct 21, 2025
…eation and app install sequential (#303)

* fix: avoid test failures due to apparant connection race condition -- start each player's conductor sequentially after a 1 second delay and adjust default k2Gossip configuration

* chore: lint

* docs: regenerate

* chore: comment uniformity

* test: update default config test

* test: remove test that can no longer be achieved, since integration_limbo empties too quickly, instead cover assertions in success case test

* chore: lint

* test: remove test that can no longer be achieved, since integration_limbo empties too quickly, instead cover assertions in success case test

* fix: reading ADMIN_PORT from conductor stdout was flaky

* chore: changelog grammer

* feat: display 'Player #' in logs to distinguish log messages from different Conductors (#302)

* feat: display 'Player #' in logs to distinguish log messages from different conductors

* feat: display 'Player #' in logs to distinguish log messages from different conductors

* docs: rebuild docs

* chore: grammer

* fix: if addPlayersX is called multiple times, ensure that subsequently created players' label is incremented starting from number of existing players

* chore: lint

* chore: Revert " feat: display 'Player #' in logs to distinguish log messages from di…" (#306)

This reverts commit 20ee01b.

* revert: remove pause between conductor starts from addPlayers -- only need to stagger app installation as that initiates networking

* chore: add TODO to comments explaining workaround

* chore: clarifying comment

* fix: clone rather than mutate map param

* chore: lint

* chore: removed TODO comment, which actually was not related to workaround

* chore: unrelated typo

* refactor: actually install apps sequentially, rather than via arbitrary pause

* chore: lint

* docs: clarify that addPlayerWithApp should not be called in parallel

* chore: changelog

* chore: changelog accuracy
@coderabbitai coderabbitai Bot mentioned this pull request Oct 21, 2025
2 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Nov 20, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants