Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Conversation

@SAKURA-CAT
Copy link
Member

Description

fix settings run id

@SAKURA-CAT SAKURA-CAT requested a review from Copilot June 10, 2025 11:07
@SAKURA-CAT SAKURA-CAT self-assigned this Jun 10, 2025
@SAKURA-CAT SAKURA-CAT added the bug Something isn't working label Jun 10, 2025
@SAKURA-CAT SAKURA-CAT merged commit d9511f6 into main Jun 10, 2025
5 checks passed
@SAKURA-CAT SAKURA-CAT deleted the chore/fix-run-id branch June 10, 2025 11:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes how run_id and run directories are handled by introducing timestamped, unique folder creation with retries, updates tests to cover both save and no-save modes, and bumps the package version.

  • Added loop in SwanLabSharedSettings to generate timestamp-based run_dir and retry on collisions
  • Expanded unit tests in test_settings.py to verify timing behavior and save/no-save branches
  • Updated pyproject.toml version from 0.2.2 to 0.2.3

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
test/unit/core/test_settings.py New tests for timestamp alignment, unique dir creation, and no-save mode
swankit/core/settings.py Implemented timestamped run_dir loop with retry and updated assignment
pyproject.toml Bumped project version from 0.2.2 to 0.2.3

# ----------------------- 检测运行文件夹的创建,确保文件夹在当前进程唯一占有 ----------
run_dir = None
while True:
run_dir is not None and time.sleep(1)
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

Using and for control flow and side-effects here is subtle. Consider replacing this with an explicit if run_dir is not None: time.sleep(1) to improve readability.

Suggested change
run_dir is not None and time.sleep(1)
if run_dir is not None:
time.sleep(1)

Copilot uses AI. Check for mistakes.

# 测试创建文件夹
# 尽量保持代码运行在一秒的开始
time.sleep(1 - (time.time() % 1)) # 确保时间戳在整秒
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

Relying on real time.sleep and datetime.now to align to the start of a second may lead to flaky tests. Consider injecting a deterministic clock or mocking datetime.now for more reliable assertions.

Copilot uses AI. Check for mistakes.
# 测试创建一个存在的文件夹
run_id = "123456"
run_dir = os.path.join(TEMP_DIR, "run-{}-{}".format(datetime.now().strftime("%Y%m%d_%H%M%S"), run_id))
os.mkdir(run_dir)
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

The test creates directories under TEMP_DIR but does not clean them up. This can lead to side-effects across runs—consider using fixtures (e.g., tmp_path) or adding teardown steps to remove created folders.

Copilot uses AI. Check for mistakes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants