Skip to content

Feat/player id in logs - #307

Merged
mattyg merged 20 commits into
mainfrom
feat/player-id-in-logs
Oct 22, 2025
Merged

Feat/player id in logs#307
mattyg merged 20 commits into
mainfrom
feat/player-id-in-logs

Conversation

@mattyg

@mattyg mattyg commented Oct 16, 2025

Copy link
Copy Markdown
Member

Summary

Display Player index in conductor log messages

(had to recreate this PR branch after accidentally merging it into another PR branch)

TODO:

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

Summary by CodeRabbit

  • New Features

    • Optional label parameter to customize conductor identifiers in logs.
    • Conductors created via player helpers now use "Tryorama - Player #…" prefixes.
    • Player-based conductor creation now waits for each conductor to finish starting before continuing.
  • Bug Fixes

    • More reliable detection of conductor startup success.
  • Documentation

    • Docs updated to document the new label property across interfaces and methods.

@coderabbitai

coderabbitai Bot commented Oct 16, 2025

Copy link
Copy Markdown

Walkthrough

Added an optional label field propagated through AppWithOptions, ConductorOptions, CreateConductorOptions and the addConductor API; conductors created via Scenario helpers receive per-instance labels and are created sequentially with explicit startup waiting; logging switched to per-conductor log prefixes (e.g., "Tryorama - Player #").

Changes

Cohort / File(s) Summary
Core implementation
ts/src/conductor.ts, ts/src/scenario.ts
Added label?: string to ConductorOptions and AppWithOptions; updated CreateConductorOptions to include label; changed Conductor constructor signature to accept label and initialize a per-instance logger; updated logging sites to use instance logger; addConductor now accepts optional label; added generatePlayerLabel and propagated labels from player helpers.
Documentation — types & API
docs/tryorama.appwithoptions.md, docs/tryorama.conductoroptions.md, docs/tryorama.createconductoroptions.md, docs/tryorama.scenario.md, docs/tryorama.scenario.addconductor.md
Updated docs to reflect new optional label property on interfaces and the expanded addConductor(networkConfig, label) signature; updated CreateConductorOptions Pick to include label.
Documentation — property pages
docs/tryorama.appwithoptions.label.md, docs/tryorama.conductoroptions.label.md
Added generated docs pages describing the optional label?: string property for AppWithOptions and ConductorOptions.
Changelog
CHANGELOG.md
Documented added label field, player log-prefix change, sequential conductor creation with startup waiting, and fixes to conductor startup recognition.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • matthme
  • ThetaSinner

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "Feat/player id in logs" refers to a real and significant aspect of the changeset—the addition of player identification in conductor log messages through the new label mechanism used in addPlayers. While the changes also introduce a broader, more generic label feature for customizing conductor identification, the title captures the specific and concrete outcome that appears to be the primary driver for these changes. The title is sufficiently clear and specific enough that a teammate would understand the change is about adding player identification to logs rather than being vague or generic.
Description Check ✅ Passed The PR description follows the required template structure with both the "### Summary" and "### TODO:" sections properly included. The summary clearly states the main objective ("Display Player index in conductor log messages"), and both checklist items in the TODO section are marked as complete, indicating that the CHANGELOG has been updated and documentation has been rebuilt. While the summary section is brief and doesn't exhaustively detail all code changes, the description meets the template requirements and provides sufficient information about the PR's completion status.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/player-id-in-logs

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.

@mattyg
mattyg force-pushed the fix/dht-sync-timing-out branch from e5c82e4 to 70820bc Compare October 16, 2025 03:29
@mattyg
mattyg requested review from a team and removed request for a team October 16, 2025 03:31
Base automatically changed from fix/dht-sync-timing-out to main October 21, 2025 17:54

@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

🧹 Nitpick comments (1)
docs/tryorama.appwithoptions.label.md (1)

1-11: Documentation lacks a description of the label field.

Unlike the corresponding ConductorOptions.label documentation page (which includes "Label to identify this conductor in logs"), this page for AppWithOptions.label only provides the type signature without explanation. Consider adding a brief description to clarify the purpose of this field.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb5764d and 7d20208.

📒 Files selected for processing (10)
  • CHANGELOG.md (2 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)
