gestalt-mobile 0.72.6 → 0.72.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -498,11 +498,13 @@ retires its saved entry. When the last known session for that workspace is
498
498
  forgotten, it deletes the **entire `<workspace>/tmp` directory**, including legacy
499
499
  output and old lease metadata. Reserve that directory for disposable data.
500
500
  While other saved sessions remain, workspace scratch is retained until final
501
- Forget. If another known session's
501
+ Forget. If the only remaining blockers are active borrowers of previously
502
+ forgotten sessions, Forget retires the last session and keeps the shared
503
+ `tmp` directory. Clean Tmp can remove the borrowed folders after release.
504
+ If another known session's
502
505
  workspace is inside `tmp`, forget that contained session first. New sessions are
503
506
  blocked throughout cleanup. Unconfirmed shutdown, unsafe paths and deletion
504
- failures retain a retryable entry; final Forget never reports success with files
505
- left behind. Reloading recovers the backend operation's state.
507
+ failures retain a retryable entry. Reloading recovers the backend operation's state.
506
508
 
507
509
  Mobile allocates temporary storage in each selected workspace. The Launcher
508
510
  validates and forwards that ownership context to managed tools, and Agents uses
@@ -67,7 +67,10 @@ export class ForgetSession {
67
67
  const cleanup = await this.deps.clean(session, operation.operationId);
68
68
  if (cleanup && typeof cleanup === 'object')
69
69
  releaseCleanup = () => cleanup.release();
70
- operation = { ...operation, scratchRetained: cleanup === 'retained' ? true : undefined };
70
+ operation = {
71
+ ...operation,
72
+ scratchRetained: cleanup === 'retained' ? true : cleanup?.scratchRetained,
73
+ };
71
74
  failureCode = 'SESSION_FORGET_FAILED';
72
75
  if (advance('finalizing').phase === 'completed')
73
76
  return operation;
@@ -53,7 +53,10 @@ export class FilesystemScratchCleanup {
53
53
  }
54
54
  async cleanWorkspace(workspacePath, protectedSessions, onlyOwnerId, authorized, authorizedSessionId, inherited) {
55
55
  await this.canonicalWorkspace(workspacePath);
56
- const counts = emptyScratchCounts();
56
+ const counts = {
57
+ ...emptyScratchCounts(),
58
+ leasedMobileSessions: [],
59
+ };
57
60
  const workspaceName = basename(workspacePath) || 'root workspace';
58
61
  const temporary = join(workspacePath, 'tmp');
59
62
  try {
@@ -109,19 +112,35 @@ export class FilesystemScratchCleanup {
109
112
  const marker = await readManagedScratchOwner(directory, workspacePath, ownerId);
110
113
  await this.assertProtection(directory, join(container, ownerId), marker, protectedSessions, authorized, onlyOwnerId ??
111
114
  (authorizedSessionId ? mobileScratchOwnerId(authorizedSessionId) : undefined));
112
- await this.releasedLeases(directory, marker);
115
+ if ((await readdir(directory)).includes('.association-lock'))
116
+ reject('busy');
117
+ const leases = await readManagedScratchLeases(directory, marker);
118
+ if (leases.some((lease) => lease.state !== 'released' || lease.consumers.length !== 0)) {
119
+ if (authorized && marker.ownerKind === 'mobile-session') {
120
+ if (marker.runtime)
121
+ await validateRuntime(marker, marker.runtime, true);
122
+ counts.leasedMobileSessions.push({
123
+ sessionId: marker.sessionId,
124
+ runtimeDirectory: marker.runtime?.directory,
125
+ });
126
+ }
127
+ reject('lease');
128
+ }
113
129
  if (authorized) {
114
130
  await this.retireNestedNamespaces(directory, protectedSessions, authorized, authorizedSessionId, containment);
115
131
  if (marker.runtime && (await validateRuntime(marker, marker.runtime, true)))
116
132
  await this.retireNestedNamespaces(marker.runtime.directory, protectedSessions, authorized, authorizedSessionId, containment);
117
133
  }
118
- await this.validatePayload(directory);
134
+ // Manual Clean Tmp bounds opportunistic inspection. Explicit Forget
135
+ // has to finish checking large owners before retiring the session.
136
+ const inspectionBudget = () => (authorized ? undefined : { entries: 0 });
137
+ await this.validatePayload(directory, inspectionBudget());
119
138
  if (marker.runtime) {
120
139
  const present = await validateRuntime(marker, marker.runtime, true);
121
140
  if (present) {
122
141
  await this.assertProtection(directory, join(container, ownerId), marker, protectedSessions, authorized, onlyOwnerId ??
123
142
  (authorizedSessionId ? mobileScratchOwnerId(authorizedSessionId) : undefined));
124
- await this.validatePayload(marker.runtime.directory);
143
+ await this.validatePayload(marker.runtime.directory, inspectionBudget());
125
144
  }
126
145
  }
127
146
  await privateDirectory(directory, false);
@@ -230,16 +249,9 @@ export class FilesystemScratchCleanup {
230
249
  }
231
250
  return counts;
232
251
  }
233
- async releasedLeases(directory, marker) {
234
- if ((await readdir(directory)).includes('.association-lock'))
235
- reject('busy');
236
- const leases = await readManagedScratchLeases(directory, marker);
237
- if (leases.some((lease) => lease.state !== 'released' || lease.consumers.length !== 0))
238
- reject('lease');
239
- }
240
252
  /** Final workspace authority can retire positively attributed nested namespaces,
241
253
  * but every nested roster, lease, inode and fence still has to pass its gate. */
242
- async retireNestedNamespaces(directory, protectedSessions, authorized, authorizedSessionId, inherited, skipContainer = false, depth = 0, budget = { entries: 0 }) {
254
+ async retireNestedNamespaces(directory, protectedSessions, authorized, authorizedSessionId, inherited, skipContainer = false, depth = 0) {
243
255
  if (depth > 128 || !authorized())
244
256
  reject('protected');
245
257
  let entries;
@@ -252,8 +264,6 @@ export class FilesystemScratchCleanup {
252
264
  throw error;
253
265
  }
254
266
  for (const entry of entries) {
255
- if (++budget.entries > 100000)
256
- reject('unrecognized');
257
267
  const name = entry.name.toString();
258
268
  if (skipContainer && name === 'sessions')
259
269
  continue;
@@ -284,7 +294,7 @@ export class FilesystemScratchCleanup {
284
294
  throw error;
285
295
  }
286
296
  }
287
- await this.retireNestedNamespaces(path, protectedSessions, authorized, authorizedSessionId, inherited, name === 'tmp', depth + 1, budget);
297
+ await this.retireNestedNamespaces(path, protectedSessions, authorized, authorizedSessionId, inherited, name === 'tmp', depth + 1);
288
298
  }
289
299
  }
290
300
  async retireRuntime(directory, marker) {
@@ -359,7 +369,7 @@ export class FilesystemScratchCleanup {
359
369
  }
360
370
  }
361
371
  }
362
- async validatePayload(directory, root = directory, depth = 0, budget = { entries: 0 }) {
372
+ async validatePayload(directory, budget, root = directory, depth = 0) {
363
373
  if (depth > 128)
364
374
  reject('unrecognized');
365
375
  // Even an empty nested namespace is not authority to retire a workspace's
@@ -370,10 +380,10 @@ export class FilesystemScratchCleanup {
370
380
  reject('unrecognized');
371
381
  for (const entry of await readdir(directory, { encoding: 'buffer', withFileTypes: true })) {
372
382
  const child = entry.name;
383
+ if (budget && ++budget.entries > 100_000)
384
+ reject('unrecognized');
373
385
  if (child.toString() === workspacePublicationName)
374
386
  reject('busy');
375
- if (++budget.entries > 100_000)
376
- reject('unrecognized');
377
387
  if (directory !== root &&
378
388
  [
379
389
  scratchMarkerName,
@@ -393,7 +403,7 @@ export class FilesystemScratchCleanup {
393
403
  // lstat never follows them, and rm unlinks them without deleting their targets.
394
404
  // Owner paths and authority metadata retain their separate no-link checks.
395
405
  if (info.isDirectory())
396
- await this.validatePayload(path, root, depth + 1, budget);
406
+ await this.validatePayload(path, budget, root, depth + 1);
397
407
  }
398
408
  }
399
409
  }
@@ -7,7 +7,7 @@ import { lstatSync, mkdirSync, realpathSync, renameSync } from 'node:fs';
7
7
  import { lstat, readdir, rm } from 'node:fs/promises';
8
8
  import { join } from 'node:path';
9
9
  import { WorkspaceSessionConflict } from '../../features/sessions/application/workspace-conflict.js';
10
- import { WorkspaceCleanupFailure } from '../../features/sessions/forget-session/use-case.js';
10
+ import { WorkspaceCleanupFailure, } from '../../features/sessions/forget-session/use-case.js';
11
11
  import { canonicalSessionWorkspace, workspaceContains, } from '../persistence/sqlite-workspace-lifecycle.js';
12
12
  import { FilesystemScratchCleanup } from './filesystem-scratch-cleanup.js';
13
13
  import { claimWorkspacePublication } from './workspace-publication.js';
@@ -48,6 +48,16 @@ export class FilesystemWorkspaceForget {
48
48
  if (counts.skipped || counts.failed) {
49
49
  if (counts.failedFolders?.length)
50
50
  cleanupFolders = counts.failedFolders.map(({ relativePath }) => relativePath);
51
+ // An earlier completed Forget may have left a borrower in this workspace.
52
+ // Its release is independent of the last session. Keep tmp in place.
53
+ if (!counts.failed &&
54
+ counts.leasedMobileSessions.length === counts.skipped &&
55
+ counts.leasedMobileSessions.every(({ sessionId }) => this.previouslyRetained(sessionId))) {
56
+ const retained = new Set(counts.leasedMobileSessions.flatMap(({ runtimeDirectory }) => runtimeDirectory ?? []));
57
+ if ((!process.getuid || !(await hasRuntimeOwner({ workspacePath: workspace }, retained))) &&
58
+ authorized())
59
+ return { release, scratchRetained: true };
60
+ }
51
61
  throw new Error('SESSION_CLEANUP_FAILED');
52
62
  }
53
63
  cleanupFolders = [];
@@ -80,7 +90,12 @@ export class FilesystemWorkspaceForget {
80
90
  throw error;
81
91
  }
82
92
  }
83
- async assertRetired(directory, depth = 0, budget = { entries: 0 }) {
93
+ previouslyRetained(id) {
94
+ return !!this.db
95
+ .prepare("SELECT 1 FROM session_forget_operations WHERE session_id=? AND phase='completed' AND scratch_retained=1")
96
+ .get(id);
97
+ }
98
+ async assertRetired(directory, depth = 0) {
84
99
  if (depth > 128)
85
100
  throw new Error('SESSION_CLEANUP_FAILED');
86
101
  let entries;
@@ -93,17 +108,16 @@ export class FilesystemWorkspaceForget {
93
108
  throw error;
94
109
  }
95
110
  for (const entry of entries) {
96
- if (++budget.entries > 100000 ||
97
- [
98
- '.gestalt-owner.json',
99
- '.gestalt-runtime.json',
100
- '.controller-lock',
101
- '.containment-lock',
102
- '.gestalt-scratch-lock',
103
- ].includes(entry.name.toString()))
111
+ if ([
112
+ '.gestalt-owner.json',
113
+ '.gestalt-runtime.json',
114
+ '.controller-lock',
115
+ '.containment-lock',
116
+ '.gestalt-scratch-lock',
117
+ ].includes(entry.name.toString()))
104
118
  throw new Error('SESSION_CLEANUP_FAILED');
105
119
  if (entry.isDirectory() && !entry.isSymbolicLink())
106
- await this.assertRetired(Buffer.concat([Buffer.from(directory), Buffer.from('/'), entry.name]), depth + 1, budget);
120
+ await this.assertRetired(Buffer.concat([Buffer.from(directory), Buffer.from('/'), entry.name]), depth + 1);
107
121
  }
108
122
  }
109
123
  retire(session, operationId, workspace, temporary, authorized) {
@@ -106,7 +106,7 @@ export async function validateRuntime(owner, runtime, allowRetiring = false) {
106
106
  return true;
107
107
  }
108
108
  /** A missing workspace does not authorize abandoning an external payload root. */
109
- export async function hasRuntimeOwner(owner) {
109
+ export async function hasRuntimeOwner(owner, retainedDirectories) {
110
110
  const container = await runtimeContainer();
111
111
  try {
112
112
  await privateDirectory(container, false);
@@ -126,6 +126,7 @@ export async function hasRuntimeOwner(owner) {
126
126
  await privateDirectory(join(container, name), false);
127
127
  const record = (await readMarker(join(container, name, runtimeMarkerName)));
128
128
  if (record.workspacePath === owner.workspacePath &&
129
+ !retainedDirectories?.has(join(container, name)) &&
129
130
  (owner.ownerId === undefined || record.ownerId === owner.ownerId))
130
131
  return true;
131
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.72.6",
3
+ "version": "0.72.7",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",