Skip to content

fix(server): keep the native thread when a handoff pointer fits - #5

Draft
jhomra21 wants to merge 6 commits into
mainfrom
fix/handoff-delivery-degrades-instead-of-failing
Draft

jhomra21 wants to merge 6 commits into
mainfrom
fix/handoff-delivery-degrades-instead-of-failing

Conversation

@jhomra21

@jhomra21 jhomra21 commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Problem

T3 reserves part of the context window for later work when it delivers a context handoff. In a long thread, that reserve can be used up while the native thread still has room for the prompt and a short recovery pointer. Delivery then fails. Upstream can now start a fresh native thread instead, but that drops the provider's own context, and it still fails when pending background work prevents the replacement.

Change

For the same native thread only, when the history doesn't fit the reserved budget, deliverContextHandoffs now tries a pointer-only handoff: no history messages, sized against the real remaining window that handoffRemainingWindow measures. Omitted history item IDs go into the delivery metadata, as before. If the pointer doesn't fit either, delivery fails or starts a fresh thread exactly as it does today. Normal history delivery keeps the existing reserve.

Scope and approval

This overlaps open PR pingdotgg#19414, which fixes the triaged pingdotgg#23275 and touches the same files. pingdotgg#19414 defers the whole handoff and sends the prompt unchanged, while this PR sends a pointer that fits the window. Related reports: pingdotgg#22636 (a Factory Droid switch-back blocked by the reserve) and pingdotgg#23142 (byte-based estimates and ACP window fallback, a different cause).

Verification

  • A new case in ContextHandoffBudget.test.ts fails on upstream main b42adff3d7 with expected 'Failure' to equal 'Success' and passes with the fix. The file passes all 17 tests.
  • ProviderTurnStartService.test.ts: 4 tests fail. The same 4 fail on clean upstream on this Windows machine: worktree recovery fails with ENOENT, a recreation-interrupt case returns Success instead of Failure, and two startup-coordination cases fail their assertions.
  • vp env exec --node 26.12.1 -- vp run check:changed: format, lint, knip, GraphQL and typecheck passed. Its only test failures were the 4 above.
  • Not checked: a live provider turn.

Built with Claude Opus 5.5 through Factory Droid in T3 Code. Upstream preparation by GPT-6.1 Terra, orchestrated by Claude Opus 5.5, through Factory Droid in T3 Code.

@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Oct 16, 2026
…w has room

Handoff delivery budgeted against the remaining window minus a reserve of
max(16k, window/4). Once a thread used more than the window minus that reserve,
the budget was 0, and any pending handoff that was not skippable failed the turn
with ContextHandoffBudgetError, even when the window still had room. Failed turns
left their handoffs pending and added more, so every later prompt failed too.

A same-native-thread handoff now falls back to a pointer-only note sized against
the real remaining window, records the dropped history as omitted, and still
throws when even the pointer cannot fit. A missed-run retry note that has no
room is skipped, since the turns stay readable through the thread.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@jhomra21
jhomra21 force-pushed the fix/handoff-delivery-degrades-instead-of-failing branch from 38535e3 to 917dcd1 Compare October 18, 2026 14:47
@github-actions

Copy link
Copy Markdown

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 917dcd1.

This comment will update automatically after the next completed run.

Use the remaining native context window for a compact recovery pointer before replacing a thread whose reserved handoff budget is exhausted.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@github-actions github-actions Bot added size:M and removed size:L labels Oct 30, 2026
@jhomra21
jhomra21 marked this pull request as draft October 30, 2026 02:32
@jhomra21 jhomra21 changed the title fix(server): handoff delivery no longer blocks prompts when the window has room fix(server): keep the native thread when a handoff pointer fits Oct 30, 2026
@jhomra21 jhomra21 changed the title fix(server): keep the native thread when a handoff pointer fits feat(web,mobile): list working Factory Droid subagents in the sidebar Oct 30, 2026
@jhomra21 jhomra21 changed the title feat(web,mobile): list working Factory Droid subagents in the sidebar fix(server): keep the native thread when a handoff pointer fits Oct 30, 2026
jhomra21 and others added 3 commits October 30, 2026 17:56
…d-of-failing

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

This branch has not been deployed

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

Labels

size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant