Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(backend): a terminal refused at use says why; an ordinary command never reads terminal contexts (#1952)

0xken1562216a311e9e
diff --git a/backend/integration/superTabs.test.ts b/backend/integration/superTabs.test.ts
index 30b943ae3..3d5b6491d 100644
--- a/backend/integration/superTabs.test.ts
+++ b/backend/integration/superTabs.test.ts
@@ -3253,6 +3253,9 @@ describe('the PM\'s terminal after a private chat (final review, Critical 1)', (
await run(tab, { type: 'conversation.agent', conversationId: second.conversationId, agentId: worker, present: true, lead: true })
await expect(typed(peers, 'after')).rejects.toMatchObject({ code: 'NATIVE_CONTEXT_REVOKED' })
+ // The refusal at use says why, as the refusal at open does (review of #1940).
+ await db.superTabNativeContext.update({ where: { id: peers }, data: { revoked: false } })
+ await expect(typed(peers, 'why')).rejects.toMatchObject({ code: 'NATIVE_CONTEXT_REVOKED', message: expect.stringContaining('a Product Manager’s terminal') })
await expect(store.native.read(host, tab, peers)).rejects.toMatchObject({ code: 'NATIVE_CONTEXT_REVOKED' })
await expect(opened(peer)).rejects.toMatchObject({ code: 'TERMINAL_PRIVATE' })
// Even a terminal the change left unrevoked is refused at use.
@@ -3384,6 +3387,31 @@ describe('the PM\'s terminal after a private chat (final review, Critical 1)', (
})
})
+// Prod, 2026-10-28 (Atlas, the hour to 14:30 VN): every command, message.send included, sent one terminal-context query of
+// 78 branches, 70 of them this project's archived groups, that returned nothing and spent 67% of its 0.6–3.8 s planning.
+describe('terminal-context revoke on an ordinary command', () => {
+ it('sends a message in a Swarm with many archived groups and a private project without touching terminal contexts', async () => {
+ const { tab } = await fixture()
+ await invite(tab)
+ await run(tab, { type: 'project.create', name: 'Owner only', visibility: 'private', brief: '' })
+ await run(tab, { type: 'conversation.create', title: 'Owner and PM', brief: '', checks: [], audience: { personIds: [owner.sub] } })
+ for (let i = 0; i < 30; i++) {
+ const group = String((await run(tab, { type: 'conversation.create', title: `Old ${i}`, brief: '', checks: [] })).result.conversationId)
+ await run(tab, { type: 'conversation.archive', conversationId: group, archived: true })
+ }
+ await db.$runCommandRaw({ profile: 2 })
+ try {
+ await run(tab, message('Status?'))
+ } finally {
+ await db.$runCommandRaw({ profile: 0 })
+ }
+ const profiled = await db.$runCommandRaw({ find: 'system.profile', filter: { 'command.profile': { $exists: false } }, batchSize: 10000 }) as
+ unknown as { cursor: { firstBatch: Array<{ ns: string; op: string }> } }
+ await db.$runCommandRaw({ drop: 'system.profile' })
+ expect(profiled.cursor.firstBatch.filter(row => row.ns.endsWith('.SuperTabNativeContext'))).toEqual([])
+ })
+})
+
describe('Swarm sweeps', () => {
const day = 86_400_000
async function finishedGroup(tab: string, lead: string) {
diff --git a/backend/src/superTabs/native.ts b/backend/src/superTabs/native.ts
index 30b51e787..fe736e931 100644
--- a/backend/src/superTabs/native.ts
+++ b/backend/src/superTabs/native.ts
@@ -73,7 +73,8 @@ export class SuperTabNativeStore {
const group = readConversation(state, { kind: 'person', userId: binding.operator.id, email: binding.operator.name }, record.conversationId)
// A terminal drives its session and its answers land in the conversation: only those who may drive it may use it.
try { mayDrive(state, { kind: 'person', userId: binding.operator.id, email: binding.operator.name }, target) } catch (error) {
- if (error instanceof SuperTabError) fail('NATIVE_CONTEXT_REVOKED', 'Only this agent\'s machine\'s owner can use its terminal now.', 403)
+ // The driving rule's own reason (read-only, the agent's project gone, a Lead or a private session), under the code clients reopen on.
+ if (error instanceof SuperTabError) fail('NATIVE_CONTEXT_REVOKED', error.message, 403)
throw error
}
if (operator.membershipGeneration !== binding.operator.membershipGeneration || group.archived || !group.agentIds.includes(target.id)