chenhg5/cc-connect · error

send permission request: %w

Error message

send permission request: %w

What it means

Relay wraps json.Encoder failures when writing the BridgeRequest (token + hook input) to the bridge TCP connection: 'send permission request: %w'. Since the connection was just established, this usually means the connection broke between dial and write — most often the bridge closed it (e.g. token rejected) or a network/socket error occurred.

Source

Thrown at agent/antigravityhook/protocol.go:58

	}
	if len(input) > maxHookInput {
		return fmt.Errorf("hook input exceeds %d bytes", maxHookInput)
	}
	if !json.Valid(input) {
		return fmt.Errorf("hook input is not valid JSON")
	}

	conn, err := net.DialTimeout("tcp", address, bridgeDialTimeout)
	if err != nil {
		return fmt.Errorf("connect permission bridge: %w", err)
	}
	defer func() { _ = conn.Close() }()
	// The listener is started before agy runs this hook, so dial failures should
	// fail closed quickly. After connect, wait much longer for a human response.
	_ = conn.SetDeadline(time.Now().Add(bridgeResponseTimeout))

	if err := json.NewEncoder(conn).Encode(BridgeRequest{Token: token, HookInput: input}); err != nil {
		return fmt.Errorf("send permission request: %w", err)
	}

	var response BridgeResponse
	if err := json.NewDecoder(io.LimitReader(conn, 64<<10)).Decode(&response); err != nil {
		return fmt.Errorf("read permission response: %w", err)
	}
	switch response.Decision {
	case "allow", "deny":
	default:
		return fmt.Errorf("invalid permission decision %q", response.Decision)
	}

	if err := json.NewEncoder(out).Encode(response); err != nil {
		return fmt.Errorf("write hook response: %w", err)
	}
	return nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check cc-connect logs for why the bridge closed the connection (likely token mismatch)
  2. Confirm CC_CONNECT_AGY_PERMISSION_TOKEN matches the token the session generated
  3. Inspect the wrapped %w error (e.g. 'broken pipe' vs 'connection reset') to pick the cause
  4. Ensure the session isn't being stopped concurrently with the permission request
  5. Retry the permission-triggering action once the bridge is confirmed healthy
Defensive patterns

Strategy: retry

Validate before calling

// verify token before invoking
if tok != expectedSessionToken { log.Fatal("CC_CONNECT_AGY_PERMISSION_TOKEN mismatch") }

Try / catch

if err := Relay(...); err != nil && strings.HasPrefix(err.Error(), "send permission request:") {
    log.Printf("bridge dropped connection (token or teardown?): %v", err)
    // fail closed = deny
}

Prevention

When it happens

Trigger: json.NewEncoder(conn).Encode returns err — connection reset by peer, bridge listener closed the socket after a failed token check, deadline exceeded, or fd error mid-write.

Common situations: Mismatched/expired CC_CONNECT_AGY_PERMISSION_TOKEN causing the bridge to drop the connection; bridge goroutine crashed while the hook was connecting; race with session teardown.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/e6ec4424d4a6b5dc. Report an issue: GitHub.