Skip to content

fix(provider): port upstream git and session management fixes#61

Merged
tyulyukov merged 17 commits into
mainfrom
marcode/port-upstream-provider-git-fixes
Apr 22, 2026
Merged

fix(provider): port upstream git and session management fixes#61
tyulyukov merged 17 commits into
mainfrom
marcode/port-upstream-provider-git-fixes

Conversation

@tyulyukov
Copy link
Copy Markdown
Owner

Summary

  • Simplifies git status refresh caching to coalesce by remote instead of specific refspecs, reducing redundant fetches across sibling worktrees
  • Adds token usage clamping to Claude adapter to prevent oversized total token counts from exceeding the reported context window
  • Extends repository identity negative cache TTL from 10s to 1 minute to reduce repeated git operations on repos without remotes
  • Fixes session restart/rebind logic to preserve active sessions when restart fails before rebind
  • Adds turn-diff-completed fallback for turn-end notifications when session state lags event derivation
  • Extracts worktree branch utility functions (isTemporaryWorktreeBranch, WORKTREE_BRANCH_PREFIX) to @marcode/shared/git for cross-module use
  • Updates test fixtures to use consistent marcode/ prefix in resolveLiveThreadBranchUpdate
  • Properly handles stale projected session state by starting fresh sessions when session status is ready but no active turn exists

Testing

  • All MarCode regression feature guards pass (turn notifications, session state handling verified)
  • New tests added for Claude token usage clamping with oversized totals and post-progress-snapshot scenarios
  • Session restart failure scenarios covered to ensure active session preservation and no premature stopSession calls
  • Git status refresh coalescing validated across sibling worktrees with different upstream branches
  • Model switching behavior verified when in-session switching is unsupported
  • bun run test passes in all packages
  • bun fmt, bun lint, bun typecheck all pass

juliusmarminge and others added 17 commits April 22, 2026 23:29
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: Heinz Gericke <115458264+heinzgericke@users.noreply.github.com>
)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Julius Marminge <julius0216@outlook.com>
…compacting field

- Cast task_progress / task_notification message.usage at the normalizeClaudeTokenUsage call sites. Upstream pingdotgg#1943 tightened the parameter to NonNullableUsage | undefined on SDK 0.2.77 where task_*.usage was loosely typed; SDK 0.2.111 strictly types it as { total_tokens, tool_uses, duration_ms }. Runtime logic already guards each field with typeof checks, so the cast is safe.
- Add compacting: false to ProviderCommandReactor.test.ts session fixture. MarCode's OrchestrationSession requires compacting, but the upstream pingdotgg#1938 test block doesn't set it.
The upstream pingdotgg#1995 test used the t3code/ temporary worktree prefix; MarCode's isTemporaryWorktreeBranch only recognizes marcode/, so the test would fail on our prefix without this adjustment.
…derivation

Approval / user-input notifications worked, but the turn-end branch of
deriveTurnNotificationTriggers was gated on a single brittle check
(thread.session?.orchestrationStatus !== "running"), which silently drops
the trigger whenever the stored session has already moved off of "running"
by the time the completion event is derived. Two real-world scenarios hit
this:

- Replay / reconnect: a single batch carries both the turn.started
  (running) and turn.completed (ready) events. getThread reflects the
  pre-batch state (often "stopped" or "ready"), so the completion
  notification is dropped.
- Out-of-band session writes: snapshot syncs or other paths that land a
  fresh session ahead of the derivation can race the notification check.

Widen the "was running" signal to also accept an in-batch transition to
"running", a tracked activeTurnId, or a latestTurn still marked "running".
The original orchestrationStatus check is preserved as the primary path.

Tests cover all three additional cases plus a negative regression for
threads that never ran.
The prior widened session-set check still missed turn-end notifications in
practice. The session-set signal is apparently unreliable in the user's
environment — possibly lost to subscription races, snapshot overwrites, or
missed batches.

Add thread.turn-diff-completed as a fallback completion signal. This event
is dispatched by CheckpointReactor strictly in response to an actual
turn.completed runtime event, so its presence is a strong guarantee that a
turn ended. It is already in the thread-detail subscription stream and
flows through the same applyRecoveredEventBatch path.

Deduplication: a completion fired via the primary session-set path in the
same batch marks the thread in completionFiredThreadIds, preventing the
turn-diff-completed branch from firing a second notification for the same
turn. Both paths honor the 5-second user-stop suppression window and the
in-batch userInitiated guard.

Tests cover: fallback firing when session-set is absent, dedup when both
signals arrive together, and suppression respect on the fallback path.

Also renames the in-batch running-transition tracker to make its intent
clearer in the guarded-completion branch.
@tyulyukov tyulyukov merged commit e20a374 into main Apr 22, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants