Skip to content

Bound ZIP log extraction by total size and entry count - #74906

Merged
pelikhan merged 4 commits into
mainfrom
copilot/uk-ai-resilience-tier-b-zip-log-extraction
Nov 4, 2026
Merged

pelikhan merged 4 commits into
mainfrom
copilot/uk-ai-resilience-tier-b-zip-log-extraction

Conversation

Copilot AI commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

ZIP logs were limited per entry but not across the archive, allowing many entries to consume excessive disk space or CPU.

  • Archive limits: Reject archives exceeding 10,000 entries or 1 GiB total uncompressed size before extraction.
  • Runtime enforcement: Track bytes written across entries, so inaccurate ZIP size metadata cannot bypass the total limit.
  • Clear errors: Report when either archive limit is exceeded.

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Add limits for total size and entry counts in ZIP log extraction Bound ZIP log extraction by total size and entry count Nov 4, 2026
Copilot AI requested a review from gh-aw-bot November 4, 2026 17:51
@pelikhan
pelikhan marked this pull request as ready for review November 4, 2026 18:09
Copilot AI adaptive review requested due to automatic review settings November 4, 2026 18:09
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: gpt56 max · ~1 AIC · ⌖ ~1 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 4, 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 Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt56 max · ~3 AIC · ⌖ ~1 AIC · ⊞ 118 · ◷

Generated by Ponytail Reviewer for #74906

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-04T18:14:00Z
review_event: COMMENT
top_themes:
  - preserve per-entry versus archive-wide size error diagnostics
  - add runtime enforcement coverage for understated ZIP metadata
files_reviewed:
  - pkg/cli/logs_download_zip.go
  - pkg/cli/logs_extract_zip_test.go
comment_count: 2

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷
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.

Review complete: no blocking correctness or security issues found.

Highlights
  • Preserve the distinction between per-entry and archive-wide size errors.
  • Add coverage for runtime enforcement when ZIP metadata understates extracted bytes.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

return extractErr
// written == maxSize+1 means the reader was not exhausted, i.e. the
// actual content is larger than the allowed size.
if uint64(written) > maxSize {

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.

The per-entry limit violation is now reported as a total-archive violation, which misleads callers and breaks the prior error distinction.

💡 Preserve the limit-specific error

extractZipFile passes maxZipEntrySize as maxSize, so an entry whose actual content exceeds 1 GiB reaches this branch and emits file extraction exceeded total uncompressed size limit. Select the message based on whether the per-entry or archive-wide limit is being enforced (or retain the existing per-entry wording) so diagnostics and error matching remain accurate.

})
}

