Skip to content

feat(pic): add options to makeLive - #314

Merged
marc0olo merged 7 commits into
mainfrom
feat/make-live-options
Sep 30, 2026
Merged

marc0olo merged 7 commits into
mainfrom
feat/make-live-options

Conversation

@marc0olo

@marc0olo marc0olo commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #142

makeLive takes an optional options object:

  • artificialDelayMs, the minimum delay between rounds. It was hard-coded to 0. It delays calls that wait for live mode to execute them: calls through the HTTP gateway, and submitted calls polled with ingressStatus. Actors, deferred actors, updateCall and awaitCall execute their rounds themselves, so they aren't delayed. Measured: an update through an agent took ~700 ms with a 300 ms delay, and a polled submitted call took ~1 s with a 1 s delay, but the others took 3–10 ms either way.
  • httpGateway, the same settings as PocketIc.create's httpGateway (IP address, port, domains, HTTPS), for the gateway makeLive starts.

Passing options to an instance that's already live, or httpGateway to one created with its own gateway, throws instead of ignoring them. If the gateway fails to start, e.g. because its port is taken, auto progress is stopped again, so the instance isn't left live without a gateway.

For the reentrancy case in #142, live mode isn't needed: calls submitted with a deferred actor before any is awaited interleave at their awaits. A new examples/reentrancy example shows it (its test for the vulnerable withdrawal relies on #315, since the second withdrawal traps) with a bank canister: a withdrawal that checks the balance before awaiting a transfer and deducts it after pays out twice, the fixed one pays out once, and a regular actor making the calls one after another misses the bug. running-tests.mdx gets short sections on testing interleaved calls (linking the example) and on live mode, and the example lists now mention both Jest and Vitest. The example is built with the Motoko recipe v5.1.0, which compiles through mops build, so it's defined in [canisters] of mops.toml; .gitignore now ignores .mops/ at any depth for its build output. The other examples move to v5 in a follow-up.

The makeLive JSDoc said the instance needs an NNS subnet for fetchRootKey. That's not the case on PocketIC 16 (checked with an agent against an instance without one), so it's removed. The broken code examples of makeLive and stopLive are fixed.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings September 29, 2026 11:00
@marc0olo
marc0olo requested a review from a team as a code owner September 29, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Failed gateway startup leaves auto-progress enabled and the instance in an inconsistent state.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Adds configurable live-mode delays and HTTP gateway settings, plus guidance and tests for interleaved calls.

Changes:

  • Adds MakeLiveOptions and forwards gateway/delay configuration.
  • Tests live-mode configuration and deferred-call interleaving.
  • Updates examples and testing documentation.
File Description
packages/​pic/​tests/​test-canister/​test_canister.did Adds interleaving test methods.
packages/​pic/​tests/​test-canister/​main.mo Implements lost-update test behavior.
packages/​pic/​tests/​test-canister/​declarations/​test_canister.did.js Updates generated JavaScript declarations.
packages/​pic/​tests/​test-canister/​declarations/​test_canister.did.d.ts Updates generated TypeScript declarations.
packages/​pic/​tests/​src/​util.ts Extracts the free-port helper.
packages/​pic/​tests/​src/​live-mode.spec.ts Tests live-mode options and validation.
packages/​pic/​tests/​src/​http-gateway.spec.ts Uses the shared port helper.
packages/​pic/​tests/​src/​create-actor.spec.ts Tests deferred-call interleaving.
packages/​pic/​src/​pocket-ic.ts Extends makeLive and fixes examples.
packages/​pic/​src/​pocket-ic-types.ts Defines public live-mode options.
packages/​pic/​src/​pocket-ic-client.ts Forwards options to server endpoints.
packages/​pic/​src/​pocket-ic-client-types.ts Exports gateway configuration encoding.
docs/​src/​content/​docs/​guides/​running-tests.mdx Documents interleaving and live mode.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/pic/src/pocket-ic.ts Outdated
Comment thread docs/src/content/docs/guides/running-tests.mdx Outdated
Comment thread packages/pic/src/pocket-ic-types.ts Outdated
@marc0olo
marc0olo marked this pull request as draft September 29, 2026 11:29
…to feat/make-live-options

# Conflicts:
#	packages/pic/tests/src/create-actor.spec.ts
@marc0olo
marc0olo changed the base branch from main to fix/deferred-actor-rejection September 29, 2026 12:43
Base automatically changed from fix/deferred-actor-rejection to main September 30, 2026 06:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The new API behavior, rollback path, tests, example, and documentation are consistent and complete.

Review effort: Balanced
Findings: None

Resolved since last review (3)
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

@marc0olo
marc0olo added this pull request to stack #317 September 30, 2026 07:48
@marc0olo
marc0olo marked this pull request as ready for review September 30, 2026 07:55
@marc0olo
marc0olo added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit d877d6a Sep 30, 2026
23 checks passed
@marc0olo
marc0olo deleted the feat/make-live-options branch September 30, 2026 13:21
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.

enable --artificial-delay for PicJs

3 participants