Skip to content

fix(cli): propagate caller context to agent log session parser subprocess - #77628

Merged
pelikhan merged 6 commits into
mainfrom
sergo/thread-ctx-agent-log-parse-r128-5b0808500d677171
Nov 14, 2026
Merged

pelikhan merged 6 commits into
mainfrom
sergo/thread-ctx-agent-log-parse-r128-5b0808500d677171

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Thread the caller's context.Context through the agent-log parsing helpers so the Node session-parser subprocess is cancelled together with gh aw logs / gh aw audit.

Evidence

runSessionParserWithSources (pkg/cli/session_parser.go:123) uses exec.CommandContext(ctx, "node", ...), but these callers passed context.Background():

  • pkg/cli/logs_parsing_persisted.go parseUnifiedAgentLog: 2 sites
  • pkg/cli/logs_parsing_javascript.go parseAgentLog: 3 sites

Every production caller already held a cancellable context and dropped it:

Caller ctx available
orderedLogsRunCollector.processReadyResult → parseWorkflowRunArtifacts c.ctx
stdin logs orchestrator (logs_orchestrator_stdin.go) ctx
renderPreparedAuditReport → parseAuditLogsIfRequested → parseAgentLogIfRequested ctx

Impact: on Ctrl+C or a deadline, node session-parser children kept running to completion. The sibling session parsers (sessions_download.go, session_normalization.go, session_atif.go) already pass ctx.

Change

Add a leading ctx context.Context parameter to parseAgentLog, parseUnifiedAgentLog, parsePersistedAgentLog, parseWorkflowRunArtifacts, parseAuditLogsIfRequested and parseAgentLogIfRequested, and pass the caller's context. Existing tests now pass t.Context(). No behaviour change when the context is never cancelled.

Validation

  • Serena (gopls) diagnostics on audit_render_output.go, logs_parsing_javascript.go, logs_orchestrator_download.go and logs_parsing_persisted_test.go: 0 errors.
  • Grep confirmed no remaining callers of the old signatures anywhere in the repo.
  • Not run: go build, go test, make fmt. The go and make commands were denied in this sandbox, so please rely on CI for compile and test results.
  • Scope: only the agent-log parsing chain was changed. Other context.Background() sites in pkg/cli were not audited in this PR.

🤖 Generated with [Claude Code]((claude.com/redacted)

Generated by 🤖 Sergo - Serena Go Expert · claude · routed: sonnet55 high · ~78 AIC · ⌖ ~2 AIC · ⊞ 4.7K · ◷

  • expires on Nov 20, 2026, 7:53 PM UTC-08:00

@github-actions github-actions Bot added cookie Issue Monster Loves Cookies! sergo labels Nov 14, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 14, 2026 05:53
Copilot AI adaptive review requested due to automatic review settings November 14, 2026 05:53
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ 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 by Ponytail Reviewer for #77628 · codex · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 182 · ◷

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~4 AIC · ⌖ ~2 AIC · ⊞ 6.6K · ◷

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt56 · ~2 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.5K · ◷

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 8.6K · ◷

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Specification Reviewer completed successfully!

PR Specification 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 by PR Specification Reviewer for #77628 · copilot · gpt56 · ~2 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

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 tests do not exercise cancellation during parsing, leaving the fix unprotected against regressions that ignore the supplied context or create log.md despite cancellation.

1 open issue
What changed in this PR

This PR threads caller contexts through the CLI’s agent-log parsing chain so Node session-parser subprocesses can be cancelled with gh aw logs and gh aw audit.

Changes:

  • Pass caller contexts through persisted, unified, and engine-specific log parsers.
  • Connect download, stdin, and audit callers to the updated helpers.
  • Update existing tests to pass t.Context().
File Description
pkg/​cli/​session_parser_test.go Update parser tests for context parameters.
pkg/​cli/​logs_parsing_persisted.go Forward context to reconstruction and rendering subprocesses.
pkg/​cli/​logs_parsing_persisted_test.go Update persisted-log tests for context parameters.
pkg/​cli/​logs_parsing_javascript.go Forward context through all agent-parser paths.
pkg/​cli/​logs_parse_test.go Update missing-input tests for context parameters.
pkg/​cli/​logs_orchestrator_stdin.go Pass the stdin orchestrator’s context to parsing.
pkg/​cli/​logs_orchestrator_download.go Pass the collector’s context through artifact parsing.
pkg/​cli/​logs_engine_definition_test.go Update engine-parser tests for context parameters.
pkg/​cli/​audit_render_output.go Thread the audit context through log-parsing helpers.
pkg/​cli/​audit_render_output_test.go Update audit helper tests for context parameters.

Review effort: Balanced (dynamic)

args = append(args, engineID)
}
session, err := runSessionParser(context.Background(), args...)
session, err := runSessionParser(ctx, args...)

Copilot AI commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Build code

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (spec-review-history)
{"id":"ldg-c706de1d-7a8f-4542-a3e2-3941d2679b22","parents":[],"payload":{"id":"ldg-91d83a03-dfae-4fd1-bd29-6bfc3fc53224","operation":"append","value":{"finding_count":0,"head_sha":"1a3ee94442516f7c287a5b84cbdf2f838d8c5c2d","outcome":"aligned"}},"sha":"sha256:36cff38c729e0010ed74f4d37b370a083edeb82297b85ead825a3dffb60c058e","timestamp":"2026-11-14T06:03:00.943Z","type":"ledger_append","version":1}
History

@github-actions github-actions Bot left a comment

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.

Reviewed the context propagation changes across the agent-log parsing chain. The updated call sites consistently pass their existing caller contexts into the Node session parser, and the changes preserve existing behavior while enabling cancellation. No blocking correctness or maintainability issues found in the diff.

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

@github-actions github-actions Bot left a comment

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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd. The signature change is mechanically sound: no context.Background() remains in the parse chain, and every caller now passes a context. Two inline suggestions below; neither blocks merge.

📋 Key Themes & Highlights

Key Themes

  • Incomplete propagation: parseFirewallLogs in the same audit path still runs an unscoped node child (inline on audit_render_output.go:189).
  • No cancellation regression test: every updated test passes t.Context(), which is never cancelled (inline on session_parser_test.go:382).
  • Compile not verified: go vet ./pkg/cli/ fails at pkg/workflow/imports.go:585 (undefined: topRawSafeOutputs). The base commit b4b6c18 has the same break, so it predates this PR and is out of scope here, but pkg/cli cannot be type-checked from this checkout to confirm the new signatures.
  • Misleading error on cancel (nit): session_parser.go:138 reports every non-zero exit as Node.js is required. A mid-run cancel kills the child and may surface that message. I only confirmed the pre-cancelled path, which returns context.Canceled correctly.

Positive Highlights

  • ✅ Consistent change across all six functions and their tests
  • ✅ Changed files are gofmt-clean
  • ✅ The collector passes its batch-scoped c.ctx, so cancellation reaches the right parser

@copilot please address the review comments above.

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

root := t.TempDir()
writeSessionTestFile(t, root, "agent-stdio.log", `{"type":"assistant","message":{"content":[{"type":"text","text":"Audit parser works"}]}}`+"\n")
require.NoError(t, parseAgentLog(root, workflow.NewClaudeEngine(), false))
require.NoError(t, parseAgentLog(t.Context(), root, workflow.NewClaudeEngine(), false))

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.

[/tdd] This test now passes t.Context(), which is never cancelled. It shows nothing regressed, but not that the fix works. Add a test that cancels the context before the call and asserts the cancellation is returned. It catches any of the five sites reverting to context.Background().

💡 Suggested test

Write an agent-stdio.log first, or the parser is never reached and the assertion cannot exercise cancellation:

ctx, cancel := context.WithCancel(t.Context())
cancel()
err := parseAgentLog(ctx, root, workflow.NewClaudeEngine(), false)
require.ErrorIs(t, err, context.Canceled)

The %w wrap in runSessionParserWithSources keeps errors.Is working. Call requireSessionTestNode(t) first, as the sibling tests do.

@copilot please address this.

auditLog.Printf("Parsing agent and firewall logs for run %d", runID)
parseAgentLogIfRequested(runID, runOutputDir, opts.Verbose)
parseAgentLogIfRequested(ctx, runID, runOutputDir, opts.Verbose)
parseFirewallLogsIfRequested(runID, runOutputDir, opts.Verbose)

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.

[/diagnosing-bugs] The cancellation fix stops at this call. parseAuditLogsIfRequested now receives ctx, but parseFirewallLogsIfRequested is still called without it, and parseFirewallLogs runs exec.Command("node", ...) at pkg/cli/logs_parsing_firewall.go:219. Ctrl+C or a deadline will still leave that node child running, which is the same symptom this PR fixes.

💡 Suggested change

Thread ctx through the firewall helpers the same way, and switch the child to exec.CommandContext(ctx, "node", nodeFile). If the firewall path is deliberately deferred, say so in the PR description.

@copilot please address this.

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (review-history)
{"id":"ldg-9995d410-8c1b-43c0-b556-1d18e2060f25","parents":[],"payload":{"id":"ldg-e9255df6-5eec-4fad-a585-3ba782453e6a","operation":"append","value":{"finding_count":0,"head_sha":"1a3ee94442516f7c287a5b84cbdf2f838d8c5c2d","outcome":"no_findings"}},"sha":"sha256:60d93d9523a577ffaac021332a4c466ce22061b3dd098680356e9ba09111b030","timestamp":"2026-11-14T06:04:14.486Z","type":"ledger_append","version":1}
History

@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. Fix failing check actions-build (FAILURE): Check run.
  3. Fix failing check Alpine Container Test (FAILURE): Check run.
  4. Fix failing check build (FAILURE): Check run.
  5. Fix failing check Build Windows CLI (FAILURE): Check run.
  6. Fix failing check build-wasm (FAILURE): Check run.
  7. Fix failing check copilot-pull-request-reviewer (FAILURE): Check run.
  8. Fix failing check impacted-go-tests (FAILURE): Check run.
  9. Fix failing check lint-go-custom (FAILURE): Check run.
  10. Fix failing check lint-go-golangci (0) (FAILURE): Check run.
  11. Fix failing check lint-go-golangci (1) (FAILURE): Check run.
  12. Fix failing check lint-go-golangci (2) (FAILURE): Check run.
  13. Fix failing check lint-go-govulncheck (FAILURE): Check run.
  14. Fix failing check mcp-server-compile-test (FAILURE): Check run.
  15. Fix failing check Native JavaScript and Actions parser tests (FAILURE): Check run.
  16. Fix failing check verify-integration-build (FAILURE): Check run.

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

Structured data
{
  "completed_task": 0,
  "head": "1a3ee94442516f7c287a5b84cbdf2f838d8c5c2d",
  "kind": "requested",
  "schema_version": "1",
  "state": "30d653b5d27dd8efc35ae36b6cc7116b3a8932e19f660f6cde4b3f346f581450",
  "work": [
    "1027833686a7050a64d8bfe136387980a34b94be7e9b120f51fd825652824672",
    "12e2d92b8c5b535f1d3147e14962e78f9a50d376e8a16f13e4326968dc5aa3f5",
    "20c5fb9e2e37672daf5b7271dae9c95ff59f03cf41d0cde5ac7e2acc9456d2d1",
    "3015d50f40986eeb1f70f6abd38b628ae18e0dd02ea748d522efe0d66f80a51f",
    "41c633c50467b0f2dc87116833139ebf287e1ad59f1a015d8d1dfedd9d1b23f1",
    "42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac",
    "4ce4dd407e604d374ecd66edfd2afc18c54e2d0b3733dbac37ac8e9c8834fdba",
    "6890db2d1f5ad1e52f17f44fea3b0f5de9e2441b83440ac6d6a8b68ece43deff",
    "8acb61a077717e3a460018aacdfde96fd489f77606cd36169e2328d9079b75bb",
    "9f329b57d351108a3c97449b5c5517fec3d320c266cdf992b531b7673be16e95",
    "b855fc6fcb55b78d8a97b8924885cae846819f33bbc1dec6e0b470fbcf24991c",
    "cabafb2817b103330ac0d1e2e098f214c40c4ca2be128895a8b14391f7e3306f",
    "e2b1dcdd50909d11ea908683e207665058785302844e162780d5fdb2120a01e0",
    "f608a3b4d2ea8983984f0ad739cad7561bee404a606e877bbdf42d2f19569a73",
    "f7883e8c8105930e955354caa741d783bcca067e66097fe9612fb72b90823998"
  ],
  "workflow": "pr-sous-chef"
}

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

gh-aw-bot and others added 2 commits November 14, 2026 06:33
…t-log-parse-r128-5b0808500d677171

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@copilot

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

Merged main in 00a70728; the reported build failures shared the missing topRawSafeOutputs definition, now supplied by main. I also addressed the persisted-parser custom-lint finding in b18a0b59. Focused CLI and workflow tests pass, and the final impacted tests passed. Workflow recompilation was blocked by npm-feed DNS failures; CodeQL timed out. No workflows were triggered.

@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. Fix failing check impacted-go-tests (FAILURE): Check run.

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

Structured data
{
  "completed_task": 0,
  "head": "b18a0b59c2de744b3f373c8b967ad9bbc66684b8",
  "kind": "requested",
  "schema_version": "1",
  "state": "7ad13d99c65e2d51a73386ee9b465eb9e30bc56e841e3d0fd24b67d62d50c6ce",
  "work": [
    "42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac"
  ],
  "workflow": "pr-sous-chef"
}

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

…t-log-parse-r128-5b0808500d677171

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
gh-aw-bot and others added 2 commits November 14, 2026 07:47
if parserSource := behaviorEngine.GetLogParserScriptSource(); parserSource != "" {
output, err = runSessionParserWithSources(
context.Background(),
ctx,
}
output, err := runSessionParserWithSources(
context.Background(),
ctx,

Copilot AI commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@copilot

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

Merged the latest main via make merge-main (1b8d652). Fixed the impacted Go test failure by updating the stale contract assertion to match current workflow guidance; the focused test and final validation pass. Fix: 9ff753c.

@pelikhan
pelikhan merged commit a4cf1c6 into main Nov 14, 2026
49 checks passed
@pelikhan
pelikhan deleted the sergo/thread-ctx-agent-log-parse-r128-5b0808500d677171 branch November 14, 2026 14:08
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.3.0

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

Labels

cookie Issue Monster Loves Cookies! sergo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants