Skip to content

Commit 3cab01e

Browse files
committed
fix: improve progress tracking with non-linear progress calculation
- Add calculate_nonlinear_progress() utility function using exponential decay curve - Replace linear time-based progress with non-linear progress in VeCPCRBuilder and VeAgentkitRuntimeRunner - Increase VeCPCRBuilder max wait time from 600s to 900s (10 to 15 minutes) - Set expected_time to 30s to control progress curve speed (faster initial progress) - Cap progress at 95% before task completion to avoid premature 100% display (cherry picked from commit 8142443a29f354f9c5aff957e7c1adda93aae4b7)
1 parent d081d8f commit 3cab01e

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

agentkit/toolkit/builders/ve_pipeline.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from agentkit.toolkit.models import BuildResult, ImageInfo
2727
from agentkit.toolkit.reporter import Reporter
2828
from agentkit.toolkit.errors import ErrorCode
29-
from agentkit.utils.misc import generate_random_id
29+
from agentkit.utils.misc import generate_random_id, calculate_nonlinear_progress
3030
from agentkit.toolkit.volcengine.services import CRServiceConfig
3131
from .base import Builder
3232

@@ -1056,8 +1056,9 @@ def download_and_show_logs(run_id: str):
10561056
self.reporter.info("Waiting for build completion...")
10571057

10581058
# Wait for build completion using reporter's long task interface
1059-
max_wait_time = 600 # 10 minutes
1059+
max_wait_time = 900 # 15 minutes
10601060
check_interval = 3 # Check every 3 seconds
1061+
expected_time = 30 # Controls progress curve speed (smaller = faster initial progress)
10611062
import time
10621063
start_time = time.time()
10631064

@@ -1098,8 +1099,7 @@ def download_and_show_logs(run_id: str):
10981099
download_and_show_logs(run_id)
10991100
raise Exception(error_msg)
11001101

1101-
# Update progress (time-based)
1102-
task.update(completed=min(elapsed_time, max_wait_time))
1102+
task.update(completed=calculate_nonlinear_progress(elapsed_time, max_wait_time, expected_time))
11031103
time.sleep(check_interval)
11041104
else:
11051105
# Unknown status
@@ -1111,8 +1111,7 @@ def download_and_show_logs(run_id: str):
11111111
download_and_show_logs(run_id)
11121112
raise Exception(error_msg)
11131113

1114-
# Update progress
1115-
task.update(completed=min(elapsed_time, max_wait_time))
1114+
task.update(completed=calculate_nonlinear_progress(elapsed_time, max_wait_time, expected_time))
11161115
time.sleep(check_interval)
11171116

11181117
except Exception:

agentkit/toolkit/config/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ def merge_runtime_envs(common_config: Any, strategy_config: Dict[str, Any]) -> D
4949
if isinstance(strategy_level_envs, dict):
5050
merged_envs.update(strategy_level_envs)
5151

52-
return merged_envs
52+
return merged_envs

agentkit/toolkit/resources/templates/golang/Dockerfile.j2

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Build stage - 支持自定义构建镜像
1+
# Build stage - Support custom image
22
{% if base_image_builder %}
33
FROM {{ base_image_builder }} AS builder
44
{% else %}
@@ -25,7 +25,6 @@ ENV GO_VERSION=1.24 \
2525
# download modules if go.mod present
2626
RUN if [ -f go.mod ]; then go mod download; fi
2727

28-
# 执行自定义构建脚本(如需安装编译依赖、证书等)
2928
{% if build_script %}
3029
RUN chmod +x {{ build_script }} && /bin/sh {{ build_script }}
3130
{% endif %}
@@ -40,7 +39,7 @@ RUN mkdir -p ${BUILD_OUTPUT_DIR} && /bin/sh {{ entry_relative_path }}
4039
RUN mkdir -p ${BUILD_OUTPUT_DIR} && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ${BUILD_OUTPUT_DIR}/${BUILD_BINARY_NAME} {{ entry_relative_path }}
4140
{% endif %}
4241

43-
# Runtime stage - 支持自定义运行时镜像
42+
# Runtime stage - Support custom image
4443
{% if base_image_runtime %}
4544
FROM {{ base_image_runtime }}
4645
{% else %}

agentkit/toolkit/resources/templates/python/Dockerfile.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 支持自定义基础镜像
1+
# Support custom base image
22
{% if base_image %}
33
FROM {{ base_image }}
44
{% else %}
@@ -20,7 +20,6 @@ RUN {% if dependencies_file %}{% if dependencies_install_path %}uv pip install {
2020
{% endif %}{% endif %}
2121
{% endif %}
2222

23-
# 执行自定义构建脚本(如需安装系统依赖、编译C扩展等)
2423
{% if build_script %}
2524
COPY {{ build_script }} /tmp/build_script.sh
2625
RUN chmod +x /tmp/build_script.sh && /tmp/build_script.sh && rm /tmp/build_script.sh

agentkit/toolkit/runners/ve_agentkit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from agentkit.toolkit.models import DeployResult, InvokeResult, StatusResult
2727
from agentkit.toolkit.reporter import Reporter
2828
from agentkit.toolkit.errors import ErrorCode
29-
from agentkit.utils.misc import generate_runtime_name, generate_runtime_role_name, generate_apikey_name, generate_client_token
29+
from agentkit.utils.misc import generate_runtime_name, generate_runtime_role_name, generate_apikey_name, generate_client_token, calculate_nonlinear_progress
3030
from agentkit.sdk.runtime.client import AgentkitRuntimeClient
3131
import agentkit.sdk.runtime.types as runtime_types
3232

@@ -594,6 +594,7 @@ def _wait_for_runtime_status_multiple(
594594
last_status = None
595595
start_time = time.time()
596596
total_time = timeout if timeout else 300 # For progress bar display
597+
expected_time = 30 # Controls progress curve speed (smaller = faster initial progress)
597598
runtime = None # Initialize runtime variable
598599

599600
# Use reporter.long_task() for progress tracking
@@ -625,8 +626,8 @@ def _wait_for_runtime_status_multiple(
625626
task.update(description=f"Runtime status: {runtime.status}")
626627
last_status = runtime.status
627628

628-
# Update progress
629-
task.update(completed=min(elapsed_time, total_time))
629+
# Update progress using non-linear curve
630+
task.update(completed=calculate_nonlinear_progress(elapsed_time, total_time, expected_time))
630631

631632
time.sleep(3)
632633

agentkit/utils/misc.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import math
1516
import string
1617
import random
1718

@@ -67,4 +68,37 @@ def generate_client_token() -> str:
6768
Returns:
6869
16位随机字符串
6970
"""
70-
return generate_random_id(16)
71+
return generate_random_id(16)
72+
73+
74+
def calculate_nonlinear_progress(
75+
elapsed: float,
76+
max_time: float,
77+
expected_time: float = 30.0,
78+
max_ratio: float = 0.95
79+
) -> float:
80+
"""Calculate non-linear progress using exponential decay curve.
81+
82+
This creates a progress bar that advances quickly at first, then slows down
83+
as it approaches completion. Useful for tasks with unpredictable duration.
84+
85+
Formula: progress = max_time * (1 - e^(-elapsed/expected_time))
86+
87+
Example progress at different times (with expected_time=30):
88+
- At 30s: ~63%
89+
- At 60s: ~86%
90+
- At 90s: ~95%
91+
92+
Args:
93+
elapsed: Elapsed time in seconds.
94+
max_time: Maximum time (used as progress bar total).
95+
expected_time: Expected completion time, controls curve speed.
96+
Smaller = faster initial progress.
97+
max_ratio: Maximum progress ratio before task completes (default 0.95).
98+
Prevents reaching 100% until task actually finishes.
99+
100+
Returns:
101+
Progress value between 0 and max_time * max_ratio.
102+
"""
103+
progress = max_time * (1 - math.exp(-elapsed / expected_time))
104+
return min(progress, max_time * max_ratio)

0 commit comments

Comments
 (0)