Skip to content

Fix Windows agent startup on 1.6.x - #4761

Open
noise64 wants to merge 7 commits into
1.6.xfrom
fix-windows-startup-1.6
Open

noise64 wants to merge 7 commits into
1.6.xfrom
fix-windows-startup-1.6

Conversation

@noise64

@noise64 noise64 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor
  • resolves GOL-2217
  • resolves GOL-2220
  • resolves GOL-2222
  • resolves GOL-2221
  • The agent stream sends a close frame and drains within a bounded wait, including after the trigger listener times out or the invocation request fails. Preserve the invocation error after closing its listener. The local-close drain logs the peer's reply code and reason. Expected peer disconnects use INFO.
  • Open sandbox directories through directory capabilities. On Windows, skip unsupported directory flushes and set directory capture times before read-only permissions. Regular files set their capture time through an already-open handle. Sync the CLI checkpoint's parent directory only on Unix.
  • Persist a cached file before setting its read-only attribute. Keep the cache entry locked until protection and sync finish. Attempt removal if either step fails. If removal also fails, return Unavailable with both causes instead of aborting. The loader's cache directory owns the leftover until shutdown cleanup. Keep the existing deletion policy for initialized entries.
  • Keep sandbox creation failures recoverable after host repair, including failures with permanent storage causes. Preserve cleanup-failure reporting. Keep the existing outcome table for permanent errors during seeding and metadata observation, including failures of a pending update. Do not add main's newer update-failure class to the 1.6.x oplog contract.
  • Clear the destination before every restore, including an empty destination. On Windows, validate and enumerate the same opened root. Pin ancestor directories against renames. Delete files and emptied directories by handle without changing attributes shared with outside hard links. Accept only symlink and mount-point reparse tags on opened entries.
  • Windows restore cleanup supports only canonical local drive paths. Reject UNC, mapped network paths and other root forms as permanent failures before enumeration. A failed final-path query preserves the OS error. Filesystems without the required handle-delete operation fail closed; there is no attribute-changing fallback or UNC support.
  • Pin the rustic_core change in golemcloud/rustic_core#7 by revision. It captures Windows read-only modes, sets timestamps through an attribute-only handle, and clears read-only before writing changed contents. Restore saved permissions after contents and timestamps. Leave symlink permissions unchanged and propagate metadata errors. The Windows snapshots were regenerated from the changed mapper. The native fork regression restores A, A again, then writable B into the same destination without clearing or permission resets; its byte, timestamp and permission assertions pass. This does not establish a Golem build with the new pin.
  • Hold built-in compilation requests until the registry has its gRPC port. Flush the queued batch after setting that port. Startup waits for the batch; each request keeps its enqueue timeout. Treat duplicate plugin registration as an expected conflict without a database error log.
  • Keep the pending compilation requests and the ready port in one mutex-protected state. Keep the failed-seed policy in effects.rs; runtime writes still return EffectDecision, while seed failures retain terminal usage-observation errors through classify_startup_error.
  • New coverage includes trigger_stream_timeout_sends_a_close_handshake and the Windows-only an_empty_unsupported_windows_root_fails_restore_permanently. The latter passed on native Windows. It substitutes an unsupported final path on an opened empty directory and checks the permanent run failure before repository loading. This covers Permanent classification with a synthetic final path, not a real-network RestoreRun.
  • Fresh Linux caller checks for this update include the file-loader suite with a_failed_protection_and_cleanup_returns_unavailable_and_keeps_cache_ownership, capture_and_seed_preserve_readonly_nested_contents_and_times, a_run_after_a_clear_that_failed_partway_clears_before_it_loads, and the CLI stream suite with failed_invocation_sends_a_close_handshake.
  • Native Windows MSVC release library checks at this maintenance head passed a_failed_protection_and_cleanup_returns_unavailable_and_keeps_cache_ownership, capture_and_seed_preserve_readonly_nested_contents_and_times and failed_invocation_sends_a_close_handshake with the pinned Rustic revision. Rust/Cargo 1.99.1 and MSVC 14.41.34120 ran non-elevated with Developer Mode off. No source repair or settings change was needed. This is focused source-test coverage, not a repeated release-asset smoke test or qualification of main. See the native commands, logs and binary provenance.
  • Caller coverage includes enqueue_is_best_effort_and_bounds_the_entire_attempt, test_component_stage on SQLite/Postgres/Postgres TLS, the CLI stream tests including peer_initiated_close_is_acknowledged, the destination tests, and a_run_after_a_clear_that_failed_partway_clears_before_it_loads. The portable permissions test, typed disk-full/quota errors, cache lease tests and capture_and_seed_preserve_readonly_nested_contents_and_times also ran locally.
  • Caller coverage for creation recovery includes sandbox_creation_failures_require_host_recovery_and_keep_cleanup_failures and an_unwritable_sandbox_root_retries_creation_after_host_repair. The existing recovery-classification and pending-update permanent-storage tests remain controls. The permission-denial test returns early as root, like existing permission tests.
  • Before this cache rollback, invocation-error and dependency update, native Windows MSVC release executor compilation and the selected non-symlink cleanup, partial-restore, cache-lease, read-only capture/seed and creation-recovery checks passed on n64legion. This includes capture_and_seed_preserve_readonly_nested_contents_and_times and the empty-root RestoreRun regression. Those broader results apply to the earlier maintenance candidate, not this head or main. The focused native checks above do not replace that broader run or repeat the release application smoke test. See the per-test table, build provenance and real-root probe results.
  • A non-elevated probe called the unchanged production clear on empty and populated UNC roots and net use mapped-drive roots. All opened handles resolved to real UNC paths. The clear returned Unsupported with "only local paths are supported on Windows" and left contents, attributes and write times unchanged. A local C: control cleared normally. This verifies network-root rejection, not network-root support or a real-network RestoreRun.
  • On Windows, sandbox_creation_failures_require_host_recovery_and_keep_cleanup_failures covers PermissionDenied, ReadOnlyFilesystem, InvalidData and TimedOut, each with and without cleanup failure. Its additional raw EIO, ESTALE and ENODEV cases are Linux/macOS only. The host-repair regression is cfg(unix). Neither exclusion was compiled on Windows.
  • Developer Mode stayed off, and symlink cleanup was excluded in the later native executor run. Its pass on the previous maintenance candidate, during an approved temporary Developer Mode window, remains historical. The unsupported-reparse-tag case is still untested at runtime. Earlier release server/CLI builds and Rust/TypeScript invocation/restart smoke tests are also historical; the executor run did not rebuild those application binaries or repeat that smoke test. The fork's backup, listing, VFS and rewrite snapshot tests passed after regeneration with snapshot updates disabled. No CI workflows change.

@noise64
noise64 marked this pull request as ready for review December 1, 2026 15:46
@noise64
noise64 requested a review from a team December 1, 2026 15:46
}
}

pub(super) fn walk(into: &Path, hooks: Hooks<'_>) -> std::io::Result<()> {

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.

Could you use try_fold to drive the directory stack here, as the Unix restore walker does, for consistency? The Windows-specific handle and deletion logic can stay as-is. If the explicit loop is measurably faster here, please include the comparison

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ee8228c.

evidence: EffectEvidence,
budget: RetryBudget,
) -> EffectDecision {
) -> Result<EffectDecision, FilesystemStorageError> {

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.

Could we keep decide_write_effect returning EffectDecision for ordinary writes? Right now Err carries an implicit lifecycle rule: each caller has to know it means Invalidate. The point of EffectDecision is that effects.rs decides how a failure affects the generation, and callers apply that decision. Startup needs to know why the generation was invalidated; it shouldn't change who decides to invalidate it.

One way to do that is to handle a failed seed attempt inside effects.rs. That's where both the recovery decision and the original observation error are available. For a terminal observation error, it can use the existing classify_startup_error to invalidate the generation and preserve the cause in the seed failure. seed_with_retry can then act on a seed outcome, such as retry or fail, while namespace, write, and resize callers keep using EffectDecision unchanged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9b690e9.

@kmatasfp

kmatasfp commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

The PR reports that the native Windows invocation and restart smoke tests passed, but the executor test binary didn't compile on Windows. Could you make the five Windows-only restore-cleanup tests runnable and report their results at the PR head? Please include the updated cache lease test in that run too. The smoke tests don't check handle pinning, outside hard-link attributes, or whether a leased cache file stays read-only.

component_id: ComponentId,
component_revision: ComponentRevision,
) {
{

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.

Before this change, port 0 only meant “omit the port.” Now it decides whether we hold or send a compilation request, and setting the port releases the held batch. Could we model those two phases explicitly, e.g. WaitingForPort { pending } and Ready { port }, and have one transition function decide what to hold or send? That keeps the queue and the condition governing it together.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9b690e9.

@kmatasfp

kmatasfp commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

The Windows directory-handle changes make sense to me. Before merge, I'd like to resolve three filesystem behavior issues and verify the affected paths on Windows.

  1. Read-only cache leases. The loader marks the temporary file read-only before persist_noclobber, but the pinned tempfile implementation on Windows clears that attribute before renaming it. This ordering predates the PR, but it means the first lease already receives a file without the promised read-only attribute. Could you make sure the persisted file is read-only before handing out that first lease?
  2. Restore root validation. The PR says an unsupported Windows root ends the restore permanently. clear_if_written checks whether the directory is empty first, so an empty unsupported root skips validation. Could you validate the opened root before that check and cover the empty case through the restore caller? Also, was rejection verified against an actual mapped drive or UNC share? The handle test opens a local directory and supplies a UNC string only as the diagnostic path. It verifies that the handle takes precedence, not what Windows returns for a real network root.
  3. Unknown reparse points. The cleanup check accepts a reparse point whenever is_symlink() is true. On Windows that classification is broader than the set of recognized tags. Could you check the tag on the opened entry so cleanup refuses an unknown tag rather than deleting the entry?
    Capture and seed. Does “set capture times before permissions” refer specifically to directories? That's what the walkthrough says and what the change implements; regular files still set the timestamp through an already-open handle. If the fix is directory-specific, clarifying the PR description is enough. I'd also like to see a Windows capture → seed round trip with a read-only nested directory and a known modification time. The seed path applies permissions first, then reopens the directory to set its time. Does the round trip preserve the contents, timestamp, and read-only attribute?
    Native Windows verification. The PR reports that invocation and restart smoke tests passed, but the executor test binary didn't compile on Windows. Could you make the five Windows-only restore-cleanup tests runnable and report their results at the PR head, along with the updated cache lease test and the round trip above? The smoke tests don't exercise handle pinning, outside hard-link attributes, or read-only cache leases.
    Separately, for GOL-2221, --trigger starts a listener without a completion key, and the three-second timeout drops its join handle without asking it to close. The local-close path also discards the peer's reply code and reason. Could you cover the trigger path and retain those diagnostics as the PR describes?

@runtologist runtologist 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.

Adversarial review of the head commit, with one finding and a reproducer in the inline comment. I checked that this PR and its counterpart make the same fix, adapted to the branch. The fix covers the stream close, the directory capabilities, the Windows restore clear, cache leases, registry port gating and plugin conflicts. Both heads reproduce this finding the same way.

noise64 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

At 9b690e95d, the selected non-symlink restore-cleanup tests, cache-lease tests and empty unsupported-root RestoreRun test passed natively on Windows. The symlink cleanup test was excluded from that run; its native pass was at e5203807. Per-test results are in the PR description.

Capture and seed: yes, setting times before permissions applies only to directories; regular files still set the time through the open handle. The description now says so. The round trip (capture_and_seed_preserve_readonly_nested_contents_and_times: a read-only nested directory with a known modification time) keeps the contents, timestamp and read-only attribute on Windows.

Network roots: at 9b690e9 we also tested a real loopback share (\\localhost\C$\…) and a net use drive mapped to it, each with an empty and a populated root. The restore clear rejects all four with "only local paths are supported on Windows" before it enumerates anything, and leaves the contents unchanged. The new RestoreRun test covers classifying an unsupported root as a permanent failure.

@kmatasfp

kmatasfp commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for the updates. The try_fold walker, the explicit compilation queue phases, and the seed recovery change address my design comments. In particular, ordinary writes still get an EffectDecision, and the seed caller can act on Retry or Fail without having to spend the retry budget or infer when to invalidate the generation. I’m happy to resolve those threads. The empty-root validation and reparse-tag checks also address my earlier code concerns.

Two things I’d still like fixed:

  1. Cache rollback can abort the executor. The persist → protect → sync ordering fixes the lease issue. But if protection or sync fails and removing the persisted file also fails, the new expect aborts the release executor. A host filesystem becoming read-only can cause both failures. Could you return an unavailable load error that retains both causes, so callers waiting on this cache entry receive the failure rather than losing the executor?
  2. A failed invocation still bypasses the WebSocket close. In the invocation path, invoke_agent(...).await...? can return before finish_listener runs. Could you keep the invocation result, finish the listener on either outcome, then return that result? A test where the socket connects but the invocation request fails would cover the missed exit.

Two smaller follow-ups:

  • Could you reconcile the Windows test results by commit? The reply says all five cleanup tests passed at 9b690e95d, while the description says the symlink test last passed at e5203807 and was excluded at the current head. The real UNC/mapped-drive probes and the capture → seed result answer my earlier questions. I’m only asking which commit exercised the symlink case; the unsupported-tag runtime case is already identified as untested.
  • Now that the recovery policy is settled, could you align the startup walkthrough and the corresponding durable-execution skill text with it? A seed can retry, and a metadata error only invalidates the generation when it meets the invalidation rule. The update paragraph also says other filesystem errors retry, although a permanent storage refusal at the update point can fail the pending update.

noise64 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in b1affe1.

This branch has not been deployed

No deployments
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.

4 participants