Skip to content

Link anonymous thread and turn lifecycle events - #5438

Closed
brsbl wants to merge 4 commits into
bb/core-capability-use-main-thr_a4mhd93zjifrom
bb/thread-turn-lifecycle-main-thr_a4mhd93zji
Closed

brsbl wants to merge 4 commits into
bb/core-capability-use-main-thr_a4mhd93zjifrom
bb/thread-turn-lifecycle-main-thr_a4mhd93zji

Conversation

@brsbl

@brsbl brsbl commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Work events cannot reliably connect an accepted message to its turn, especially after queueing or retry.

What changed

  • Persist random analytics-only thread, parent, and message IDs separately from content and public thread records.
  • Report applied lifecycle transitions and coarse turn outcomes after commit, retaining queue groups and original acceptance timestamps.
  • Reuse retry provenance, exclude steering from turn origins, and report unavailable links without guessing.
  • Restrict new turn outcome provider values to shipped declarations, including after custom providers are disabled.

How you verified

  • Remote CI passed at a96641c3e8.
  • ACP-next ran uncached in the sequential Windows host shard; its original tests and timeouts are unchanged.
  • Real Codex root, child, follow-up, and grouped queued turns completed through the branch app/server/daemon.
  • Thread, parent, and request IDs joined correctly; archiving emitted the expected lifecycle transition.
  • A real Claude rejection using an isolated invalid OAuth token emitted failed/auth.
  • A due one-shot automation completed with trigger: schedule, using the same turn events as other work.
  • Production-sender payloads were captured locally and screened for identifying content; no production PostHog delivery occurred.
  • The older Claude error path without an HTTP status remains a separate categorization limitation.
  • Cumulative verification used 207404a8b7; the later Capture anonymous plugin usage through shared boundaries #5439 fix changes only plugin RPC request metadata.
Prior implementation verification and review history
  • Remote CI passed at 41e9b51b.
  • Privacy regressions failed before the fix and passed afterward on Linux and Windows.
  • Cumulative review covered the stack at 654570f7; its provider privacy finding is fixed and validated without repeating the review.
  • Exact-head app/server/daemon → deterministic ACP process → local capture verified root/child IDs, continuation, queued sends, stop, opt-out, restart persistence, and a disabled custom provider mapping to other.
  • A grouped queued send on the unchanged descendant 40972c58 emitted both accepted message IDs on turn_started and turn_finished. The original QA request used an incomplete expected queue prefix; correcting that fixture request completed the check.
  • Retry, steer, permission, and failure variants are covered in remote CI rather than every variant in the live pass.
Recorded P2 follow-ups
  • Soft deletion can clear analytics state before final runtime settlement; startup cancellation can lose the pending request link.
  • Retained-turn reconciliation can count another start; host interruption can be categorized as start_failed.
  • first_turn uses current root-thread count rather than historical first completion.
  • Request-origin lookup scans historical request JSON.

Original implementation thread: Retention measurement

BB-Thread: Growth analytics

BB-Thread-ID: thr_a4mhd93zji

AGENT GENERATED

@brsbl
brsbl added this pull request to stack #5440 October 13, 2026 17:43
@brsbl
brsbl marked this pull request as ready for review October 13, 2026 19:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a96641c3e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +422 to +426
if (transition === "thread_deleted") {
deps.db
.delete(telemetryThreads)
.where(eq(telemetryThreads.threadId, thread.id))
.run();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve telemetry state until deleted turns settle

When a running thread is soft-deleted, its runtime can settle later, but this immediately removes its persisted analytics identity and request linkage. A subsequent lifecycle settlement therefore either recreates a different thread_analytics_id or cannot emit the final outcome, severing the turn from its earlier turn_started and message events. Defer this cleanup until the runtime has settled or the thread is physically removed.

Useful? React with 👍 / 👎.

Comment on lines +137 to +141
if (event.type === "run.started") {
const requestId = state?.pendingRequestId ?? null;
db.update(telemetryThreads)
.set({ activeRequestId: requestId, pendingRequestId: null })
.where(eq(telemetryThreads.threadId, threadId))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid counting retained-turn revival as a new turn

When reconcileDaemonReportedThreads revives an errored thread because the daemon still reports its existing turn as active, this unconditional run.started handling emits another turn_started and replaces the active request with the usually empty pending request. The same host turn can consequently be counted once as failed and again as a new unavailable-origin turn when it completes; distinguish reconciliation/revival starts from actual dispatch starts.

Useful? React with 👍 / 👎.

Comment on lines +247 to +249
.where(isNull(threads.parentThreadId))
.get()?.count ?? 0;
return rootThreads <= 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not infer install history from the current root count

On upgrade, an established installation with exactly one root thread—regardless of how many turns it has already completed—passes this check and labels its next outcome first_turn: true. Deleted or consolidated thread histories can produce the same false positive, corrupting first-turn conversion metrics; this needs a historical marker rather than the current number of root rows.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T19:21:12.055864Z a96641c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@brsbl
brsbl removed this pull request from stack #5440 October 14, 2026 03:16
@brsbl
brsbl force-pushed the bb/core-capability-use-main-thr_a4mhd93zji branch 4 times, most recently from 2ea2674 to 46c5a16 Compare October 21, 2026 06:59
@github-actions github-actions Bot closed this Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This is an automated message. We have closed this pull request because it has been open for more than two weeks.

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