Skip to content

fix: agent exits promptly after a short trace drains - #25

Merged
CodingInAVan merged 1 commit into
mainfrom
drain-fix
Jun 24, 2026
Merged

fix: agent exits promptly after a short trace drains#25
CodingInAVan merged 1 commit into
mainfrom
drain-fix

Conversation

@CodingInAVan

Copy link
Copy Markdown
Contributor

Problem

gpufl trace --upload hung for ~60s at the very end of short traces (e.g. the tutorials) even though the upload UI already showed "complete." The launcher would eventually hard-kill the agent and print a misleading "late windows may need a post-hoc gpufl upload" warning.

Root cause

In exit-when-drained mode, GpuflAgent.awaitDrainThenExit only declared a session "drained" after it had observed the live .tmp/ window marker through its 1s poll (sawActive). A short trace creates and finalizes (removes) that marker between two polls, so sawActive never flipped — the drain loop spun forever. The launcher then waited out its full --agent-drain-ms cap (60s) and hard-killed the agent.

Fix

Gate the drain on a cumulative signal instead of the race-prone .tmp/ observation:

  • TailerManager.hasStartedAnySession() — backed by the startedSessions keyset, which is added to on discovery and never cleared.
  • Drain = started && activeTailers == 0 && !anyActiveSession, two consecutive clean polls.

The window-model LogTailer only decrements activeTailers after a window is fully sent, so there's no premature-exit risk. The agent now self-exits ~2–3s after the upload drains.

Refactor (folded in)

Centralized the agent's magic-number sleeps into a Delays utility with an interrupt-aware sleep() helper, replacing ad-hoc Thread.sleep/catch blocks across GpuflAgent, LogTailer, SessionWatcher, and TailerManager. signalSessionComplete also gains exponential backoff and slf4j logging.

Testing

  • ./gradlew build green (unit tests + jacoco).
  • Verified end-to-end: a short gpufl trace --upload now finishes immediately after "agent finished uploading" — no 60s hang.

@CodingInAVan
CodingInAVan merged commit 3db0885 into main Jun 24, 2026
1 check passed
@CodingInAVan
CodingInAVan deleted the drain-fix branch June 24, 2026 01:46
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.

1 participant