Skip to content

feat: make bridge startup timeout and hang threshold configurable via aft.jsonc#90

Open
herjarsa wants to merge 1 commit into
cortexkit:mainfrom
herjarsa:fix/wsl-bridge-timeout-configurable
Open

feat: make bridge startup timeout and hang threshold configurable via aft.jsonc#90
herjarsa wants to merge 1 commit into
cortexkit:mainfrom
herjarsa:fix/wsl-bridge-timeout-configurable

Conversation

@herjarsa
Copy link
Copy Markdown

@herjarsa herjarsa commented Jun 3, 2026

Problem

WSL/DrvFs environments have slow filesystem startup (95s+ cold start measured with total 2721
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 .
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 17:02 ..
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 .alfonso
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 .bg-shell
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 .cargo
-rw-r--r-- 1 herjarsa 197121 373 Jun 3 16:27 .dockerignore
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 17:02 .git
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 .github
-rw-r--r-- 1 herjarsa 197121 2340 Jun 3 16:27 .gitignore
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 .gsd
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 .opencode
-rw-r--r-- 1 herjarsa 197121 25392 Jun 3 16:27 ARCHITECTURE.md
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 assets
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 benchmarks
-rw-r--r-- 1 herjarsa 197121 1861 Jun 3 16:27 biome.json
-rw-r--r-- 1 herjarsa 197121 87780 Jun 3 16:27 bun.lock
-rw-r--r-- 1 herjarsa 197121 98740 Jun 3 16:27 Cargo.lock
-rw-r--r-- 1 herjarsa 197121 517 Jun 3 16:27 Cargo.toml
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 crates
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 docs
-rw-r--r-- 1 herjarsa 197121 1090 Jun 3 16:27 LICENSE
-rw-r--r-- 1 herjarsa 197121 895 Jun 3 16:27 Makefile
-rw-r--r-- 1 herjarsa 197121 2306 Jun 3 16:27 package.json
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 packages
-rw-r--r-- 1 herjarsa 197121 17668 Jun 3 16:27 README.md
-rw-r--r-- 1 herjarsa 197121 110 Jun 3 16:27 rustfmt.toml
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 scripts
-rw-r--r-- 1 herjarsa 197121 15938 Jun 3 16:27 STRUCTURE.md
drwxr-xr-x 1 herjarsa 197121 0 Jun 3 16:27 tests
-rw-r--r-- 1 herjarsa 197121 386 Jun 3 16:27 tsconfig.base.json
-rw-r--r-- 1 herjarsa 197121 292 Jun 3 16:27 tsconfig.json timing). The AFT bridge binary hits the hardcoded 30s DEFAULT_BRIDGE_TIMEOUT_MS timeout and enters a restart loop:

[aft-plugin] [aft] Bridge started (binary: ~/.cache/opencode/.../aft)
[aft-plugin] [aft] Request timed out after 30000ms — bridge kept warm
... (repeats, bridge never fully initializes)

The hardcoded BRIDGE_HANG_TIMEOUT_THRESHOLD = 2 also causes premature restarts — WSL needs more tolerance.

Solution

Add two new optional fields to aft.jsonc:

  • configure_timeout_ms: bridge startup timeout (default: 30000)
  • hang_timeout_threshold: consecutive timeouts before restart (default: 2)

WSL config example:

{
  "configure_timeout_ms": 120000,
  "hang_timeout_threshold": 10
}

Changes

packages/aft-bridge/src/bridge.ts

  • Add hangTimeoutThreshold?: number to BridgeOptions interface
  • Store instance-level this.hangTimeoutThreshold in BinaryBridge constructor
  • Use this.hangTimeoutThreshold instead of BRIDGE_HANG_TIMEOUT_THRESHOLD constant in keepWarm logic

packages/opencode-plugin/src/config.ts

  • Add configure_timeout_ms and hang_timeout_threshold to AftConfigSchema

packages/opencode-plugin/src/index.ts

  • Pass aftConfig.configure_timeout_ms and aftConfig.hang_timeout_threshold through poolOptions to BridgePool

Backward Compatible

Both fields are optional with safe defaults. Existing aft.jsonc files work unchanged.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Make the bridge startup timeout and hang restart threshold configurable via aft.jsonc to prevent restart loops on slow filesystems (e.g., WSL/DrvFs). Defaults are unchanged, so no config changes are required.

  • New Features
    • Added configure_timeout_ms to control bridge timeout (default: 30000 ms).
    • Added hang_timeout_threshold for consecutive timeouts before restart (default: 2). Values are read from aft.jsonc and passed through the plugin to the bridge.

Written for commit 7a175d1. Summary will update on new commits.

Review in cubic

Greptile Summary

This PR makes the bridge startup timeout and hang-restart threshold configurable via aft.jsonc to address restart loops on slow filesystems like WSL/DrvFs. Both new fields are optional with unchanged defaults, so existing configs continue to work without modification.

  • bridge.ts: Adds hangTimeoutThreshold to BridgeOptions and stores it as an instance field on BinaryBridge, replacing the hardcoded constant in the keep-warm logic.
  • config.ts: Extends AftConfigSchema with configure_timeout_ms and hang_timeout_threshold as optional positive integers.
  • index.ts: Wires the new config fields into poolOptions, though the two assignments are duplicated verbatim (copy-paste artifact on lines 564–567).

Confidence Score: 4/5

Safe to merge — the logic change is correct and backward-compatible; only a duplicate assignment pair needs cleanup.

The bridge.ts and config.ts changes are clean. The only real flaw is a copy-paste duplication in index.ts that repeats both poolOptions assignments verbatim; it has no behavioral effect but is dead code that should be removed before merging.

packages/opencode-plugin/src/index.ts — duplicate assignment pair on lines 564–567.

Important Files Changed

Filename Overview
packages/aft-bridge/src/bridge.ts Adds hangTimeoutThreshold to BridgeOptions and stores it as an instance field in BinaryBridge; the constant BRIDGE_HANG_TIMEOUT_THRESHOLD is replaced by the instance value in keep-warm logic. Clean implementation.
packages/opencode-plugin/src/config.ts Adds configure_timeout_ms and hang_timeout_threshold as optional positive integers to AftConfigSchema. Schema additions are correct and backward-compatible.
packages/opencode-plugin/src/index.ts Passes config values through to poolOptions, but the two assignments are copy-pasted twice (lines 564–567), resulting in redundant dead code.

Sequence Diagram

sequenceDiagram
    participant Config as aft.jsonc
    participant Plugin as opencode-plugin/index.ts
    participant Pool as BridgePool
    participant Bridge as BinaryBridge

    Config->>Plugin: configure_timeout_ms, hang_timeout_threshold
    Plugin->>Pool: poolOptions.timeoutMs, poolOptions.hangTimeoutThreshold
    Pool->>Bridge: new BinaryBridge(options)
    Bridge->>Bridge: "this.timeoutMs = options.timeoutMs ?? DEFAULT_BRIDGE_TIMEOUT_MS"
    Bridge->>Bridge: "this.hangTimeoutThreshold = options.hangTimeoutThreshold ?? BRIDGE_HANG_TIMEOUT_THRESHOLD"

    Note over Bridge: On request timeout
    Bridge->>Bridge: consecutiveTimeouts++
    alt "consecutiveTimeouts < this.hangTimeoutThreshold OR childActiveSinceRequest"
        Bridge->>Bridge: Keep warm (no restart)
    else
        Bridge->>Bridge: Restart bridge
    end
Loading

Reviews (1): Last reviewed commit: "feat: make bridge startup timeout and ha..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/opencode-plugin/src/index.ts">

<violation number="1" location="packages/opencode-plugin/src/index.ts:564">
P2: Duplicate consecutive assignments to poolOptions.timeoutMs and poolOptions.hangTimeoutThreshold</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/opencode-plugin/src/index.ts Outdated
Comment on lines +564 to +567
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Duplicate consecutive assignments to poolOptions.timeoutMs and poolOptions.hangTimeoutThreshold

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/opencode-plugin/src/index.ts, line 564:

<comment>Duplicate consecutive assignments to poolOptions.timeoutMs and poolOptions.hangTimeoutThreshold</comment>

<file context>
@@ -561,6 +561,10 @@ async function initializePluginForDirectory(input: Parameters<Plugin>[0]) {
       );
     },
   };
+  poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
+  poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
+  poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
</file context>
Suggested change
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;

Comment thread packages/opencode-plugin/src/index.ts Outdated
Comment on lines +564 to +567
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The two assignment pairs at lines 564–567 are exact duplicates — timeoutMs and hangTimeoutThreshold are each written twice with the same value. This is a copy-paste artifact; the second pair is dead code and should be removed.

Suggested change
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;
poolOptions.timeoutMs = aftConfig.configure_timeout_ms;
poolOptions.hangTimeoutThreshold = aftConfig.hang_timeout_threshold;

@herjarsa herjarsa force-pushed the fix/wsl-bridge-timeout-configurable branch from e44ef33 to 39fb77c Compare June 3, 2026 15:24
… aft.jsonc

WSL/DrvFs environments have slow filesystem startup (95s+ cold start),
causing the AFT bridge binary to hit the hardcoded 30s timeout and enter
a restart loop. This adds two new optional fields to aft.jsonc:

- configure_timeout_ms: bridge startup timeout (default: 30000)
- hang_timeout_threshold: consecutive timeouts before restart (default: 2)

Both can be raised in WSL environments, e.g.:
  { "configure_timeout_ms": 120000, "hang_timeout_threshold": 10 }

Changes:
- Add hangTimeoutThreshold option to BridgeOptions interface
- Store instance-level hangTimeoutThreshold in BinaryBridge (replaces const)
- Add configure_timeout_ms and hang_timeout_threshold to AftConfigSchema
- Pass config values through poolOptions to BridgePool
@herjarsa herjarsa force-pushed the fix/wsl-bridge-timeout-configurable branch from 39fb77c to 7a175d1 Compare June 3, 2026 15:24
@herjarsa
Copy link
Copy Markdown
Author

herjarsa commented Jun 3, 2026

Fixed the duplicate assignment. @cubic-dev-ai please re-review.

1 similar comment
@herjarsa
Copy link
Copy Markdown
Author

herjarsa commented Jun 3, 2026

Fixed the duplicate assignment. @cubic-dev-ai please re-review.

@cubic-dev-ai
Copy link
Copy Markdown

cubic-dev-ai Bot commented Jun 3, 2026

Fixed the duplicate assignment. @cubic-dev-ai please re-review.

@herjarsa I have started the AI code review. It will take a few minutes to complete.

1 similar comment
@cubic-dev-ai
Copy link
Copy Markdown

cubic-dev-ai Bot commented Jun 3, 2026

Fixed the duplicate assignment. @cubic-dev-ai please re-review.

@herjarsa I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

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.

1 participant