Skip to content

mac: drain the helper's stderr on termination, so an abnormal exit says why - #683

Merged
GoKubar merged 3 commits into
mainfrom
agent/astra/helper-stderr-swift
Sep 16, 2026
Merged

GoKubar merged 3 commits into
mainfrom
agent/astra/helper-stderr-swift

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Split out of #659 so it can land without the workflow token scope.

The bug

LineProcessClient and PreviewControllerClient both cleared the stderr readability handler inside the termination handler and then drained stdout only. A helper's last words — the panic message, the failed open — were discarded along with the pipe. So every abnormal helper exit in this app has been throwing away its own explanation, leaving callers with a bare helper exited (1).

Both now drain stderr the way they already drain stdout, and the controller carries the last line onto the exit:

helper exited (1): thread 'main' panicked at ...

Every consumer matches on the helper exited prefix, so appending a reason changes no decision — the new test in PreviewControllerTests pins exactly that, so a future refactor cannot quietly turn the message into a behavioural dependency.

Why now

IMECompositionTests.testCancelledCompositionLeavesTheHelperAndLedgerUntouched deterministically aborts the Mac suite (#681) — confirmed identical across three unrelated branches, always at that same test, right after HostedWindowSupportTests.testTheCompletionPopupFollowsItsHostOffScreen passes. That test drives a real helper subprocess and awaits holds(...), helperDocument() and historyLabels(). Whatever the helper is saying as it dies is currently being thrown away, which is a large part of why the abort has been so hard to characterise.

This change does not fix #681. It makes #681 diagnosable.

Relationship to #659

#659 remains open for its other half: a SNAPSHOT_ARTIFACTS upload step in .github/workflows/ci.yml plus the .gitignore entry. The authenticated token on this machine carries gist, read:org, repo but not workflow, so GitHub refuses to merge any PR touching .github/workflows/** from here:

refusing to allow an OAuth App to create or update workflow
`.github/workflows/ci.yml` without `workflow` scope

Nothing in this commit depends on that half. Credit for the original diagnosis and implementation belongs to #659's author; this is the same Swift diff, taken verbatim onto current main.

GoKubar and others added 2 commits September 16, 2026 00:07
…ys why

Both `LineProcessClient` and `PreviewControllerClient` cleared the stderr
readability handler in the termination handler and then drained stdout only,
so a helper's last words -- the panic message, the failed open -- went out
with the pipe. Every abnormal helper exit in this app has been discarding its
own explanation.

Both now drain stderr the way they already drain stdout, and the controller
carries the last line onto the exit:

    helper exited (1): thread 'main' panicked at ...

Every consumer matches on the `helper exited` prefix, so appending a reason
changes no decision; the new test in `PreviewControllerTests` pins that.

This is the Swift half of #659, split out so it can land now: #659 also adds
a `SNAPSHOT_ARTIFACTS` upload step to `.github/workflows/ci.yml`, and the
authenticated token on this machine lacks the `workflow` scope, so the
combined PR cannot be merged here. The CI half stays on #659 for an
operator with that scope. No behaviour in this commit depends on it.

Motivation is immediate: `IMECompositionTests
.testCancelledCompositionLeavesTheHelperAndLedgerUntouched` deterministically
aborts the Mac suite (#681), and that test drives a real helper subprocess.
Whatever the helper is saying as it dies is currently being thrown away.

Implementation-Agent: Claude Opus 5 (orchestrator-astra, linux-primary)
Commit-Executor: Claude Opus 5 via Claude Code (direct-agent Git execution
under the observed-Cursor-limit user override)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Two defects in the rebased change, both in PreviewControllerClient:

- `maxStderrTailBytes` is named in bytes and the overflow check reads
  `utf8.count`, but the trim used `String.suffix(n)`, which counts grapheme
  clusters. A helper logging non-ASCII could hold several times the stated
  bound. Trim on the UTF-8 view instead; decoding repairs a scalar split at
  the new start, which is fine for an evidence tail.
- The new members were inserted between `deliver`'s doc comment and `deliver`,
  so the comment had silently become the documentation for `recentStderr`.

Implementation-Agent: claude-opus-5 (export-consolidation lane)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
@GoKubar
GoKubar force-pushed the agent/astra/helper-stderr-swift branch from da44b28 to 87a0cd7 Compare September 16, 2026 04:08
`handleController` opens with `guard let controller else { return }`, so inside
the function `controller` is a non-optional `PreviewControllerClient` shadowing
the optional property — which is also why the same block writes `self.controller
= nil` explicitly. The new `recentStderr` reads used `controller?.`, which does
not compile:

  error: cannot use optional chaining on non-optional value of type
         'PreviewControllerClient'

This was a genuine defect in the change, not (as first thought) a contaminated
worktree: it reproduces on a clean build of the rebased branch at 87a0cd7.

Implementation-Agent: claude-opus-5 (export-consolidation lane)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit)
Co-authored-by: GoKubar <[email protected]>
@GoKubar
GoKubar merged commit bc68ae8 into main Sep 16, 2026
18 of 21 checks passed
d-q222 added a commit that referenced this pull request Sep 16, 2026
#659 re-added stderr-tail draining that #683 already merged into main
independently. The merge concatenated both insertions with no conflict
markers (each patch's context didn't overlap enough for git to flag it),
leaving two declarations of the same members -- 'ambiguous use of
recentStderr' at the build step. Kept #659's version (UTF-8-safe trim,
avoids splitting a multi-byte scalar at the truncation boundary); removed
#683's plain grapheme-count .suffix() version, and reattached its orphaned
doc comment to deliver(), where it belongs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant