Skip to content

Preserve CLI proxy timeout diagnostics when logs exceed the capture limit - #76538

Merged
pelikhan merged 5 commits into
mainfrom
copilot/fix-startup-timeout-diagnostics
Nov 10, 2026
Merged

pelikhan merged 5 commits into
mainfrom
copilot/fix-startup-timeout-diagnostics

Conversation

Copilot AI commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

CLI proxy logs exceeding the capture limit suppressed both the startup failure reason and all captured diagnostics. This change separates failure reporting from capture and retains a bounded, redacted log tail.

  • Failure reporting: Emit timeout and upstream-connectivity errors directly before collecting container logs.
  • Bounded diagnostics: Retain the final log lines, report truncation separately, and avoid failing successful startup solely because logs overflow.
  • Redaction safeguards: Collect mask registrations across the full stream, bound their count and size, discard partial leading lines, and withhold output if redaction fails.

Copilot AI changed the title [WIP] Fix startup timeout diagnostics loss in CLI proxy log Preserve CLI proxy timeout diagnostics when logs exceed the capture limit Nov 10, 2026
Copilot AI requested a review from pelikhan November 10, 2026 15:16
@pelikhan
pelikhan marked this pull request as ready for review November 10, 2026 15:35
Copilot AI adaptive review requested due to automatic review settings November 10, 2026 15:36
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #76538

@github-actions

github-actions Bot commented Nov 10, 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: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

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

Generated from PR Code Quality Reviewer · gpt56 · ~7 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

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

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

Generated by PR Specification Reviewer for #76538

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

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 Design Decision Gate 🏗️ · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 8.5K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@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.

What this change does: It retains a bounded, redacted tail of CLI proxy diagnostics and reports startup failures directly.

One simplification: remove the file-input mode now that production uses stream capture, and move its relevant tests to the capture path.

Verdict: Ship.
Lean: -15 lines possible.

Generated by ✂️ Ponytail Reviewer for #76538 · codex · routed: gpt61 medium · ~5 AIC · ⌖ ~1 AIC · ⊞ 181
Comment /ponytail to run again

const content = readCliProxyDiagnostics(process.argv[2]);
const redacted = redactCliProxyDiagnostics(content, process.env);
process.stdout.write(redacted.trimEnd().split("\n").slice(-20).join("\n"));
const captured = process.argv[2] === "--capture" ? await captureCliProxyDiagnostics(process.stdin) : null;

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 only production caller now uses --capture, so the file-input branch and readCliProxyDiagnostics are used only by tests. Remove that mode and move the relevant output tests to capture; this removes a second input path and its file-only tests without changing the proxy or gateway callers.

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.

Addressed in e585ddf: removed the file-input branch and readCliProxyDiagnostics, migrated output coverage to stream capture, and removed file-only tests. The gateway’s shared redaction API is unchanged.

@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.

Reviewed PR head 2e5e2768b180e8a6d6ddab47c13bde388d893030 against specs/compiler-threat-detection-spec.md §5.2.2 (Proxy Startup Diagnostic Privacy).

Blocking finding: the new capture path publishes a bounded/truncated tail on overflow, whereas the existing MUST contract requires withholding the entire captured payload and emitting only a fixed, value-free error; partially sanitized or truncated raw output MUST NOT be published. Inline comment added on actions/setup/sh/start_cli_proxy.sh:77. No specification synchronization is eligible because the implementation change conflicts with the mandatory security contract.

Generated by PR Specification Reviewer for #76538 · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review-specs to run again

Comment thread actions/setup/sh/start_cli_proxy.sh Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-10T15:40:00Z
review_event: COMMENT
top_themes: [capture-tail-copying, weakened-fail-closed-tests]
files_reviewed: [actions/setup/js/redact_cli_proxy_diagnostics.cjs, actions/setup/js/start_cli_proxy.test.cjs, actions/setup/sh/start_cli_proxy.sh]
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 · ~7 AIC · ⌖ ~2 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.

Found two low-severity issues: the capture loop copies the retained 1 MiB tail on every chunk, causing avoidable O(log_size × 1 MiB) copying for oversized logs; and sanitizer-failure tests were weakened from exact-output checks to substring checks, allowing partial diagnostic leakage to pass. No blocking correctness issue identified in the static review. Tests were not run per review constraints.

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

const result = runProxy({ ready, sanitizerFailure: true });
expect(result.status).toBe(1);
expect(result.output).toBe("::error::CLI proxy diagnostics withheld because secret redaction failed\n");
expect(result.output).toContain("::error::CLI proxy diagnostics withheld because secret redaction failed\n");

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.

These assertions no longer guarantee the fail-closed output is the only published output. A regression could emit partial sanitizer content and still satisfy toContain. Please assert exact stdout (or explicitly assert that no diagnostic payload is present) for both sanitizer-failure cases.

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.

Addressed in e585ddf: sanitizer-failure tests now assert empty stdout and exact stderr, including the separately emitted timeout message where applicable. Partial diagnostic output fails these assertions.

const text = chunk.toString().replaceAll("\0", "");
const bytes = Buffer.from(text);
truncated ||= tail.length + bytes.length > MAX_DIAGNOSTIC_BYTES;
tail = Buffer.concat([tail, bytes]).subarray(-MAX_DIAGNOSTIC_BYTES);

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 rebuilds and copies up to the full 1 MiB retained tail for every stdin chunk. On a large Docker log, that makes capture cost grow roughly as O(log_size × 1 MiB), adding substantial CPU and memory bandwidth precisely on the overflow path. Please use a bounded chunk/ring-buffer approach or trim only when the retained buffer exceeds a larger threshold.

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.

Addressed in e585ddf: capture stores bounded chunks and concatenates only once. On overflow it discards all stored chunks and drains remaining input without copying a retained tail.

@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.

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

}
collectMasks(pending);
// Never publish the first partial line: truncation could split a credential.
const content = truncated ? tail.subarray(tail.indexOf(10) + 1).toString("utf8") : tail.toString("utf8");

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] When the tail has no newline, indexOf(10) + 1 evaluates to 0, so the slice keeps the whole buffer. Line 96 is the only guard that stops a partial line from being published. This invariant is subtle and easy to break in a refactor.

💡 Suggested change

Add a one-line comment explaining that the empty-string guard on line 96 is what prevents publishing a truncated first line. Add a direct unit test for a truncated tail that contains no newline.

@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.

Addressed in e585ddf: restoring fail-closed overflow removes the partial-line slicing invariant entirely. A comment explains that unterminated partial lines are also withheld, and the direct no-newline overflow test asserts both streams are empty.

const result = runProxy({ ready, sanitizerFailure: true });
expect(result.status).toBe(1);
expect(result.output).toBe("::error::CLI proxy diagnostics withheld because secret redaction failed\n");
expect(result.output).toContain("::error::CLI proxy diagnostics withheld because secret redaction failed\n");

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] This exact toBe assertion on withheld output was changed to toContain, so the test no longer proves that nothing else reaches the output. Restore an exact check on the withheld stdout, or assert the full output matches the expected diagnostic lines.

💡 Suggested assertion

Assert the complete result.output against the expected withheld message, so any extra leaked line fails the test.

@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.

Addressed in e585ddf: replaced substring checks with exact empty-stdout and full-stderr assertions for sanitizer execution failure, thrown redactor exceptions, and missing sanitizer cases.

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

Redaction ordering and byte-boundary handling can discard useful diagnostics or complete retained lines, leaving logs empty.

3 open issues
What changed in this PR

This PR addresses #76449 by keeping CLI proxy startup failure messages visible when logs exceed the capture limit, while preserving a bounded, redacted diagnostic tail.

Changes:

  • Reports timeout and upstream-connectivity failures independently of log capture.
  • Adds streaming tail capture with bounded mask metadata and fail-closed redaction.
  • Extends tests for oversized logs, successful startup, partial lines, and mask limits.
File Description
actions/​setup/​sh/​start_cli_proxy.sh Separates failure reporting from capture and publishes sanitized tails with truncation warnings.
actions/​setup/​js/​start_cli_proxy.test.cjs Checks failure messages, bounded diagnostics, and successful startup despite oversized output.
actions/​setup/​js/​redact_cli_proxy_diagnostics.test.cjs Adds capture tests for mask retention, partial-line removal, and metadata limits.
actions/​setup/​js/​redact_cli_proxy_diagnostics.cjs Implements bounded streaming capture, full-stream mask collection, and output-size enforcement.

Review effort: Max (auto)

Comment on lines +81 to +96
tail = Buffer.concat([tail, bytes]).subarray(-MAX_DIAGNOSTIC_BYTES);
const lines = (pending + text).split("\n");
pending = lines.pop() || "";
for (const line of lines) collectMasks(line);
// Keep scanning giant lines for commands without retaining their full prefix.
const command = pending.indexOf("::add-mask::");
if (command !== -1) pending = pending.slice(command);
if (Buffer.byteLength(pending) > MAX_DIAGNOSTIC_BYTES) {
if (command !== -1) throw new Error("CLI proxy mask limit exceeded");
pending = Buffer.from(pending).subarray(-MAX_DIAGNOSTIC_BYTES).toString("utf8");
}
}
collectMasks(pending);
// Never publish the first partial line: truncation could split a credential.
const content = truncated ? tail.subarray(tail.indexOf(10) + 1).toString("utf8") : tail.toString("utf8");
return { content: truncated && !tail.includes(10) ? "" : content, truncated, masks: [...masks] };
const redacted = redactCliProxyDiagnostics(content, process.env);
process.stdout.write(redacted.trimEnd().split("\n").slice(-20).join("\n"));
const captured = process.argv[2] === "--capture" ? await captureCliProxyDiagnostics(process.stdin) : null;
const content = captured ? captured.content.trimEnd().split("\n").slice(-20).join("\n") : readCliProxyDiagnostics(process.argv[2]);
Comment on lines +123 to +124
const tail = Buffer.from(output).subarray(-MAX_DIAGNOSTIC_BYTES);
output = tail.includes(10) ? tail.subarray(tail.indexOf(10) + 1).toString("utf8") : "";
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (actions/setup/js/redact_cli_proxy_diagnostics.cjs:117): address unresolved feedback - Review comment
  3. Review (actions/setup/sh/start_cli_proxy.sh:77): address unresolved feedback - Review comment
  4. Review (actions/setup/js/start_cli_proxy.test.cjs:337): address unresolved feedback - Review comment
  5. Review (actions/setup/js/redact_cli_proxy_diagnostics.cjs:81): address unresolved feedback - Review comment
  6. Review (actions/setup/js/redact_cli_proxy_diagnostics.cjs:95): address unresolved feedback - Review comment
  7. Review (actions/setup/js/start_cli_proxy.test.cjs:337): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "2e5e2768b180e8a6d6ddab47c13bde388d893030",
  "kind": "requested",
  "schema_version": "1",
  "state": "2e56f8aac1536dc65ed8beab140448e346b1104cee79b12311fe3b5d29631475",
  "work": [
    "5371a7c744076eaa4ea7ea1b61bc447a45468d7b4ba16851a304d2c87b2e8780",
    "66dd2306415ecb7c578e7e47a41c1f8adf7a3f1f868fa7634e96b6cfd7010a64",
    "8166fc635be3561e78f601b760a3dd0de11658c0575faf0f62f55995440a7b9a",
    "8735b77ff9fcbe649e584627ec82a9938cd5055ac7c90a06d600572234e8ddb4",
    "c949b77c6058eaf5000a0ded8d45f7b01eb267eb6e754e93ea89b516669e22f7",
    "f4144ba94041362ebd70aa4b5e8fac9be87d303b0fbda438aba7fcc3bb98b8a2"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 6.9K · ◷
Comment /souschef to run again

Copilot AI commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Updated from main using make merge-main (merge commit 7bc4a4f) and addressed all six linked requests in e585ddf. Overflow now withholds the entire payload per the privacy contract while preserving separately emitted startup failure reasons; unused file mode and repeated tail copying are removed, with exact leakage assertions restored. Build and all 365 workflow compilations passed; focused proxy/gateway tests passed (282 passed, 1 skipped), the final validation gate passed, and secret scanning found no secrets. CodeQL timed out and instructed against retrying, so that check remains incomplete. No PR merge or CI dispatch was performed.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot ensure this change is privacy preserving, no secrets are leaked

Copilot AI commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ensure this change is privacy preserving, no secrets are leaked

Reviewed the capture/publish path: raw diagnostics are processed in memory and only the redacted result can reach the private temporary capture file. Overflow and redaction failures publish no diagnostic payload and emit only fixed, value-free errors. The tests assert empty output on these failure paths and verify GH_TOKEN, registered masks, proxy variables, and built-in token patterns are redacted. Focused tests pass (57/57), and the branch’s impacted-js-tests CI job passed. No further code change was needed.

@pelikhan
pelikhan merged commit 40af6db into main Nov 10, 2026
114 checks passed
@pelikhan
pelikhan deleted the copilot/fix-startup-timeout-diagnostics branch November 10, 2026 22:07
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.3

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.

A startup timeout loses its diagnostics when the CLI proxy log overflows the capture limit

4 participants