Skip to content

Retain cached JSONL history within requested date ranges - #60361

Merged
pelikhan merged 4 commits into
mainfrom
copilot/update-logs-command-handling
Sep 12, 2026
Merged

Retain cached JSONL history within requested date ranges#60361
pelikhan merged 4 commits into
mainfrom
copilot/update-logs-command-handling

Conversation

Copilot AI commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

logs --cached-jsonl appended new records without pruning cached runs outside the requested time range.

  • Cache lifecycle

    • Preserve existing JSONL content.
    • Append newly collected records.
    • Atomically filter run records after collection.
  • Filtering

    • Apply inclusive --start-date and --end-date bounds.
    • Preserve workflow-list, rate-limit, unknown, and undated records.
    • Retain existing file permissions.
gh aw logs --cached-jsonl logs.jsonl \
  --start-date 2026-09-01 \
  --end-date 2026-09-10

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Retain and filter appended cached logs JSONL Retain cached JSONL history within requested date ranges Sep 12, 2026
Copilot AI requested a review from pelikhan September 12, 2026 01:13
@pelikhan
pelikhan marked this pull request as ready for review September 12, 2026 01:14
Copilot AI balanced review requested due to automatic review settings September 12, 2026 01:14

Copilot AI 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.

🟡 Changes recommended

Stdin mode bypasses filtering, and unknown-schema run records can be incorrectly deleted.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds post-collection date-range pruning for cached JSONL history while retaining unrelated records and file permissions.

Changes:

  • Filters cached run records after single- and multi-target collection.
  • Implements inclusive date bounds and atomic rewriting.
  • Updates CLI help and adds cache-filtering tests.
