Skip to content

homelab_aptHistory returns oldest rotated entries instead of most recent #89

Closed

Description

@TMHSDigital

Summary

homelab_aptHistory returns the oldest rotated apt history instead of the most recent entries.

Where

  • mcp-server/src/tools/aptHistory.ts:24-27

Details

`(grep -E '...' /var/log/apt/history.log 2>/dev/null; ` +
`zgrep -E '...' /var/log/apt/history.log.*.gz 2>/dev/null) ` +
`| tail -${args.lines}`

The current log (newest) is printed first and the rotated archives (older) after it, so tail keeps the archive lines. The glob also sorts lexically (.1.gz, .10.gz, .11.gz, .12.gz, .2.gz ... .9.gz), so the last lines come from history.log.9.gz.

Impact

Once apt logs have rotated even once, "recent history" shows months-old entries and the latest upgrades never appear.

Steps to reproduce

  1. Use a Pi with rotated apt logs (anything older than about a month).
  2. Call homelab_aptHistory {lines: 10}.
  3. The returned entries are old ones, not the latest.

Suggested fix

Print the rotated files oldest to newest, then the current log last, and then tail. For example:
ls -1v /var/log/apt/history.log.*.gz | tac | xargs -r zgrep -hE '...'; grep -E '...' /var/log/apt/history.log

Acceptance criteria

  • The newest entries come out last, before tail
  • Numeric (not lexical) ordering of the rotated files
  • A mocked-SSH test asserts the generated command

Getting started

  • Relevant files: mcp-server/src/tools/aptHistory.ts
  • How to run tests: cd mcp-server && npm test

Filed by repo-audit/full-audit at 9cfe5e3. Severity: medium. Effort: S. audit-key: bug|mcp-server/src/tools/aptHistory.ts|register

Activity

  1. added
    bug
    good first issue
    severity: medium
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issueseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions