Skip to content

Conversation

@kr1shna-exe
Copy link

@kr1shna-exe kr1shna-exe commented Jan 14, 2026

Problem

When using Stagehand V3 with verbose: 0, debug-level logs are still printed if v3Logger falls back to console logging.The fallback path bypasses verbosity filtering, resulting in unexpected debug output.

Solution

Applied a default verbosity threshold check to the fallback logging path to ensure debug messages are suppressed unless explicitly allowed.

Changes

  • Added a default fallback verbosity check in v3Logger
  • Prevented debug-level logs from being printed when verbosity is effectively disabled

Fixes #1490


Summary by cubic

Stops debug logs from printing when verbose: 0 by adding a fallback verbosity threshold (1) to the v3Logger console fallback. Fixes #1490.

Written for commit 36b82cc. Summary will update on new commits.

@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

⚠️ No Changeset found

Latest commit: 36b82cc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 14, 2026

Greptile Summary

This PR attempts to fix debug logs appearing in console fallback when verbose: 0 by adding a verbosity check with FALLBACK_VERBOSITY = 1. However, the implementation has critical issues:

  • The hardcoded FALLBACK_VERBOSITY = 1 means the fallback path won't respect user's configured verbosity (e.g., debug logs will be suppressed even when user sets verbose: 2)
  • The fix will break existing test logger-initialization.spec.ts:311 which expects all log levels to appear in console fallback
  • The root issue is that fallback logging has no access to per-instance verbosity settings

The AgentProvider.ts import fix (ai instead of ai/dist) is good and aligns with TypeScript best practices per custom rule 08cb1f73.

Confidence Score: 2/5

  • This PR has a critical logic bug that breaks user-configured verbosity in fallback scenarios and will cause test failures
  • The hardcoded FALLBACK_VERBOSITY doesn't respect user's verbose setting, causing debug logs to be suppressed even when verbose: 2 is set, and info logs to appear when verbose: 0 is set. This will also break existing test expectations.
  • Pay close attention to packages/core/lib/v3/logger.ts which contains the logic bug

Important Files Changed

Filename Overview
packages/core/lib/v3/logger.ts Added hardcoded FALLBACK_VERBOSITY check in console fallback path, but this doesn't respect user's configured verbosity and will break existing tests
packages/core/lib/v3/agent/AgentProvider.ts Fixed import to use non-dist path (ai instead of ai/dist) for better TypeScript compatibility

Sequence Diagram

sequenceDiagram
    participant User
    participant Stagehand
    participant v3Logger
    participant AsyncLocalStorage
    participant StagehandLogger
    participant Console

    User->>Stagehand: new Stagehand({verbose: 0, disablePino: true})
    Stagehand->>StagehandLogger: create with verbose=0
    Stagehand->>AsyncLocalStorage: bindInstanceLogger(instanceId, logger)
    
    Note over Stagehand,AsyncLocalStorage: Normal flow - context preserved
    User->>Stagehand: perform operation
    Stagehand->>v3Logger: v3Logger({level: 2, message: "debug"})
    v3Logger->>AsyncLocalStorage: getStore()
    AsyncLocalStorage-->>v3Logger: instanceId
    v3Logger->>StagehandLogger: log(line)
    StagehandLogger->>StagehandLogger: check: level (2) > verbose (0)?
    Note over StagehandLogger: YES - suppressed ✓
    
    Note over Stagehand,Console: Context lost scenario (setTimeout, etc)
    User->>Stagehand: perform async operation
    Stagehand->>v3Logger: v3Logger({level: 2, message: "debug"})
    v3Logger->>AsyncLocalStorage: getStore()
    AsyncLocalStorage-->>v3Logger: undefined (context lost)
    v3Logger->>v3Logger: check: level (2) > FALLBACK_VERBOSITY (1)?
    Note over v3Logger: YES - suppressed
    Note over v3Logger,Console: Issue: Uses hardcoded value,<br/>not user's verbose setting
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +81 to +83
if (lvl > FALLBACK_VERBOSITY) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: hardcoded FALLBACK_VERBOSITY = 1 doesn't respect user's configured verbosity level

when user sets verbose: 2 (show debug), fallback will still suppress debug logs. when user sets verbose: 0 (errors only), fallback will show info logs.

this will also break the existing test at logger-initialization.spec.ts:311 which expects all 3 log levels (error, info, debug) to be logged to console fallback.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/logger.ts
Line: 81:83

Comment:
**logic:** hardcoded `FALLBACK_VERBOSITY = 1` doesn't respect user's configured verbosity level

when user sets `verbose: 2` (show debug), fallback will still suppress debug logs. when user sets `verbose: 0` (errors only), fallback will show info logs.

this will also break the existing test at `logger-initialization.spec.ts:311` which expects all 3 log levels (error, info, debug) to be logged to console fallback.

How can I resolve this? If you propose a fix, please make it concise.

// Per-instance routing using AsyncLocalStorage
const logContext = new AsyncLocalStorage<string>();
const instanceLoggers = new Map<string, (line: LogLine) => void>();
const FALLBACK_VERBOSITY = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider storing per-instance verbosity settings in a Map (similar to instanceLoggers) instead of hardcoding fallback verbosity. this would allow the fallback path to respect each instance's configured verbosity level.

const instanceVerbosity = new Map<string, 0 | 1 | 2>();

export function bindInstanceLogger(
  instanceId: string,
  logger: (line: LogLine) => void,
  verbosity: 0 | 1 | 2 = 1,
): void {
  instanceLoggers.set(instanceId, logger);
  instanceVerbosity.set(instanceId, verbosity);
}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/logger.ts
Line: 34:34

Comment:
**style:** consider storing per-instance verbosity settings in a Map (similar to `instanceLoggers`) instead of hardcoding fallback verbosity. this would allow the fallback path to respect each instance's configured verbosity level.

```typescript
const instanceVerbosity = new Map<string, 0 | 1 | 2>();

export function bindInstanceLogger(
  instanceId: string,
  logger: (line: LogLine) => void,
  verbosity: 0 | 1 | 2 = 1,
): void {
  instanceLoggers.set(instanceId, logger);
  instanceVerbosity.set(instanceId, verbosity);
}
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

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.

Bug : v3Logger fallback bypasses verbose level filtering, causing debug logs even with verbose: 0

1 participant