Skip to content

chat: completion waiter can block forever on p.Wait() before program startup — session never deregistered #4515

Closed

Description

@dezren39

Finding (from PR review)

Codex (chatgpt-codex-connector[bot]) raised a P2 on PR #4384 — "Synchronize the completion waiter with program startup":

If this goroutine runs before Wish starts the program, p.Wait() blocks forever: in the pinned Bubble Tea v0.25.0 implementation, finished is initialized by Run, not NewProgram, and Wait receives directly from that channel. The Wish middleware calls this handler before p.Run(), so there is no initialization ordering guarantee. An early waiter receives from a nil channel permanently, leaking the new goroutine and preventing that session from ever being deregistered; concurrent initialization also introduces a data race. Tie removal to a lifecycle hook with guaranteed startup ordering or to the return of Run.

Evidence

Acceptance criteria

  • The deregistration waiter can no longer block forever when it runs before the program starts: removal is tied to a lifecycle point with guaranteed startup ordering (e.g. the return of Run, or an equivalent synchronized hook), with no data race on channel initialization.
  • A regression test or equivalent verification covers a session whose waiter starts before the program runs and shows the session is still deregistered.
  • Or: resolve by a documented decision on this issue explaining why the ordering cannot occur in practice.

Activity

  1. added
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/normalOrdinary priority (the default)
    app/chatPackage/app: chat (pkgs/ or apps/ in this repo)
    on Nov 2, 2026
  2. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  4. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 | task 6430 | worker repo-worker-code | lane opencode | session ses_e5e62840746ffesH1oSbEqvXGg | 2026-11-02

    Triage verified against current main: the flaw is real. Bubble Tea v0.25.0 initializes p.finished in Run (tea.go:425), not NewProgram, so the go func(){ p.Wait(); a.remove(p) }() spawned in ProgramHandler (main.go:124-126) can block on a nil channel forever when scheduled before wish's synchronous p.Run() — confirmed empirically (Wait() on a never-run program stays blocked). Wish middleware (wish@v1.2.0/bubbletea/tea.go) calls p.Run() strictly after this handler returns, and always tears the session down right after, so no in-handler Wait can have guaranteed ordering.

    Fix: PR #4521 ties deregistration to session-context cancellation (watchSession) instead of p.Wait() — valid at handler time, session always outlives the program, zero contact with p.finished. Includes TestWatchSessionRemovesOnSessionEnd; go test -race 4/4 pass in pkgs/chat.

  5. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 | task 6430 | worker repo-worker-code | lane opencode | session ses_e5e62840746ffesH1oSbEqvXGg | parked | 2026-11-02

    PR #4521 is open and implementation/tests are complete. The basic OpenCode metered-provider guard remained queued after the five-minute CI poll; task 6430 is parked for 20 minutes. Resume by checking PR #4521 checks and all Codex review findings, then complete once merge criteria are met.

  6. added
    work/assignedQueue worker lifecycle state
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed on Nov 2, 2026
  7. 403 remaining items

  8. added
    status/blockedQueue or user escalation state
    user/escalatedRequires a Drew decision or access
    epic/id-programReprioritization program epic (2026-11-12)
    and removed
    status/triagedTriaged and routed (see agent note)
    on Nov 8, 2026
  9. dezren39 commented on Nov 12, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  10. dezren39 commented on Nov 12, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · blocked / escalated

  11. added and removed
    queue/blockedQueue or user escalation state
    status/blockedQueue or user escalation state
    on Nov 13, 2026
  12. dezren39 commented on Nov 13, 2026

    @dezren39
    MemberAuthor

    Unblocked 2026-11-13 under Drew's order "fix all fixable and reblocked" (set decisions-2026-11-13-blocked-review): queue task(s) 13551 released to the queue. The block rested on the premise that dezren39-authored work is Drew-owned — revoked by Drew's 2026-11-11 authorship ruling (dezren39 is the fleet's working identity; its issues/PRs are fleet work product, not a hold). Verified live at release: issue open, no Drew-hold labels (user/owned, held, do-not-auto-edit).

  13. added a commit that references this issue on Nov 13, 2026
  14. dezren39 commented on Nov 13, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — replacement PR merged; stale escalation retired

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

Metadata

Metadata

Assignees

Labels

app/chatPackage/app: chat (pkgs/ or apps/ in this repo)epic/id-programReprioritization program epic (2026-11-12)priority/normalOrdinary priority (the default)source/pr-comment-reviewFiled by the pr-comment-review job

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions