Skip to content

fix(agent): poll for pending attachments before the first cloud turn#3409

Closed
posthog[bot] wants to merge 3 commits into
mainfrom
posthog-code/fix-first-turn-pasted-attachment
Closed

fix(agent): poll for pending attachments before the first cloud turn#3409
posthog[bot] wants to merge 3 commits into
mainfrom
posthog-code/fix-first-turn-pasted-attachment

Conversation

@posthog

@posthog posthog Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Problem

When a user pastes a long prompt into a new cloud session, the text is converted into a generated pasted-text.txt attachment. On the first message, the agent can receive only the attachment summary and cannot read the file; the same file is available on a later turn.

Why: the first turn resolves pending attachments from the run artifact manifest, which can briefly lag the upload finalization write. The existing single immediate refetch can still observe the stale manifest, especially for fast-starting sessions.

Changes

  • Poll the run artifact manifest with a short bounded backoff until every requested pending artifact is listed.
  • Preserve the existing explicit missing-attachment notice when the manifest never catches up.

How did you test this?

  • pnpm --dir packages/agent exec vitest run src/server/agent-server.test.ts -t "AgentServer pending user attachments" --reporter=default
  • pnpm --dir packages/agent exec vitest run src/posthog-api.test.ts --reporter=default
  • pnpm --filter @posthog/agent typecheck
  • Biome formatting and git diff --check pass.
  • The full AgentServer HTTP Mode suite cannot run in this environment because its fixture performs an unsigned git commit, which is blocked; those tests are unrelated to this change.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

A pasted-text attachment could be missing on the first message of a new
cloud session and only become readable after a second message.

The first turn resolves pending attachments through the run's artifact
manifest, which can momentarily lag the just-uploaded artifacts. The
previous mitigation refetched the run once, which often still misses them
when propagation takes longer than a single round trip. Poll the manifest
a few times with a short backoff until every requested artifact is listed
before building the initial prompt. Also add a bounded retry to artifact
downloads so an object that isn't readable yet right after upload doesn't
fail the turn.

The second-message path is unaffected: it receives fully resolved artifact
metadata directly and never consults the manifest.

Generated-By: PostHog Code
Task-Id: 76c08662-af28-426f-838b-fc11c313e48b
@trunk-io

trunk-io Bot commented Jul 14, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit eb0df21.

tatoalo added 2 commits July 14, 2026 12:12
Generated-By: PostHog Code
Task-Id: 855ffa3f-1804-44a4-8ec4-63cd2bc8b018
Remove the speculative artifact download retry from the existing fix. The reported first-turn failure follows the stale run manifest path; retrying every download failure would also delay or mask authentication and client errors without addressing the confirmed race.

Generated-By: PostHog Code
Task-Id: 855ffa3f-1804-44a4-8ec4-63cd2bc8b018
@tatoalo

tatoalo commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

superseded by #3425

@tatoalo tatoalo closed this Jul 14, 2026
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