Skip to content

fix(agent): recover or flag pending attachments that fail to reach the cloud agent#3039

Merged
fercgomes merged 2 commits into
mainfrom
posthog-code/fix-cloud-pasted-attachment-fallback
Jul 2, 2026
Merged

fix(agent): recover or flag pending attachments that fail to reach the cloud agent#3039
fercgomes merged 2 commits into
mainfrom
posthog-code/fix-cloud-pasted-attachment-fallback

Conversation

@fercgomes

@fercgomes fercgomes commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes GROW-99

Pasting a prompt into PostHog Code auto-converts it to a pasted-text.txt attachment. On cloud tasks the file is uploaded as a run artifact and the sandbox agent reads it from .posthog/attachments/…. Intermittently the agent instead received the bare task description Attached files: pasted-text.txt as plain text — no file, no inline content — and replied that it "can't find the file… no text was included inline", unable to do the task. (The task title also stayed Untitled.)

Root cause

In agent-server.ts → sendInitialTaskMessage, when getPendingUserPrompt() returns null (no pending message and no resolvable artifacts) it falls back to task.description. For a pasted-text-only task that description is just the Attached files: … summary, so the agent is handed a prompt naming a file it was never given. The artifact fails to resolve when the run's artifacts manifest doesn't yet contain the just-uploaded pending_user_artifact_ids — most likely a transient manifest lag at run start.

Fix

Hardened getPendingUserPrompt:

  1. Best-effort recovery — refetch the run manifest once when a declared attachment isn't listed yet, so a transient lag doesn't drop the attachment (the pasted text then reaches the agent).
  2. Safe degraded prompt — if an attachment still can't be hydrated, append an explicit "the attachment didn't come through, ask the user to paste it directly or re-send" notice instead of the misleading bare description. Skill bundles (installed silently) are excluded from the count.
  3. Adds a warn("Pending user attachments could not be loaded", …) log with resolved/expected counts, so a consistent failure (artifact genuinely missing server-side) is obvious in run logs.

The misleading task.description fallback in sendInitialTaskMessage is now bypassed for this case, and the resume paths benefit too since they share getPendingUserPrompt.

Tests

New AgentServer pending user attachments suite in agent-server.test.ts:

  • missing attachment (refetch also empty) → explicit notice appended, not null
  • refetch recovers the artifact → resource_link block, no notice
  • no pending artifacts → null, and no refetch

Typecheck and Biome are clean.

The file's existing HTTP-mode tests run a git commit in createTestRepo, which is blocked in the signed-commits sandbox this was authored in — so I couldn't run them locally. The new tests are deliberately self-contained (no git/HTTP) and pass; CI covers the rest.

Notes

  • This was seen as a one-off, so the change hardens the degraded path and adds recovery rather than chasing a root cause I couldn't confirm. If it reproduces every time, the new warn log points at the artifact genuinely not landing in taskRun.artifacts server-side.
  • The earlier title fix (fix(sessions): name tasks from pasted text-file contents #2850) is unrelated — it only touched name generation, not how the file reaches the agent.

Closes GROW-99

…e cloud agent

Pasted text in a cloud task is uploaded as a run artifact and read by the
sandbox agent from .posthog/attachments. When the run's artifact manifest does
not yet list the just-uploaded pending_user_artifact_ids, getPendingUserPrompt
returned null and sendInitialTaskMessage fell back to task.description — the bare
"Attached files: pasted-text.txt" summary — handing the agent a prompt that names
a file it was never given.

Harden getPendingUserPrompt:
- Refetch the run manifest once when a declared attachment isn't listed yet, so a
  transient lag doesn't drop the attachment.
- If an attachment still can't be hydrated, append an explicit "didn't come
  through, ask the user to re-send" notice instead of the misleading description.
  Skill bundles (installed silently) are excluded from the check.
- Log a warning with resolved/expected counts so a consistent failure is visible.

Closes GROW-99

Generated-By: PostHog Code
Task-Id: 62e30413-5b19-4752-9520-b0e772c462ce
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit e44adde.

@greptile-apps

greptile-apps Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): recover or flag pending atta..." | Re-trigger Greptile

Comment thread packages/agent/src/server/agent-server.ts Outdated
…etch resolve

Review feedback (Greptile): getArtifactsById logs a per-id warning for each
unresolved id, and the new refetch path calls it twice, so a genuinely missing
artifact produced two identical low-level warnings on top of the high-level
summary. Add a warnOnMissing option (default true) and pass false on the
speculative pre-refetch resolve, where a miss is expected and is exactly what
triggers the refetch.

Generated-By: PostHog Code
Task-Id: 62e30413-5b19-4752-9520-b0e772c462ce
@fercgomes fercgomes marked this pull request as ready for review July 1, 2026 21:53
@fercgomes fercgomes requested a review from a team July 1, 2026 21:54
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "fix(agent): avoid duplicate "missing art..." | Re-trigger Greptile

@fercgomes fercgomes merged commit be1a3e8 into main Jul 2, 2026
27 checks passed
@fercgomes fercgomes deleted the posthog-code/fix-cloud-pasted-attachment-fallback branch July 2, 2026 17:05
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.

2 participants