Skip to content

agent pnl silently ignores unexpected positional args and falls back to 24h #42

Description

@timbrinded

Summary

hlgo agent pnl silently accepts an extra positional argument like 720h, ignores it, and falls back to the default --lookback-hours 24.

This is easy to miss in scripts/agent flows because the command succeeds and returns valid-looking JSON, but for the wrong time window.

Environment

  • repo: timbrinded/hlgo
  • local repro commit: aa673f0
  • binary rebuilt from source on Linux arm64

Steps to reproduce

Assuming HL_PRIVATE_KEY is set and the account has fills/positions:

hlgo agent pnl 720h --format json

Actual outcome

The command succeeds, but the positional 720h is ignored. The output still reports the default lookback:

{
  "lookback_hours": 24,
  ...
}

In my repro, the same happened for 168h and 336h as well.

Expected outcome

One of these should happen instead:

  1. Preferred: reject unexpected positional args with a validation error, e.g. unknown argument: 720h or accepts no args.
  2. Alternative: intentionally support positional duration syntax and parse 720h / 168h / 336h into lookback_hours.

What should not happen is silent success with the default 24h window.

Likely root cause

cmd/agent_pnl.go only reads the --lookback-hours flag:

lookbackHours, _ := cmd.Flags().GetInt("lookback-hours")

and defines:

cmd.Flags().Int("lookback-hours", 24, ...)

But the command does not appear to set an Args validator (for example cobra.NoArgs), so extra positional input is accepted and ignored.

Suggested fix

  • Add Args: cobra.NoArgs to newAgentPnlCmd() (and possibly audit other commands for the same silent-extra-arg pattern).
  • Add a regression test covering:
hlgo agent pnl 720h

which should fail with a non-zero exit code.

Why this matters

For humans this is confusing; for agents/scripts it is worse, because the command returns plausible output and can lead to incorrect performance analysis or decision-making while appearing to work correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions