Skip to content

feat(btw): own detached work execution and lifecycle - #137

Merged
BegoniaHe merged 3 commits into
masterfrom
split/btw-work-runtime
Sep 10, 2026
Merged

BegoniaHe merged 3 commits into
masterfrom
split/btw-work-runtime

Conversation

@YUZHEthefool

@YUZHEthefool YUZHEthefool commented Sep 10, 2026

Copy link
Copy Markdown
Member

Summary

Extract work execution and per-origin task state over the existing Agent executor. Track pending/running/terminal outcomes, propagate cancellation, retain terminal records, and store generic failure text.

Related issue

Related: #125
Parent: #122
Design: #28

Stack

  • Base: split/btw-entry. Depends on PR #136.
  • Follow-up PRs: #138.

Behavior

Own detached work under the existing runtime lifecycle. Acknowledge a task, track pending/running/terminal states, and execute through the established Agent executor with bounded concurrency. Keep conversation available while work runs.

Non-goals

Persistent jobs, restart recovery, cross-device scheduling, and an automatic retry/rollback platform are separate work.

Implementation notes

Base branch: split/btw-entry. Depends on PR #136. This PR shows only this feature's changes relative to that dependency. The original prototype at 33ee103a62937db3e930c89ba47a648b75cc7772 is provenance; integration follows current master's owners and authorization contracts. The parent issue records review/integration order.

No new HTTP contract or dependency changes. Feature settings and behavior are documented in both languages.

Validation

89 focused work/entry/config tests passed initially. After integrating the metadata repair from B1, 17 work and metadata tests passed; converted enablement, concurrency and retention controls remain visible. Six damaged Chinese labels/hints were then restored; metadata tests and scoped Prettier passed, and all related Chinese strings were checked for encoding damage.

Python checks used the existing Python 3.14.1 environment with python -m pytest and task-local --basetemp directories. Local Node was 24.11.1; CI must validate the pinned toolchain. Relevant scoped formatting and Markdown checks were run. The root tracker records the final combined validation. No live model evaluation is implied by deterministic tests or documentation checks.

Compatibility and risk

Depends on B1. This slice provides the work runtime; B4 attaches scheduler delivery and shutdown ownership, and B2 provides the command. max_concurrent bounds active execution, not the waiting backlog.

Checklist

  • A corresponding development Issue exists and this PR contains one feature or experiment.
  • Tests and bilingual documentation accompany the change, or missing experimental implementation is explicitly described.
  • Existing authorization, current APIs/configuration, Python 3.14+, and integrated documentation constraints are retained.
  • No dependencies, credentials, generated site output, or fork publication claims are introduced.
  • A human maintainer review and separate AI-assisted review have approved merging.

Repository references: AGENTS.md, GOVERNANCE.md, AI_POLICY.md, and the feat PR template.

Agent note

Codex prepared this PR at the user's request to split the original #28 implementation into reviewable features, with only classifier experiments marked as drafts. AI assisted extraction, current-path adaptation, tests, and English descriptions. The validation above was performed locally; remaining limitations are stated explicitly. This note is not a maintainer approval. No PR has been merged.

@BegoniaHe BegoniaHe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI-assisted review completed against the stacked base split/btw-entry. Focused tests passed, but the blocking error-redaction issue below must be fixed before this slice is ready.

WorkSessionStatus.FAILED,
error="Work task failed.",
)
raise

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Redact detached executor failures before they reach task logging

This re-raises the original executor exception from the detached task. create_tracked_task then logs that exception with exc_info=exc, so provider/tool exception messages can place URLs, tokens, credentials, or sensitive configuration into logs even though the session stores "Work task failed.". That violates the repository error-redaction invariant. Please terminate the detached failure path with a sanitized/log-safe exception (or consume and log it through safe_error / redact_sensitive_text) while preserving cancellation propagation, and add a log-capture regression test proving a sentinel secret from the executor is absent from emitted logs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed in e2f20cc. Detached execution now consumes non-cancellation failures after logging them through safe_error, so the task registry cannot emit the raw traceback. The added regression test verifies an api_key sentinel is absent from captured logs while the session remains generically failed and finalization still runs.

Base automatically changed from split/btw-entry to master September 10, 2026 18:59
Reuse the existing Agent executor with bounded execution concurrency,
terminal retention, cancellation propagation and generic failure state.

Related: #125
AI-Generated: true
Generated-At: 2026-09-10T15:34:43Z
Restore the six work enablement, concurrency, and retention translations
from their runtime metadata descriptions and hints.

AI-Generated: true
Generated-At: 2026-09-10T16:37:36Z
@BegoniaHe
BegoniaHe force-pushed the split/btw-work-runtime branch from 0b17c33 to 0851fb1 Compare September 10, 2026 18:59
Prevent raw executor exceptions from reaching tracked-task logging and cover the redaction boundary.

AI-Generated: true
Generated-At: 2026-09-10T19:02:24Z
@BegoniaHe
BegoniaHe force-pushed the split/btw-work-runtime branch from 5f7b20c to e2f20cc Compare September 10, 2026 19:02
await asyncio.wait_for(executor.started.wait(), timeout=1)
task.cancel()
with pytest.raises(asyncio.CancelledError):
await task
@BegoniaHe
BegoniaHe merged commit 037994e into master Sep 10, 2026
6 of 26 checks passed
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.

feat(btw): own detached work execution and lifecycle

3 participants