🧰 Additional context used
🧬 Code graph analysis (2)
ts/src/conductor.ts (1)
ts/src/logger.ts (1)
  • makeLogger (9-27)
ts/src/scenario.ts (1)
ts/src/conductor.ts (1)
  • NetworkConfig (66-135)
🪛 markdownlint-cli2 (0.18.1)
docs/tryorama.appwithoptions.md

69-69: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

docs/tryorama.scenario.addconductor.md

61-61: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

⏰ 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 (29)
docs/tryorama.appwithoptions.md (1)

54-72: Auto-generated documentation is consistent with existing patterns.

The label property addition follows the same structure and format as other optional properties in AppWithOptions. The table row is correctly formatted and consistent with the generated documentation style.

docs/tryorama.conductoroptions.label.md (1)

1-12: New property documentation is well-formed and clear.

The new file follows standard API Documenter conventions with a clear description and correct TypeScript signature for the optional label property.

docs/tryorama.createconductoroptions.md (1)

12-12: Type definition correctly reflects label addition to conductor options.

The CreateConductorOptions type now includes "label" in its Pick from ConductorOptions, enabling label specification during conductor creation.

docs/tryorama.scenario.addconductor.md (2)

12-12: Method signature correctly updated to include optional label parameter.

The addConductor signature now includes the optional label parameter, reflecting the new capability to customize conductor labels.


49-64: Parameter documentation added with consistent formatting.

The label parameter is documented in the parameters table following the same format as networkConfig, clearly indicating it is optional.

docs/tryorama.scenario.md (1)

230-230: Method reference correctly updated to reflect label parameter.

The Scenario.addConductor method reference now shows both parameters, maintaining consistency with the detailed method documentation.

docs/tryorama.conductoroptions.md (1)

56-74: Property documentation consistently added to ConductorOptions interface.

The label property is properly integrated into the ConductorOptions documentation with a clear description and appropriate reference link, and is positioned logically in the properties table.

CHANGELOG.md (2)

8-8: Changelog entry accurately documents the new label feature.

The addition properly summarizes the new optional label field across the affected types and function, with a clear explanation of its purpose in log message prefixing.


13-14: Changelog entries comprehensively document behavioral changes.

The changelog properly documents:

  • The new label field addition (line 8)
  • Sequential conductor creation with delays (lines 24, 28)
  • Player index in log prefixes via "Tryorama - Player #" (line 24)
  • Fixes for flaky startup recognition (line 14, 29)

All entries are well-organized with appropriate PR references.

Also applies to: 24-24, 28-29

ts/src/scenario.ts (5)

47-47: LGTM!

The optional label field allows callers to provide custom conductor labels, which integrates cleanly with the conductor creation flow.


106-114: LGTM!

The addConductor method correctly accepts and forwards the optional label to the conductor creation options.


149-150: Label generation is safe for parallel creation.

The generatePlayerLabel method uses this.conductors.length + index, which is evaluated when called. Since the loop index i increments and this.conductors.length is captured at the time of the map, labels will be consecutive (e.g., "Player 0", "Player 1", "Player 2") even when conductors are created in parallel via Promise.all.


266-266: LGTM!

The label from appWithOptions is correctly passed to addConductor.


388-390: LGTM!

The generatePlayerLabel method produces human-readable labels in the format "Player N" where N is the player's index in the scenario.

ts/src/conductor.ts (15)

24-26: LGTM!

The defaultLogger is appropriately used for static and pre-instance logging contexts where a per-instance logger is not yet available.


57-60: LGTM!

The label field is well-documented and provides a clear way to identify conductors in logs.


169-172: LGTM!

Including label in the CreateConductorOptions type ensures it can be passed through the factory function.


186-190: LGTM!

The label is correctly picked from options and passed to the conductor factory.


224-232: Constructor signature change is safe.

The constructor parameter order changed from (timeout?: number) to (label?: string, timeout?: number). Since the constructor is private and only called by the factory method (line 255), this is not a breaking change for external consumers.


250-273: LGTM!

The defaultLogger is appropriately used during conductor creation since the instance logger isn't available until after the constructor runs.


310-312: LGTM!