File summaries
File Description
pkg/cli/logs_orchestrator.go Filters single-target caches after collection.
pkg/cli/logs_multi.go Filters multi-target caches after collection.
pkg/cli/logs_command.go Documents date-range cache retention.
pkg/cli/logs_cached_json.go Implements atomic date filtering.
pkg/cli/logs_cached_json_test.go Tests filtering, preservation, and permissions.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +392 to +396
if err := json.Unmarshal(trimmed, &record); err != nil ||
record.Kind != cachedLogsJSONLKindRun ||
record.Run == nil ||
record.Run.CreatedAt.IsZero() {
filtered = append(filtered, line...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4e5... filterDateRange now requires record.SchemaVersion == cachedLogsJSONLSchemaVersion for run records, so unknown/future-schema run records are preserved. Added a regression test with a schema_version: 99 run record in the excluded range that stays in the file.

Comment thread pkg/cli/logs_command.go
Comment on lines +155 to +156
artifacts again. New results are appended immediately as JSON Lines. When a date range is specified,
cached run records outside that range are removed after collection; other record types are retained.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a9707d7: StartDate/EndDate are now plumbed through StdinLogsOptions, and DownloadWorkflowLogsFromStdin defers a call to cachedJSONLWriter.filterDateRange mirroring the discovery-mode path. Added a regression test exercising --stdin with a cached JSONL and date range.

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by Ponytail Reviewer for #60361

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security scanning failed for Design Decision Gate 🏗️. Review the logs for details.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions github-actions Bot 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.

Ponytail review: focused on over-engineering only.

net: -0 lines possible.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by ✂️ Ponytail Reviewer for #60361 · codex · gpt53codex · 4.32 AIC · ⌖ 3.98 AIC · ⊞ 12.8K
Comment /ponytail to run again

@github-actions

Copy link
Copy Markdown
Contributor

ADR Required

I could not find an existing ADR in the PR body or on the PR branch that covers this change using the required Michael Nygard sections (Context, Decision, Alternatives Considered, Consequences).

Evidence used:

  • ADR enforcement is required because this PR adds 137 lines in default business-logic directories (pkg/), which exceeds the 100-line threshold.
  • The implementation introduces a design decision for gh aw logs --cached-jsonl: append new records immediately, then prune cached run records outside the requested inclusive date range while preserving non-run and undated records.
  • The most recent existing ADR on the branch is docs/adr/60323-cancel-sibling-log-targets-on-shared-count-limit.md, which covers a different logs orchestration decision.

I added a draft ADR at docs/adr/60361-retain-cached-jsonl-history-within-date-ranges.md.

Next action: review and refine that ADR, then keep it with the PR so this decision is explicit before merge.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · gpt54 · 19.5 AIC · ⊞ 9.9K ·
Comment /review to run again

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs — the core append/filter lifecycle logic and test are solid, but two edge cases undermine the correctness guarantee this PR advertises.

📋 Key Themes & Highlights

Key Themes

  • --stdin path is silently unguarded: loadStdinLogsOptions drops StartDate/EndDate, and DownloadWorkflowLogsFromStdin never calls filterDateRange. The updated --cached-jsonl doc claims cached run records outside the range are always removed after collection — that's false for --stdin. This was also flagged by an earlier bot review comment on the same line.
  • Schema-version blind spot in filterDateRange: the preservation check treats any record that fails to unmarshal cleanly into the current run shape as safe-to-keep via CreatedAt.IsZero(), but a future-schema run record with a valid created_at would be misidentified and could be incorrectly dropped or kept for the wrong reason. Also flagged by an earlier bot comment.

Positive Highlights

  • ✅ Atomic filter-then-write via writeFileAtomically, with a no-op short-circuit (bytes.Equal) when nothing changed — avoids unnecessary rewrites.
  • ✅ Good regression test (TestCachedLogsJSONLWriterFiltersAppendedContentByDateRange) exercising boundary dates, undated records, workflow-list/rate-limit/unknown record preservation, and file permission retention.
  • defer + errors.Join pattern in logs_multi.go/logs_orchestrator.go cleanly ties filtering to the collection lifecycle without obscuring the original error.

Requesting changes to close the --stdin gap (or explicitly document/reject it) and to make the schema-version guard explicit with a regression test, per the inline comments.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 64 AIC · ⌖ 14.1 AIC · ⊞ 10.4K
Comment /matt to run again

record.Kind != cachedLogsJSONLKindRun ||
record.Run == nil ||
record.Run.CreatedAt.IsZero() {
filtered = append(filtered, line...)

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.

[/diagnosing-bugs] filterDateRange only pattern-matches on Kind == cachedLogsJSONLKindRun, ignoring SchemaVersion. A future-schema run record (e.g. schema_version: 99) will unmarshal into the current struct with zero/garbage fields, likely leaving CreatedAt zero, so it's preserved by this check — but it's silently mis-parsed rather than genuinely 'unknown and safe to keep'. This mirrors a bot review comment already on this line.

💡 Suggested fix

Guard on record.SchemaVersion != cachedLogsJSONLSchemaVersion explicitly (treat unrecognized/newer schema versions as opaque/preserved, the same way unknown kinds are handled), rather than relying on CreatedAt.IsZero() as an implicit signal. Add a regression test with a run record at a future schema_version containing a valid created_at in the excluded range, and assert it is still preserved (proving the schema check, not an accidental zero-value, is what protects it).

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a9707d7: filterDateRange now requires record.SchemaVersion == cachedLogsJSONLSchemaVersion for run records before pruning, so future-schema run records are preserved. Added a regression test with a schema_version: 99 run record in the excluded range.

Comment thread pkg/cli/logs_command.go
artifacts again. New results are appended immediately as JSON Lines. Aggregate analysis may be approximate when compact
cached records omit detailed data.
artifacts again. New results are appended immediately as JSON Lines. When a date range is specified,
cached run records outside that range are removed after collection; other record types are retained.

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.

[/diagnosing-bugs] This doc says cached run records outside the requested range are always removed, but loadStdinLogsOptions (line ~225) drops StartDate/EndDate when building StdinLogsOptions, and DownloadWorkflowLogsFromStdin never calls filterDateRange at all. Using --stdin --cached-jsonl --start-date/--end-date silently skips pruning, contradicting this doc and the PR description's stated guarantee. Flagged previously by another reviewer on this same line.

💡 Suggested fix

Either (a) plumb StartDate/EndDate through to StdinLogsOptions and call cachedJSONLWriter.filterDateRange in DownloadWorkflowLogsFromStdin (mirroring the defer pattern added in logs_multi.go/logs_orchestrator.go), or (b) explicitly document/reject the combination for the stdin path. Add a regression test exercising --stdin with a cached JSONL and date range to lock in whichever behavior is chosen — right now there's no test covering this path at all.

@copilot please address this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a9707d7: StartDate/EndDate now flow through StdinLogsOptions and DownloadWorkflowLogsFromStdin filters the cache on completion, matching the discovery-mode guarantee described in the docs. Added a regression test.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Copilot AI and others added 2 commits September 12, 2026 02:34
…iltering

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
pelikhan merged commit 67dbe17 into main Sep 12, 2026
32 checks passed
@pelikhan
pelikhan deleted the copilot/update-logs-command-handling branch September 12, 2026 03:29
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.89.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants