osuite 2.14.0 → 2.14.2

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.
@@ -10,6 +10,14 @@ Ordinary `run()` and `status()` never invoke a recovery adapter or retry an
10
10
  uncertain native call. Recovery is an explicit host application decision, not an
11
11
  agent-supplied permission flag. All errors retain `retryAutomatically: false`.
12
12
 
13
+ When a known uncertain call has no adapter, `recover()` returns
14
+ `RECOVERY_UNSUPPORTED` with the matching parent's local state, action ID,
15
+ replay URL and no-resend guidance. It does not contact Studio, inspect the
16
+ resource, or create a child. A different input or binding conflicts without
17
+ returning the original record. An unused ID creates no record. An authoritative
18
+ empty status is only a point-in-time observation, not a guarantee that another
19
+ writer cannot commit after the read.
20
+
13
21
  ## Trust boundary
14
22
 
15
23
  The developer installs a trusted, versioned adapter on a tool binding **before
@@ -6,6 +6,8 @@ import { createStateStore } from '../runtime/state.mjs';
6
6
  import { admitAction, actionAdmission, cavaFingerprint } from '../runtime/admission.mjs';
7
7
  import { matchesStoredAction, reject } from './contract.mjs';
8
8
 
9
+ const receiptWindow = Object.freeze({ headersTimeoutMs: 2500, timeoutMs: 5000 });
10
+
9
11
  export function createStudioAuthority(config, journalPath) {
10
12
  const responseLimits = { maxResponseBytes: 1048576 };
11
13
  const baseApi = createApiClient(config, responseLimits);
@@ -46,7 +48,7 @@ export function createStudioAuthority(config, journalPath) {
46
48
  }
47
49
 
48
50
  async function read(record) {
49
- const response = await baseApi.request('GET', `/api/actions/${encodeURIComponent(record.actionId)}`);
51
+ const response = await baseApi.request('GET', `/api/actions/${encodeURIComponent(record.actionId)}`, undefined, receiptWindow);
50
52
  if (!response.ok) return { available: false, status: response.status };
51
53
  if (!matchesStoredAction(response.body, record, config)) return { available: false, status: response.status, mismatch: true };
52
54
  return { available: true, body: response.body, action: response.body.action || response.body };
@@ -67,7 +69,7 @@ export function createStudioAuthority(config, journalPath) {
67
69
  if (!session.ok || actualSession?.runtime_session_id !== record.sessionId
68
70
  || actualSession?.org_id !== config.orgId || actualSession?.agent_id !== config.agentId
69
71
  || actualSession?.runtime_adapter_id !== config.runtimeId) reject('CURRENT_AUTHORITY_UNAVAILABLE');
70
- let claimed = false, receivedAt = null;
72
+ let claimed = false, requestStartedAt = null;
71
73
  const claim = () => {
72
74
  if (claimed) reject('OUTCOME_UNKNOWN');
73
75
  if (aborted()) reject('ABORTED');
@@ -80,10 +82,10 @@ export function createStudioAuthority(config, journalPath) {
80
82
  config: effective,
81
83
  api: { async request(method, endpoint, body, options) {
82
84
  if (aborted()) reject('ABORTED');
83
- if (method === 'POST' && endpoint === '/api/actions') claim();
84
- const response = await api.request(method, endpoint, body, options);
85
- if (method === 'POST' && endpoint === '/api/actions') {
86
- receivedAt = performance.now();
85
+ const registering = method === 'POST' && endpoint === '/api/actions';
86
+ if (registering) { claim(); requestStartedAt = performance.now(); }
87
+ const response = await api.request(method, endpoint, body, registering ? receiptWindow : options);
88
+ if (registering) {
87
89
  if (!response.ok || !matchesStoredAction(response.body, record, config)
88
90
  || !cavaFingerprint(response.body)) {
89
91
  settle(phase === 'redeeming' ? 'uncertain_redemption' : 'uncertain_request');
@@ -100,7 +102,7 @@ export function createStudioAuthority(config, journalPath) {
100
102
  { actionId: record.actionId, fingerprint: record.fingerprint }).authorized);
101
103
  },
102
104
  });
103
- if (result.authorized) return { phase, receivedAt, response: result.response,
105
+ if (result.authorized) return { phase, dispatchDeadline: requestStartedAt + receiptWindow.timeoutMs, response: result.response,
104
106
  ruleExpiresAt: result.ruleRolloutBinding?.expires_at ?? null };
105
107
  if (result.reason === 'policy_block') {
106
108
  if (!claimed) claim();
@@ -128,7 +130,7 @@ export function createStudioAuthority(config, journalPath) {
128
130
  result_digest: resultDigest, result_retained: false, independent_resource_verification: false,
129
131
  ...(record.recovery ? { recovery: record.recovery, recovery_evidence_digest: record.errorCode?.slice('recovery_'.length) ?? null } : {}) }),
130
132
  ...(state === 'uncertain' ? { error_message: 'Native call outcome is uncertain; no automatic resend.' } : {}),
131
- });
133
+ }, receiptWindow);
132
134
  return response.ok && matchesStoredAction(response.body, record, config)
133
135
  && response.body.action?.status === (state === 'completed' ? 'completed' : 'failed')
134
136
  && typeof response.body.action?.timestamp_end === 'string';
@@ -30,7 +30,10 @@ function recoveryGuidance(code, state) {
30
30
  else if (['requesting', 'redeeming', 'dispatching', 'uncertain', 'uncertain_request', 'uncertain_redemption'].includes(state)) nextStep = 'reconcile_without_resend';
31
31
  else if (!code && state === 'prepared') nextStep = 'check_current_authority';
32
32
  else nextStep = 'inspect_configuration';
33
- return Object.freeze({ nextStep, preserveOperationId: true, message: recoveryMessages[nextStep] });
33
+ const message = code === 'RECOVERY_UNSUPPORTED' && state === 'uncertain'
34
+ ? 'No resource recovery contract was installed for this call. Keep the same operation ID and reconcile against the original receipt. An empty lookup is not permission to resend.'
35
+ : recoveryMessages[nextStep];
36
+ return Object.freeze({ nextStep, preserveOperationId: true, message });
34
37
  }
35
38
 
36
39
  export class GovernedToolError extends Error {
@@ -153,14 +153,18 @@ export function createGovernedTools({ config: rawConfig, namespace, journalPath,
153
153
  }
154
154
  // No await or user observer between this last check, the durable fence,
155
155
  // and invoking the original tool. This is not resource-side atomicity.
156
- if (aborted() || closed || performance.now() - admitted.receivedAt > 5000 || (recovery && !recovery.fresh())) {
156
+ const grantExpiry = admitted.phase === 'redeeming' ? Date.parse(admitted.response.action.approval_expires_at) : Infinity;
157
+ const ruleExpiry = admitted.ruleExpiresAt == null ? Infinity : Date.parse(admitted.ruleExpiresAt);
158
+ const current = () => performance.now() < admitted.dispatchDeadline && Date.now() < Math.min(grantExpiry, ruleExpiry)
159
+ && (!recovery || recovery.fresh());
160
+ if (aborted() || closed || !current()) {
157
161
  journal.settle(scope, operationId, owner, admitted.phase,
158
162
  admitted.phase === 'redeeming' ? 'uncertain_redemption' : 'uncertain_request');
159
163
  reject(aborted() ? 'ABORTED' : 'OUTCOME_UNKNOWN', status(local(operationId)));
160
164
  }
161
165
  if (!journal.settle(scope, operationId, owner, admitted.phase, 'dispatching', dispatchPatch)) reject('OPERATION_BUSY', status(local(operationId)));
162
166
  // Durable local I/O can outlive the admission, even without an await.
163
- if (aborted() || closed || performance.now() - admitted.receivedAt > 5000 || (recovery && !recovery.fresh())) {
167
+ if (aborted() || closed || !current()) {
164
168
  try { journal.settle(scope, operationId, owner, 'dispatching', 'uncertain'); }
165
169
  catch { /* The committed dispatch fence still forbids replay if cleanup cannot write. */ }
166
170
  reject(aborted() ? 'ABORTED' : 'OUTCOME_UNKNOWN', status(local(operationId)));
@@ -216,10 +220,9 @@ export function createGovernedTools({ config: rawConfig, namespace, journalPath,
216
220
  const settings = runOptions(options);
217
221
  if (settings.aborted()) reject('ABORTED');
218
222
  const adapter = bindings[parent.params.name].recovery;
219
- if (!adapter) reject('RECOVERY_UNSUPPORTED');
220
- const record = local(operationId);
223
+ const record = journal.getBound(parent.record);
224
+ if (!adapter) reject('RECOVERY_UNSUPPORTED', status(record));
221
225
  if (!record) reject('RECOVERY_UNAVAILABLE');
222
- journal.prepare(parent.record); // Compare every stored identity without replacing the parent.
223
226
  if (record.state !== 'uncertain') { stopForState(record); reject('RECOVERY_UNAVAILABLE', status(record)); }
224
227
  const { invocation, request } = makeRecoveryInvocation(parent, adapter);
225
228
  try {
@@ -333,6 +333,12 @@ export class OperationJournal {
333
333
  return this.#db.prepare('SELECT * FROM operations WHERE scope=? AND operation_id=?').get(scope, operationId);
334
334
  }
335
335
 
336
+ #boundRow(value) {
337
+ const row = this.#read(value.scope, value.operationId);
338
+ if (row && Object.entries(FIELDS).some(([field, column]) => value[field] !== row[column])) fail('CONFLICT');
339
+ return row;
340
+ }
341
+
336
342
  #row(row) {
337
343
  if (!row) return null;
338
344
  return Object.freeze({
@@ -353,11 +359,8 @@ export class OperationJournal {
353
359
  return this.#run(() => {
354
360
  const value = validateRecord(record);
355
361
  return this.#transaction(() => {
356
- const prior = this.#read(value.scope, value.operationId);
357
- if (prior) {
358
- if (Object.entries(FIELDS).some(([field, column]) => value[field] !== prior[column])) fail('CONFLICT');
359
- return this.#row(prior);
360
- }
362
+ const prior = this.#boundRow(value);
363
+ if (prior) return this.#row(prior);
361
364
  if (this.#db.prepare('SELECT count(*) AS n FROM operations').get().n >= this.#maxOperations) fail('JOURNAL_CAPACITY');
362
365
  const now = Date.now();
363
366
  this.#db.prepare(`INSERT INTO operations(scope,operation_id,input_digest,context_digest,binding_digest,
@@ -378,6 +381,10 @@ export class OperationJournal {
378
381
  });
379
382
  }
380
383
 
384
+ getBound(record) {
385
+ return this.#run(() => this.#row(this.#boundRow(validateRecord(record))));
386
+ }
387
+
381
388
  claim(scope, operationId, fromStates, nextState, owner) {
382
389
  return this.#run(() => {
383
390
  identity(scope, operationId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osuite",
3
- "version": "2.14.0",
3
+ "version": "2.14.2",
4
4
  "description": "OSuite governed action SDK for AI agents. Approve, replay, prove, and verify runtime decisions.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -77,7 +77,10 @@ export function createApiClient(config, { fetchImpl = globalThis.fetch, timeoutM
77
77
  }
78
78
  }
79
79
  const controller = new AbortController();
80
- const timer = setTimeout(() => controller.abort(), Math.max(1, Math.min(options.timeoutMs ?? timeoutMs, 30000)));
80
+ const totalMs = Math.max(1, Math.min(options.timeoutMs ?? timeoutMs, 30000));
81
+ const headMs = Math.max(1, Math.min(options.headersTimeoutMs ?? totalMs, totalMs));
82
+ const started = performance.now();
83
+ let timer = setTimeout(() => controller.abort(), headMs);
81
84
  let status = 0;
82
85
  try {
83
86
  const response = await fetchImpl(baseUrl + endpoint, {
@@ -88,6 +91,16 @@ export function createApiClient(config, { fetchImpl = globalThis.fetch, timeoutM
88
91
  ...(payload === undefined ? {} : { body: JSON.stringify(payload) }),
89
92
  });
90
93
  status = response.status;
94
+ if (headMs < totalMs) {
95
+ const elapsed = performance.now() - started;
96
+ if (controller.signal.aborted || elapsed >= headMs) {
97
+ controller.abort();
98
+ return { ok: false, status, error: 'timeout' };
99
+ }
100
+ // A timely header buys only the remainder of the original total, never a fresh timeout per chunk.
101
+ clearTimeout(timer);
102
+ timer = setTimeout(() => controller.abort(), Math.max(1, totalMs - elapsed));
103
+ }
91
104
  if (status < 200 || status >= 300) {
92
105
  await response.body?.cancel();
93
106
  return { ok: false, status, error: 'http_error' };
@@ -110,6 +123,9 @@ export function createApiClient(config, { fetchImpl = globalThis.fetch, timeoutM
110
123
  try { parsed = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks))); } catch {
111
124
  return { ok: false, status, error: 'invalid_response' };
112
125
  }
126
+ if (headMs < totalMs && (controller.signal.aborted || performance.now() - started >= totalMs)) {
127
+ return { ok: false, status, error: 'timeout' };
128
+ }
113
129
  if (!isObject(parsed)) return { ok: false, status, error: 'invalid_response' };
114
130
  return { ok: true, status, body: parsed };
115
131
  } catch (error) {