Using the instance logger (this._logger) for configuration updates correctly associates these logs with the specific conductor instance.


325-328: LGTM!

The error message now uses the instance logger, improving log clarity when multiple conductors are running.


344-359: LGTM!

Startup logs now use the instance logger, making it easy to track which conductor is starting up and identify issues per instance.


372-403: LGTM!

Shutdown logs use the instance logger, providing clear visibility into which conductor is shutting down.


411-411: LGTM!

Connection logs use the instance logger for better traceability.


425-426: LGTM!

App interface attachment logs use the instance logger.


438-438: LGTM!

App WebSocket connection logs use the instance logger.


516-520: LGTM!

App installation logs use the instance logger, making it clear which conductor is installing which app.


545-545: LGTM!

The static cleanup function correctly uses defaultLogger since it operates globally across all conductors.

Comment thread ts/src/scenario.ts Outdated
@cocogitto-bot

cocogitto-bot Bot commented Oct 21, 2025

Copy link
Copy Markdown

✔️ adcdcaa...1161111 - Conventional commits check succeeded.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ts/src/scenario.ts (1)

135-157: Documentation-code mismatch: Implementation is parallel, not sequential.

The documentation states "Each conductor is created sequentially, once the previous has completed startup" (lines 135-136), but the implementation uses Promise.all, which creates conductors in parallel.

Additionally, multiple other methods in this file (installAppsForPlayers, installSameAppForPlayers, addPlayersWithSameApp, addPlayersWithApps) explicitly use sequential for loops with TODO comments referencing issue #297 to avoid connection failures. This method should follow the same pattern.

Apply this diff to make conductor creation sequential and consistent with other methods:

   async addPlayers(
     amount: number,
     networkConfig?: NetworkConfig,
   ): Promise<Player[]> {
     await this.ensureLocalServices();
-    return Promise.all(
-      new Array(amount).fill(0).map(async (_, i) => {
-        const conductor = await this.addConductor(
-          networkConfig,
-          this.generatePlayerLabel(i),
-        );
-        const agentPubKey = await conductor.adminWs().generateAgentPubKey();
-        return { conductor, agentPubKey };
-      }),
-    );
+    // Sequentially create conductors.
+    // TODO This is a workaround to avoid connection failures.
+    // See https://github.com/holochain/tryorama/issues/297
+    const players = [];
+    for (let i = 0; i < amount; i++) {
+      const conductor = await this.addConductor(
+        networkConfig,
+        this.generatePlayerLabel(i),
+      );
+      const agentPubKey = await conductor.adminWs().generateAgentPubKey();
+      players.push({ conductor, agentPubKey });
+    }
+    return players;
   }
🧹 Nitpick comments (1)
ts/src/scenario.ts (1)

390-392: Consider 1-indexed labels for better UX.

The current implementation generates 0-indexed labels ("Player 0", "Player 1", etc.). For human-readable log messages, 1-indexed labels ("Player 1", "Player 2", etc.) are typically more intuitive and align with common UX conventions.

Apply this diff to use 1-indexed labels:

   private generatePlayerLabel(index: number): string {
-    return `Player ${this.conductors.length + index}`;
+    return `Player ${this.conductors.length + index + 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 7d20208 and 1161111.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • ts/src/scenario.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
🧰 Additional context used
🧬 Code graph analysis (1)
ts/src/scenario.ts (1)
ts/src/conductor.ts (1)
  • NetworkConfig (66-135)
🔇 Additional comments (3)
ts/src/scenario.ts (3)

46-46: LGTM! Label field properly added.

The optional label field is correctly typed and follows TypeScript conventions for optional properties.


105-127: LGTM! Label parameter properly propagated.

The label parameter is correctly threaded through the conductor creation options and handles both configuration scenarios appropriately.


264-275: LGTM! Label correctly propagated from app options.

The appWithOptions.label is properly passed to addConductor, maintaining consistency with the label propagation design.

@mattyg
mattyg requested a review from a team October 21, 2025 19:15
@mattyg
mattyg merged commit 89b2033 into main Oct 22, 2025
6 of 8 checks passed
@mattyg
mattyg deleted the feat/player-id-in-logs branch October 22, 2025 15:18
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.

2 participants