func TestUnzipFileWithLimits(t *testing.T) {

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.

This test only covers the pre-scan based on declared ZIP sizes and does not exercise the runtime byte-counting safeguard this change introduces.

💡 Add an understated-metadata case

Add a case whose declared UncompressedSize64 is below the configured total while the reader produces more bytes, then assert extraction stops with the total-limit error and verify the resulting files. That protects remainingSize accounting and the io.LimitReader enforcement from regressions instead of testing only metadata validation.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR adds a lot of new core business logic (111 new lines in pkg/), but it does not link an Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/74906-bound-zip-log-extraction-by-total-size-and-entry-count.md. Please review and complete it before merging.

Decision recorded in the draft: ZIP log extraction now has two archive-wide limits: at most 10,000 entries and at most 1 GiB uncompressed in total. They are checked twice: once from the archive metadata before anything is written, and again by counting bytes as entries are extracted (unzipFileWithLimits, extractZipFileWithLimit).

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch. It was generated from the PR diff and [uk-ai-resilience] Tier B: ZIP log extraction lacks total size/entry limits (code scanning 1062) #74889.

  2. Complete the sections marked [TODO: verify]: who made the decision, and whether real log archives come close to 1 GiB or 10,000 entries. Also check the listed trade-offs: the limits cannot be overridden, the total limit equals the per-entry limit, and if the total limit is exceeded during extraction, files already written are left behind.

  3. Commit the finalized ADR to docs/adr/ on your branch.

  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-74906: Bound ZIP Log Extraction by Total Size and Entry Count (link unavailable: invalid HTTPS URL)

Once an ADR is linked in the PR body, this gate will re-run and check that the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context: What is the problem? What forces are at play?
  • Decision: What did you decide? Why?
  • Alternatives Considered: What else could have been done?
  • Consequences: What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files named by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: opus55 medium · ~28 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷
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 /tdd and /codebase-design. The core logic is sound: the archive-wide preflight runs before any extraction, the runtime budget is enforced with min(maxSize, maxZipEntrySize), and an exact-size file is accepted. Posting observations only.

📋 Key Themes & Highlights

Key Themes

  • Untested runtime budget: TestUnzipFileWithLimits covers only the preflight checks. The runtime byte-count guard, which is the protection the PR description relies on, has no test (see inline comment).
  • Ambiguous error wording: the runtime error says "total" even when the per-entry 1 GB cap is the limit that fired.

Positive Highlights

  • ✅ Preflight validation rejects over-limit archives before any entry is written, and the test asserts the destination stays empty.
  • ✅ Close() errors are propagated through named returns, matching the existing destFile pattern.
  • ✅ The per-entry extractZipFile caller in logs_episode_retrieval_artifacts.go keeps its own 64 MiB total check, so it is not weakened.
  • ✅ Targeted zip tests pass when run with the -run filter for Zip and Unzip.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again

Comment thread pkg/cli/logs_download_zip.go Outdated
// written == maxSize+1 means the reader was not exhausted, i.e. the
// actual content is larger than the allowed size.
if uint64(written) > maxSize {
extractErr = fmt.Errorf("file extraction exceeded total uncompressed size limit: %s", f.Name)

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.

[/codebase-design] This message says "total uncompressed size limit", but it also fires when the per-entry 1 GB cap binds. The extractZipFile path passes maxZipEntrySize as the budget, so one oversized file would be reported as an archive-total problem. Use wording that matches the limit that actually fired, or neutral wording such as "exceeded size limit".

@copilot please address this.

return extractErr
// written == maxSize+1 means the reader was not exhausted, i.e. the
// actual content is larger than the allowed size.
if uint64(written) > maxSize {

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.

[/tdd] The runtime byte budget is the guarantee the PR description relies on (archive metadata can lie), but no test reaches it. Coverage shows lines 163-166 never run, and the per-entry size pre-check at lines 52-54 is also untested.

💡 Suggested test

Call extractZipFileWithLimit directly with a budget smaller than the real content, so the declared size does not trigger the error (sketch, adapt the zip setup):

func TestExtractZipFileWithLimitEnforcesRuntimeBudget(t *testing.T) {
    t.Parallel()
    // one-entry zip containing "hello" (5 bytes), opened with zip.OpenReader
    _, err := extractZipFileWithLimit(r.File[0], t.TempDir(), false, 4)
    require.ErrorContains(t, err, "exceeded total uncompressed size limit")
    _, err = extractZipFileWithLimit(r.File[0], t.TempDir(), false, 5)
    require.NoError(t, err)
}

I ran an equivalent probe locally and both assertions held.

@copilot please address this.

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

The archive limits still allow disk or inode exhaustion through unbounded implicit parent-directory creation.

3 open issues
What changed in this PR

Adds archive-wide resource limits to the CLI’s GitHub Actions log ZIP extraction, addressing #74889.

Changes:

  • Reject archives exceeding 10,000 entries or 1 GiB of declared uncompressed data before extraction.
  • Track a shared byte budget during extraction and propagate file-close errors.
  • Add multi-entry tests verifying archive-limit rejection occurs before files are created.
File Description
pkg/​cli/​logs_extract_zip_test.go Tests entry-count and total-size preflight rejection.
pkg/​cli/​logs_download_zip.go Adds archive limits, runtime byte accounting, and close-error handling.

Review effort: Max (auto)

Comment on lines +46 to +47
if len(r.File) > maxEntryCount {
return fmt.Errorf("zip archive contains too many entries (max %d)", maxEntryCount)
Comment on lines +323 to +324
}
}
Comment thread pkg/cli/logs_download_zip.go Resolved
@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Note

The pull request was not created — a fallback review issue was created instead due to protected file changes: #74930

PR finisher summary

Submitted for publication (not confirmed pushed): merged main locally, and added a unique-directory cap (maxZipDirectoryCount, preflight) against inode exhaustion; reverted the runtime error to neutral "exceeded size limit" wording; added tests for the runtime byte budget (exact/over budget, byte counts), per-entry limit, multi-entry total boundary and the directory cap.

Validation: go test ./pkg/cli -run Zip passes; impacted tests passed; golangci-lint is not installed in this environment, so lint was not run.

Review replies/resolutions are deferred until the fix is published. CI needs a maintainer re-trigger after publication.

PR finisher dispatch requested for the following outstanding work:

Sous-chef head: fc96c8d
Sous-chef work: 08301dce4fe7e638ee276f7a451280a6a50b67f1105f35e1f74e9a97b4480c44 214398f51f8ce01cb23c52d3df608eed4b51004d023a9e89497857cdd94b8dd1 347a5fadc7183962184a5744e7d285e811deef95a565445c9c9aebdc15ac2e76 5056ef16d8401278bebaba0f07831fc276d9b59172fe75025d91cda2ef9da78d 5edcdb25226932b9ac0266e9dab065f73a2816bee58b362ef7325133a94b41ba c28876159ca821f7a54c43dcb8de4ff30503d0c92be9e8665f0fa5221b212a0c ea2e2cff6a60d434b650037fc939611685654cc3d0af04b4cbe6e80d8e3889bb
Sous-chef state: 9f76074f237cf9c420e9cecfe9f014a10234a2920dd5e1eb4e2c9f1e7d282e69

Generated by 🏁 PR Finisher · copilot · auto · ~24 AIC · ⌖ ~2 AIC · ⊞ 10.7K · ◷

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Ran pr-finisher and pushed ee2c7b21: bounded implicit directory creation, added runtime-budget and exact-boundary tests, and corrected limit-error wording. Formatting, full lint, focused ZIP tests, and the final impacted-test/drift gate passed. CodeQL skipped Go analysis because its database was too large.

Not yet merge-ready: review threads still require replies/resolution, the draft ADR needs maintainer approval and a PR-body link, and mergeability is currently unknown after the push. Thread resolution and PR-body editing are unavailable through the authenticated tools here. CI on the new HEAD remains unverified and needs a maintainer re-trigger; the inspected approval-gated runs had no failed jobs. No merge performed.

Copilot AI requested a review from pelikhan November 4, 2026 19:05
@pelikhan
pelikhan merged commit 2c9a7d5 into main Nov 4, 2026
35 of 36 checks passed
@pelikhan
pelikhan deleted the copilot/uk-ai-resilience-tier-b-zip-log-extraction branch November 4, 2026 19:13
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.0

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.

[uk-ai-resilience] Tier B: ZIP log extraction lacks total size/entry limits (code scanning 1062)

4 participants