Skip to content
Source
Sign inSign up
pingdotgg/t3code

Stream git hook progress events for stacked git actions #1214

Mergedjuliusmarmingemerged 14 commits intomain fromrefs/pull/1214/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Closes #1194

Summary

  • add end-to-end git action progress reporting for runStackedAction, including action_started, phase transitions, hook lifecycle, hook output, success, and failure events
  • extend git execution layers to support progress callbacks and surface hook start/finish via Git Trace2 during commit execution
  • wire WebSocket handling to generate an actionId and publish gitActionProgress events only to the initiating client
  • update shared contracts/protocol types for git progress events and plumb support through web transport/native API/UI
  • add server, web, and contracts tests covering hook progress ordering, hook failure behavior, and websocket event scoping

Testing

  • apps/server/src/git/Layers/GitManager.test.ts: added tests for ordered commit-hook progress events and action_failed on hook rejection
  • apps/server/src/wsServer.test.ts: added test to verify git action progress is delivered only to the initiating websocket
  • apps/web/src/wsNativeApi.test.ts and apps/web/src/wsTransport.test.ts: added progress-channel handling coverage
  • packages/contracts/src/ws.test.ts: added contract-level ws progress event checks
  • Not run: bun fmt
  • Not run: bun lint
  • Not run: bun typecheck
  • Not run: bun run test

Note

Stream real-time git hook progress events to the initiating WebSocket client during stacked git actions

  • Adds a discriminated union GitActionProgressEvent schema covering action_started, phase_started, hook_started, hook_output, hook_finished, action_finished, and action_failed events, broadcast over a new git.actionProgress WebSocket push channel.
  • Sets up git trace2 monitoring (GitCore.ts) by pointing GIT_TRACE2_EVENT to a temp file, parsing JSON hook lifecycle events, and forwarding them via progress callbacks.
  • runStackedAction in GitManager.ts now accepts a progressReporter and actionId, emitting phase and hook events throughout the action and reporting structured failure on error.
  • Progress events are scoped to the requesting client: wsServer.ts injects a per-socket reporter and wsNativeApi.ts exposes git.onActionProgress for UI subscriptions.
  • The UI (GitActionsControl.tsx) generates a UUID actionId per action, subscribes to progress events, and updates a long-running toast with phase labels, elapsed time, and live hook output.
  • git.runStackedAction requests now set timeoutMs: null to disable client-side timeouts; WsTransport is updated to handle nullable timeouts and reject pending requests on WebSocket close.
Macroscope summarized 035f61d.

Note

Medium Risk Adds a new end-to-end progress event pipeline (Git TRACE2 parsing, websocket push channel, UI toast updates) and changes the git.runStackedAction contract to require actionId, which can break existing clients and is moderately complex to get correct under concurrency/timeouts.

Overview Adds end-to-end progress reporting for git.runStackedAction, emitting structured lifecycle events (action_started, phase transitions, hook start/finish, hook output, success/failure) correlated via a client-provided actionId.

On the server, GitCore now supports per-line stdout/stderr callbacks and uses Git TRACE2 event logs to detect commit hook execution; GitManager wires these into a progressReporter, applies a longer commit timeout, and publishes git.actionProgress pushes only to the initiating websocket connection.

On the client, the contracts/websocket protocol gain the git.actionProgress channel and actionId requirement; the web transport supports disabling request timeouts (used for runStackedAction) and rejects in-flight requests on socket close, while GitActionsControl subscribes to progress pushes to drive a live “running…” toast with hook/output updates. Tests were added/updated across server, web, and contracts to cover event ordering, hook failures, correlation, and delivery scoping.

Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 035f61d153c303791eb8764f3de83039ab932273. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: e3c94be5-e7f5-4161-b06e-6a2798074a25

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/show-git-hook-progress`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low

      https://github.com/pingdotgg/t3code/blob/e84f5dc2c2714e37650deadcb43929dd959a212d/apps/web/src/wsTransport.ts#L191

      When the WebSocket closes, pending requests are rejected and removed from this.pending, but this.outboundQueue is not cleared. On reconnect, flushQueue() sends queued messages with id values that no longer exist in this.pending. The server processes these requests and sends responses, but handleMessage() silently drops them because this.pending.get(message.id) returns undefined. For non-idempotent operations, this causes the caller to believe the request failed while the server actually executed it.

      ✅ Resolved in 367ae470ee46d0332e7e58fb634f8332e9c6dbc8

    4. bugbot run

    5. ✅ Bugbot reviewed your changes and found no new issues!

      Comment @cursor review or bugbot run to trigger another review on this PR

    6. Cursor Bugbot has reviewed your changes and found 2 potential issues.

      Autofix Details

      Bugbot Autofix prepared fixes for both issues found in the latest run.

      • ✅ Fixed: Trace2 watcher path comparison may silently skip events
        • The watcher now compares event.path against the basename of the trace file path (via path.basename()) in addition to the full path, so basename-only paths from fs.watch correctly trigger readTraceDelta.
      • ✅ Fixed: Concurrent flush and watcher may race on shared state
        • Wrapped readTraceDelta with a Semaphore(1) mutex so the watcher fiber and flush call cannot concurrently access the shared processedChars and lineBuffer state.

      Create PR

      Or push these changes by commenting:

      @cursor push e1599eebd9
      Preview (pingdotgg/t3code@e1599eebd9)
      diff --git a/apps/server/src/git/Layers/GitCore.ts b/apps/server/src/git/Layers/GitCore.ts
      --- a/apps/server/src/git/Layers/GitCore.ts
      +++ b/apps/server/src/git/Layers/GitCore.ts
      @@ -12,6 +12,7 @@
         Result,
         Schema,
         Scope,
      +  Semaphore,
         Stream,
       } from "effect";
       import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
      @@ -361,30 +362,36 @@
             }
           });
       
      -  const readTraceDelta = fs.readFileString(traceFilePath).pipe(
      -    Effect.catch(() => Effect.succeed("")),
      -    Effect.flatMap((delta) =>
      -      Effect.gen(function* () {
      -        if (delta.length <= processedChars) {
      -          return;
      -        }
      -        const appended = delta.slice(processedChars);
      -        processedChars = delta.length;
      -        lineBuffer += appended;
      -        let newlineIndex = lineBuffer.indexOf("\n");
      -        while (newlineIndex >= 0) {
      -          const line = lineBuffer.slice(0, newlineIndex);
      -          lineBuffer = lineBuffer.slice(newlineIndex + 1);
      -          yield* handleTraceLine(line);
      -          newlineIndex = lineBuffer.indexOf("\n");
      -        }
      -      }),
      +  const deltaMutex = Semaphore.makeUnsafe(1);
      +  const readTraceDelta = deltaMutex.withPermit(
      +    fs.readFileString(traceFilePath).pipe(
      +      Effect.catch(() => Effect.succeed("")),
      +      Effect.flatMap((delta) =>
      +        Effect.gen(function* () {
      +          if (delta.length <= processedChars) {
      +            return;
      +          }
      +          const appended = delta.slice(processedChars);
      +          processedChars = delta.length;
      +          lineBuffer += appended;
      +          let newlineIndex = lineBuffer.indexOf("\n");
      +          while (newlineIndex >= 0) {
      +            const line = lineBuffer.slice(0, newlineIndex);
      +            lineBuffer = lineBuffer.slice(newlineIndex + 1);
      +            yield* handleTraceLine(line);
      +            newlineIndex = lineBuffer.indexOf("\n");
      +          }
      +        }),
      +      ),
           ),
         );
      +  const traceFileName = path.basename(traceFilePath);
         const watchTraceFile = Stream.runForEach(fs.watch(traceFilePath), (event) => {
           const eventPath = event.path;
           const isTargetTraceEvent =
      -      eventPath === traceFilePath || path.resolve(eventPath) === traceFilePath;
      +      eventPath === traceFilePath ||
      +      eventPath === traceFileName ||
      +      path.basename(eventPath) === traceFileName;
           if (!isTargetTraceEvent) return Effect.void;
           return readTraceDelta;
         }).pipe(Effect.ignoreCause({ log: true }));
    7. @cursor push e1599eebd9

    8. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/367ae470ee46d0332e7e58fb634f8332e9c6dbc8/apps/web/src/wsTransport.ts#L191

      When a reconnect succeeds before the stale WebSocket's close event fires, the stale socket's close handler clears outboundQueue and rejects all pending requests even though they belong to the new active connection. The this.ws === ws check at line 192 only guards this.ws = null, not the cleanup logic below it. Consider moving the queue and pending cleanup inside the this.ws === ws check so it only runs for the currently-active socket.

      ✅ Resolved in 7741845f5df4eb15424e3c95a3cb9909a71d8a20

    9. juliusmarminge merged this384f350

    10. juliusmarminge closed this

    11. Cursor Bugbot has reviewed your changes and found 1 potential issue.

      Fix All in Cursor Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
      @@ -259,0 +381,21 @@
      381+ }
      382+
      383+ const appended = contents.slice(processedChars);
      384+ const combined = remainder + appended;
      385+ const lines = combined.split("\n");
      386+ const nextRemainder = lines.pop() ?? "";
      387+
      388+ return [
      389+ lines.map((line) => line.replace(/\r$/, "")),
      390+ {
      391+ processedChars: contents.length,
      392+ remainder: nextRemainder,
      393+ },
      394+ ];
      395+ }).pipe(
      396+ Effect.flatMap((lines) => Effect.forEach(lines, handleTraceLine, { discard: true })),
      397+ ),
      398+ ),
      399+ ),
      400+ Effect.ignore({ log: true }),
      401+ ),

      Trace file fully re-read on every watch event

      Low Severity

      readTraceDelta calls fs.readFileString(traceFilePath) on every file-system watch event, re-reading the entire file from the start, then slicing from processedChars. As the trace file grows during a long-running commit with multiple hooks, the cumulative bytes read grows quadratically in the file size. Using a byte-offset–based read (or keeping a file handle open for incremental reads) would avoid re-reading already-processed content.

      Fix in Cursor Fix in Web

Sign in to join this conversation.