Skip to content

feat(codemode): sleep primitive + std async helpers (mapLimit, retry, withTimeout) (design #800, phase 2) #803

Closed

Description

@dezren39

Sub-issue of #800 (design: Code Mode's missing standard library). Implements phase 2 of that design; depends on phase 1's libraries mechanism (sibling sub-issue of #800).

Scope

  1. sleep host primitive: one new extension in packages/core alongside CodeModeWeb (packages/core/src/codemode/web.ts is the pattern: host function, AbortSignal.timeout-style capping). Its global is not exposed under its own name — the std library wraps it as std.sleep(ms). A single sleep is capped at the execution's remaining wall-clock budget. Per the extension contract (packages/codemode/src/extension.ts) it is not a tool call and does not consume maxToolCalls; the execution timeout still bounds total wall time.
  2. Async helpers in the std library (program-side, on phase 1's mechanism):
    • std.sleep(ms) — as above.
    • std.mapLimit(items, limit, fn) — bounded concurrency, results in input order; on first rejection no new items start and the promise rejects with that error.
    • std.retry(fn, { attempts, delayMs, backoff, shouldRetry }) — retries rejections only, delays via std.sleep, deterministic by default (no jitter unless requested).
    • std.withTimeout(promiseOrFn, ms) — rejects with a timeout error after ms. It does not cancel the underlying work (an admitted tool call may still complete host-side); this is stated in the instructions listing (§3).
  3. Instructions: the std listing in packages/core/src/codemode/instructions.ts gains the async members, including the withTimeout non-cancellation warning in plain words.
  4. interpreter-support.md checklist entries updated for the async surface.

Acceptance criteria

  • Tests (in the interpreter, via packages/codemode / core tests): mapLimit never exceeds the limit, preserves order, and starts no new items after a rejection; retry succeeds after transient rejections and stops after attempts, with delays routed through the sleep primitive (no wall-clock-flaky assertions); withTimeout rejects a slow promise at the deadline while the underlying tool call's completion is still recorded.
  • A single std.sleep longer than the remaining execution budget does not extend the execution past its timeout.
  • Tool calls made inside helpers count toward maxToolCalls and appear in toolCalls exactly as direct calls do.
  • Instructions render the async members with the non-cancellation warning.
  • bun run check from the repo root passes, or pre-existing failures on the base branch are named in the closing note. Tests run from package directories per repo AGENTS.md.

Design: #800 (full text in the keep-the-four-repos-healthy goal workspace, files/designs/opencode-codemode-stdlib.md, §§2–3).

Activity

  1. added
    kind/featureNew feature or capability request
    priority/normalOrdinary priority (the default)
    app/corePackage: core (pkgs/ or apps/ in this repo)
    effort/mMedium: expected under 1 day of work
    on Oct 29, 2026
  2. developing-today commented on Oct 29, 2026

    @developing-today
  3. dezren39 commented on Oct 29, 2026

    @dezren39
    Author

    🤖 Agent note · filed

  4. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedAn agent holds this item via the queue (claimed task)
    status/parkedDeliberately paused with a recorded resume condition
    and removed on Oct 29, 2026
  5. dezren39 commented on Oct 29, 2026

    @dezren39
    Author

    Parked by queue worker (lane B): phase 2 cannot start until phase 1 lands.

    Verified fresh this shift: #802 is still OPEN and its libraries mechanism is not on main — task 2963's triage (2026-10-29T02:14Z) confirmed the gap at origin/main and enqueued the #802 implementation as task 2982. The #803 packet explicitly directs the worker to park/block on this dependency if #802 is not yet merged.

    Task 2964 is parked for 2h with a resume brief: resume only after #802 closes / task 2982 completes, then implement the capped sleep host extension in packages/core (pattern: packages/core/src/codemode/web.ts, capped at the execution's remaining budget, not exposed as its own global) plus std.sleep / std.mapLimit / std.retry / std.withTimeout on the #802 libraries mechanism, with the instructions std listing (including the withTimeout non-cancellation warning) and interpreter-support.md updates.

  6. dezren39 commented on Oct 29, 2026

    @dezren39
    Author

    Dependency revalidated by queue worker (lane B), task 2964: #802 (phase 1, libraries mechanism) is still OPEN and its implementation PR #812 is OPEN/unmerged (checked 2026-10-29T04:49Z), so the mechanism this phase-2 work builds on is not on main yet. Per the packet, task 2964 is re-parked 2h. Resume once #802 closes / PR #812 merges.

  7. 8 remaining items

  8. added
    status/parkedDeliberately paused with a recorded resume condition
    queue/claimedA queue worker has claimed the task for this item
    and removed
    queue/claimedA queue worker has claimed the task for this item
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Oct 29, 2026
  9. dezren39 commented on Oct 29, 2026

    @dezren39
    Author

    agent-note:v1
    state: picked-up
    task: 2964 (repo-health-opencode-pilot)
    pr: #872
    note: Resumed from park (CI pending). Fresh check: typecheck + affected packages pass; basic unit linux failed only on unrelated config-plugin reload test, windows on pair/managed-service timeouts (codemode suite 1416 pass in both logs). One undispositioned Codex P2 found: withTimeout deadline >30s is shortened by the 30s sleep cap. Fixing that in the PR before any merge decision; not merging past it.

  10. dezren39 commented on Oct 29, 2026

    @dezren39
    Author

    🤖 Agent note · done — merged via PR #872

  11. removed
    queue/claimedA queue worker has claimed the task for this item
    work/assignedAn agent holds this item via the queue (claimed task)
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/corePackage: core (pkgs/ or apps/ in this repo)effort/mMedium: expected under 1 day of workkind/featureNew feature or capability requestpriority/normalOrdinary priority (the default)source/design-architectFiled by the repo design architect jobstatus:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions