{"record":{"id":"9583ce16ad5b70ac","repo":"Tencent/WeKnora","slug":"sandbox-ensure-session-dir-s-w","errorCode":null,"errorMessage":"sandbox: ensure session dir %s: %w","messagePattern":"sandbox: ensure session dir (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/session_manager.go","lineNumber":494,"sourceCode":"\tif !ok || !m.client.Capabilities().SupportsSnapshots {\n\t\treturn nil, errors.New(\"sandbox: remote provider does not support snapshots\")\n\t}\n\treturn snapshots.ListSnapshots(ctx, sandboxID)\n}\n\n// EnsureSessionDir creates dir inside the session's live sandbox when one is\n// bound. It is a no-op when the session has no live binding; the skill\n// framework will materialise the directory during the next Execute call.\nfunc (m *SessionBoundManager) EnsureSessionDir(ctx context.Context, sessionID, dir string) error {\n\tif strings.TrimSpace(dir) == \"\" {\n\t\treturn nil\n\t}\n\thandle, ok, err := m.lookupSessionHandle(ctx, sessionID)\n\tif err != nil || !ok {\n\t\treturn err\n\t}\n\tif err := ignoreExistingDir(m.client.MakeDir(ctx, handle, dir)); err != nil {\n\t\treturn fmt.Errorf(\"sandbox: ensure session dir %s: %w\", dir, err)\n\t}\n\treturn nil\n}\n\n// WriteSessionInputFile writes a durable attachment path into the session's\n// remote sandbox, provisioning the sandbox on first call. It is refused when\n// the manager has fallen back to Local (writing to the host would leak\n// attachments outside the tenant's isolation boundary).\nfunc (m *SessionBoundManager) WriteSessionInputFile(\n\tctx context.Context, sessionID, filePath string, content []byte,\n) error {\n\tif err := m.requireRemoteBackend(); err != nil {\n\t\treturn err\n\t}\n\tif strings.TrimSpace(sessionID) == \"\" {\n\t\treturn errors.New(\"sandbox: session ID required for input staging\")\n\t}\n\tclean, err := cleanSessionInputPath(filePath)","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/session_manager.go#L476-L512","documentation":"EnsureSessionDir looks up the session's live sandbox handle and calls MakeDir for the requested directory, wrapping any failure with \"sandbox: ensure session dir <dir>\". Note it silently returns nil (no error) when the session has no live sandbox, so this error only occurs when a sandbox IS bound but the MakeDir call fails.","triggerScenarios":"Calling EnsureSessionDir(ctx, sessionID, dir) where lookupSessionHandle finds a live handle but the provider's MakeDir returns an error (permission denied, invalid path, sandbox terminated mid-call, provider API error, context deadline).","commonSituations":"Sandbox was reclaimed/expired between handle lookup and MakeDir, path contains illegal characters for the provider, quota/disk limits hit, or transient provider 5xx during attachment staging.","solutions":["Inspect the wrapped error to distinguish permission vs. path vs. provider-availability issues.","Confirm the session's sandbox is still alive (re-provision if expired) and retry the call.","Validate the dir path is absolute/provider-compatible before calling.","Retry with backoff for transient provider errors."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check session has a live sandbox before ensuring dirs\nif !store.HasLiveBinding(ctx, sessionID) {\n    return nil // nothing to ensure; EnsureSessionDir is a no-op anyway\n}","typeGuard":null,"tryCatchPattern":"if err := mgr.EnsureSessionDir(ctx, sessionID, dir); err != nil {\n    var provErr *sandbox.ProviderError\n    if errors.As(err, &provErr) && provErr.Retryable {\n        return retryEnsure(ctx, sessionID, dir)\n    }\n    return fmt.Errorf(\"ensure session dir %s: %w\", dir, err)\n}","preventionTips":["Only call EnsureSessionDir after confirming the session's sandbox is live.","Validate dir paths (absolute, provider-safe characters) before calling.","Monitor sandbox TTLs; re-provision expired sandboxes before file operations.","Watch provider disk quotas in dashboards."],"tags":["go","sandbox","filesystem","remote"],"backgroundTag":"remote-mkdir-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}